From a36132344544bf4a124de9ba8fc4418ab1248c95 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 18 Feb 2023 23:46:50 +0200 Subject: [PATCH] feat: add ws_protocol option --- CHANGELOG.md | 1 + Trunk.toml | 2 ++ src/autoreload.js | 8 +++++++- src/build.rs | 7 ++++++- src/cmd/build.rs | 2 +- src/cmd/watch.rs | 2 +- src/config/models.rs | 5 +++++ src/config/rt.rs | 3 +++ src/pipelines/html.rs | 19 +++++++++++++++---- src/serve.rs | 1 + src/watch.rs | 3 ++- 11 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e1d9aa..c08cab9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe - Added `data-target-path` to `copy-dir`. - Allow processing `", RELOAD_SCRIPT)); + target_html.select("body").append_html(format!( + "", + RELOAD_SCRIPT.replace( + "{{protocol}}", + &self.ws_protocol.clone().unwrap_or_else(|| "auto".into()) + ) + )); } } } diff --git a/src/serve.rs b/src/serve.rs index 402174a0..7d2fd2f0 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -39,6 +39,7 @@ impl ServeSystem { cfg.watch.clone(), shutdown.clone(), Some(build_done_chan.clone()), + cfg.ws_protocol.clone(), ) .await?; let http_addr = format!( diff --git a/src/watch.rs b/src/watch.rs index 3b15946c..74f91484 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -38,6 +38,7 @@ impl WatchSystem { cfg: Arc, shutdown: broadcast::Sender<()>, build_done_tx: Option>, + ws_protocol: Option, ) -> Result { // Create a channel for being able to listen for new paths to ignore while running. let (watch_tx, watch_rx) = mpsc::channel(1); @@ -47,7 +48,7 @@ impl WatchSystem { let _watcher = build_watcher(watch_tx, cfg.paths.clone())?; // Build dependencies. - let build = BuildSystem::new(cfg.build.clone(), Some(build_tx)).await?; + let build = BuildSystem::new(cfg.build.clone(), Some(build_tx), ws_protocol).await?; Ok(Self { build, ignored_paths: cfg.ignored_paths.clone(),