From 2b2a0f12c75032453fbefd2491d3ef51ff0ba88e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 24 Nov 2019 11:33:50 +0100 Subject: Update document title properly in `iced_web` --- web/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'web/src') diff --git a/web/src/lib.rs b/web/src/lib.rs index dd401c31..8239ffc9 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -143,7 +143,10 @@ pub trait Application { instance.spawn(command); let window = web_sys::window().unwrap(); + let document = window.document().unwrap(); + document.set_title(&instance.title); + let body = document.body().unwrap(); let vdom = dodrio::Vdom::new(&body, instance); @@ -153,6 +156,7 @@ pub trait Application { #[derive(Clone)] struct Instance { + title: String, ui: Rc>>>, } @@ -162,14 +166,25 @@ where { fn new(ui: impl Application + 'static) -> Self { Self { + title: ui.title(), ui: Rc::new(RefCell::new(Box::new(ui))), } } fn update(&mut self, message: Message) { let command = self.ui.borrow_mut().update(message); + let title = self.ui.borrow().title(); self.spawn(command); + + let window = web_sys::window().unwrap(); + let document = window.document().unwrap(); + + if self.title != title { + document.set_title(&title); + + self.title = title; + } } fn spawn(&mut self, command: Command) { -- cgit