diff --git a/Cargo.lock b/Cargo.lock index ef4fe3b..78f138d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3097,6 +3097,7 @@ dependencies = [ "uuid", "wasm-bindgen", "wasm-bindgen-test", + "wasm-sockets", "web-sys", ] @@ -7303,6 +7304,19 @@ dependencies = [ "syn 2.0.100", ] +[[package]] +name = "wasm-sockets" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d14bbe65995269301ab677e5d69b3b69195447c01137ef44f72b10eecea55c77" +dependencies = [ + "js-sys", + "log", + "thiserror 1.0.69", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.77" diff --git a/web/Cargo.toml b/web/Cargo.toml index ec1bea9..72cde9a 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -37,6 +37,7 @@ letterbox-shared = { version = "0.12.1", path = "../shared", registry = "xinu" } letterbox-notmuch = { version = "0.12.1", path = "../notmuch", registry = "xinu" } seed_hooks = { version = "0.4.0", registry = "xinu" } strum_macros = "0.27.1" +wasm-sockets = "1.0.0" [package.metadata.wasm-pack.profile.release] wasm-opt = ['-Os'] diff --git a/web/src/main.rs b/web/src/main.rs index 0a4ac74..a4dd3e9 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -11,6 +11,7 @@ mod consts; mod graphql; mod state; mod view; +mod websocket; fn main() { // This provides better error messages in debug mode. diff --git a/web/src/state.rs b/web/src/state.rs index 6923c8f..12d7750 100644 --- a/web/src/state.rs +++ b/web/src/state.rs @@ -11,6 +11,7 @@ use crate::{ consts::SEARCH_RESULTS_PER_PAGE, graphql, graphql::{front_page_query::*, send_graphql, show_thread_query::*}, + websocket, }; /// Used to fake the unread string while in development @@ -38,7 +39,7 @@ pub fn init(url: Url, orders: &mut impl Orders) -> Model { if url.hash().is_none() { orders.request_url(urls::search(unread_query(), 0)); } else { - orders.request_url(url); + orders.request_url(url.clone()); }; // TODO(wathiede): only do this while viewing the index? Or maybe add a new message that force // 'notmuch new' on the server periodically? @@ -60,6 +61,7 @@ pub fn init(url: Url, orders: &mut impl Orders) -> Model { }, catchup: None, last_url: Url::current(), + websocket: websocket::init(url, &mut orders.proxy(Msg::WebSocket)), } } @@ -659,6 +661,10 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { orders.send_msg(Msg::ScrollToTop); model.catchup = None; } + + Msg::WebSocket(ws) => { + websocket::update(ws, &mut model.websocket, &mut orders.proxy(Msg::WebSocket)) + } } } @@ -691,6 +697,7 @@ pub struct Model { pub versions: Version, pub catchup: Option, pub last_url: Url, + pub websocket: websocket::Model, } #[derive(Debug)] @@ -822,4 +829,6 @@ pub enum Msg { CatchupMarkAsRead, CatchupNext, CatchupExit, + + WebSocket(websocket::Msg), }