chiark / gitweb /
debug template injection
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 29 Dec 2020 02:05:04 +0000 (02:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 29 Dec 2020 02:05:04 +0000 (02:05 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/daemon-otter.rs
src/config.rs
templates/front.tera
templates/loading.tera
wdriver/wdt-simple.rs

index 25cd534db430007c41eb5d27fa12484a3bdf3424..7626d799948e893a5108af92c36f2bce07b0447b 100644 (file)
@@ -12,7 +12,9 @@ use rocket_contrib::serve::StaticFiles;
 use otter::imports::*;
 
 #[derive(Serialize,Debug)]
-struct FrontPageRenderContext { }
+struct FrontPageRenderContext {
+  debug_js_inject: Arc<String>,
+}
 
 #[derive(Copy,Clone,Debug)]
 enum ResourceLocation { Main, Wasm(&'static str), }
@@ -63,6 +65,7 @@ struct LoadingRenderContext<'r> {
   nick: String,
   layout: PresentationLayout,
   ptoken: &'r RawTokenVal,
+  debug_js_inject: Arc<String>,
 }
 #[get("/")]
 #[throws(OE)]
@@ -88,11 +91,14 @@ fn loading(layout: Option<PresentationLayout>, ia: PlayerQueryString)
       nick: gpl.nick.clone(),
       game: g.name.to_string(),
       ptoken: &ia.raw_token,
+      debug_js_inject: config().debug_js_inject.clone(),
       layout,
     };
     Template::render("loading", &c)
   } else {
-    let c = FrontPageRenderContext { };
+    let c = FrontPageRenderContext {
+      debug_js_inject: config().debug_js_inject.clone(),
+    };
     Template::render("front", &c)
   }
 }
index 1f9bee4ea39018ea5f7608ed51927379a403fbb5..416e15e37377aaf62f26160b0207ff991d577264 100644 (file)
@@ -34,6 +34,7 @@ pub struct ServerConfigSpec {
   pub bundled_sources: Option<String>,
   pub shapelibs: Option<Vec<shapelib::Config1>>,
   pub sendmail: Option<String>,
+  pub debug_js_inject_file: Option<String>,
 }
 
 #[derive(Debug,Clone)]
@@ -57,6 +58,7 @@ pub struct ServerConfig {
   pub bundled_sources: String,
   pub shapelibs: Vec<shapelib::Config1>,
   pub sendmail: String,
+  pub debug_js_inject: Arc<String>,
 }
 
 impl TryFrom<ServerConfigSpec> for WholeServerConfig {
@@ -68,6 +70,7 @@ impl TryFrom<ServerConfigSpec> for WholeServerConfig {
       http_port, public_url, sse_wildcard_url, rocket_workers,
       template_dir, nwtemplate_dir, wasm_dir,
       log, bundled_sources, shapelibs, sendmail,
+      debug_js_inject_file,
     } = spec;
 
     let defpath = |specd: Option<String>, leaf: &str| -> String {
@@ -127,11 +130,18 @@ impl TryFrom<ServerConfigSpec> for WholeServerConfig {
     let log = LogSpecification::from_toml(&log)
       .context("log specification")?;
 
+    let debug_js_inject = Arc::new(match &debug_js_inject_file {
+      Some(f) => fs::read_to_string(f)
+        .with_context(|| f.clone()).context("debug_js_inject_file")?,
+      None => "".into(),
+    });
+
     let server = ServerConfig {
       save_dir, command_socket, debug,
       http_port, public_url, sse_wildcard_url, rocket_workers,
       template_dir, nwtemplate_dir, wasm_dir,
       bundled_sources, shapelibs, sendmail,
+      debug_js_inject,
     };
     WholeServerConfig {
       server: Arc::new(server),
index be885ab41d91afc6e5b7ec5a77d368e0f950ad21..70571e65e795c7dffbd49e80c0aaf5015f00b84b 100644 (file)
@@ -1,6 +1,7 @@
 <html>
   <head>
     <title>Otter</title>
+{{ debug_js_inject }}
   </head>
 <body>
 
index 5f3cd2a8e623a45439849fb107afa5b8f947cb5f..55da37e9a5a706a3570795f2243e6c693693aa94 100644 (file)
@@ -6,6 +6,7 @@
     <title>{{ game | escape }} - {{ nick | escape }} - Otter
     </title>
 <link rel="license" href="/_/libre">
+{{ debug_js_inject }}
 <script defer>let wasm_input = fetch('/_/wasm.wasm');</script>
 <script src="/_/wasm.js" defer></script>
 <script id="global-info" data-layout="{{ layout }}"></script>
index ec94fc26047b268d73ec69c4f37e37df474dcc87..f2840464c9d34fc4eff02a4daf6967bc0c7045ec 100644 (file)
@@ -6,13 +6,16 @@ use otter_webdriver_tests::*;
 
 #[throws(AE)]
 fn main(){
-  let (mut su, inst) = setup(module_path!()).always_context("setup")?;
-  let [alice, bob] : [Window; 2] =
-    su.setup_static_users(&inst)?.try_into().unwrap();
-  debug!("ok {:?} {:?}", alice, bob);
+  {
+    let (mut su, inst) = setup(module_path!()).always_context("setup")?;
+    let [alice, bob] : [Window; 2] =
+      su.setup_static_users(&inst)?.try_into().unwrap();
+    debug!("ok {:?} {:?}", alice, bob);
 
-  su.w(&alice)?.synch()?;
+    su.w(&alice)?.synch()?;
 
-  sleep(750 * MS);
-  debug!("finishing");
+    sleep(750 * MS);
+    debug!("finishing");
+  }
+  info!("ok");
 }