Update document title properly in iced_web
This commit is contained in:
parent
9f3abe9202
commit
2b2a0f12c7
1 changed files with 15 additions and 0 deletions
|
|
@ -143,7 +143,10 @@ pub trait Application {
|
||||||
instance.spawn(command);
|
instance.spawn(command);
|
||||||
|
|
||||||
let window = web_sys::window().unwrap();
|
let window = web_sys::window().unwrap();
|
||||||
|
|
||||||
let document = window.document().unwrap();
|
let document = window.document().unwrap();
|
||||||
|
document.set_title(&instance.title);
|
||||||
|
|
||||||
let body = document.body().unwrap();
|
let body = document.body().unwrap();
|
||||||
let vdom = dodrio::Vdom::new(&body, instance);
|
let vdom = dodrio::Vdom::new(&body, instance);
|
||||||
|
|
||||||
|
|
@ -153,6 +156,7 @@ pub trait Application {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Instance<Message> {
|
struct Instance<Message> {
|
||||||
|
title: String,
|
||||||
ui: Rc<RefCell<Box<dyn Application<Message = Message>>>>,
|
ui: Rc<RefCell<Box<dyn Application<Message = Message>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,14 +166,25 @@ where
|
||||||
{
|
{
|
||||||
fn new(ui: impl Application<Message = Message> + 'static) -> Self {
|
fn new(ui: impl Application<Message = Message> + 'static) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
title: ui.title(),
|
||||||
ui: Rc::new(RefCell::new(Box::new(ui))),
|
ui: Rc::new(RefCell::new(Box::new(ui))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) {
|
||||||
let command = self.ui.borrow_mut().update(message);
|
let command = self.ui.borrow_mut().update(message);
|
||||||
|
let title = self.ui.borrow().title();
|
||||||
|
|
||||||
self.spawn(command);
|
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<Message>) {
|
fn spawn(&mut self, command: Command<Message>) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue