fix: fixed warn info

This commit is contained in:
mrxiaozhuox committed 2022-01-22 22:19:59 +08:00
1 parent 5e710f6693
commit d18a93f129
11 files changed
+43 -44

No files matched your search

+6 -5
View File
@@ -1,6 +1,6 @@
use axum::{
extract::{
ws::{Message, WebSocket},
ws::Message,
Extension, TypedHeader, WebSocketUpgrade,
},
http::StatusCode,
@@ -19,11 +19,11 @@ struct WsRelodState {
update: bool,
}
impl WsRelodState { fn change(&mut self) { self.update = !self.update } }
impl WsRelodState { fn change(&mut self) { self.update = !self.update; } }
pub async fn startup(config: CrateConfig) -> anyhow::Result<()> {
log::info!("Starting development server 🚀");
log::info!("🚀 Starting development server...");
let (tx, rx) = channel();
@@ -40,8 +40,9 @@ pub async fn startup(config: CrateConfig) -> anyhow::Result<()> {
match v {
DebouncedEvent::Create(_) | DebouncedEvent::Write(_) |
DebouncedEvent::Remove(_) | DebouncedEvent::Rename(_, _) => {
builder::build(&watcher_conf).unwrap();
watcher_ws_state.lock().unwrap().change();
if let Ok(_) = builder::build(&watcher_conf) {
watcher_ws_state.lock().unwrap().change();
}
},
_ => {}
}
+19 -8
View File
@@ -14,15 +14,26 @@
</script>
<script>
const socket = new WebSocket("ws://localhost:8080/ws");
socket.addEventListener("message", function (event) {
console.log(event);
if (event.data === "reload") {
window.location.reload();
}
});
(function () {
var protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
var url = protocol + "//" + window.location.host + "/ws";
var poll_interval = 2000;
var reload_upon_connect = () => {
window.setTimeout(() => {
var ws = new WebSocket(url);
ws.onopen = () => window.location.reload();
ws.onclose = reload_upon_connect;
}, poll_interval);
};
var ws = new WebSocket(url);
ws.onmessage = (ev) => {
if (ev.data == "reload") {
window.location.reload();
}
};
ws.onclose = reload_upon_connect;
})();
</script>
</body>
</html>