diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index 273d2488..d8abad60 100644 --- a/examples/application/src/main.rs +++ b/examples/application/src/main.rs @@ -147,7 +147,9 @@ where } fn update_title(&mut self) -> Command { - let title = self.active_page_title().to_owned(); - self.set_title(title) + let header_title = self.active_page_title().to_owned(); + let window_title = format!("{header_title} — COSMIC AppDemo"); + self.set_header_title(header_title); + self.set_window_title(window_title) } } diff --git a/examples/config/src/main.rs b/examples/config/src/main.rs index 892936d5..f606e15c 100644 --- a/examples/config/src/main.rs +++ b/examples/config/src/main.rs @@ -85,7 +85,7 @@ fn test_config(config: Config) { pub fn main() { println!("Testing config"); test_config(Config::new("com.system76.Example", 1).unwrap()); - + println!("Testing state"); test_config(Config::new_state("com.system76.Example", 1).unwrap()); } diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index 9e6297a1..a9901413 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -76,9 +76,10 @@ impl cosmic::Application for App { error_status: None, }; - let command = app.set_title("Open a file".into()); + app.set_header_title("Open a file".into()); + let cmd = app.set_window_title("COSMIC OpenDialog Demo".into()); - (app, command) + (app, cmd) } fn header_end(&self) -> Vec> { @@ -136,43 +137,40 @@ impl cosmic::Application for App { let mut contents = String::new(); std::mem::swap(&mut contents, &mut self.file_contents); - return Command::batch(vec![ - // Set the file's URL as the application title. - self.set_title(url.to_string()), - // Reads the selected file into memory. - cosmic::command::future(async move { - // Check if its a valid local file path. - let path = match url.scheme() { - "file" => url.path(), - other => { - return Message::Error(format!( - "{url} has unknown scheme: {other}" - )); - } - }; + // Set the file's URL as the application title. + self.set_header_title(url.to_string()); - // Open the file by its path. - let mut file = match tokio::fs::File::open(path).await { - Ok(file) => file, - Err(why) => { - return Message::Error(format!("failed to open {path}: {why}")); - } - }; - - // Read the file into our contents buffer. - contents.clear(); - - if let Err(why) = file.read_to_string(&mut contents).await { - return Message::Error(format!("failed to read {path}: {why}")); + // Reads the selected file into memory. + return cosmic::command::future(async move { + // Check if its a valid local file path. + let path = match url.scheme() { + "file" => url.path(), + other => { + return Message::Error(format!("{url} has unknown scheme: {other}")); } + }; - contents.shrink_to_fit(); + // Open the file by its path. + let mut file = match tokio::fs::File::open(path).await { + Ok(file) => file, + Err(why) => { + return Message::Error(format!("failed to open {path}: {why}")); + } + }; - // Send this back to the application. - Message::FileRead(url, contents) - }) - .map(cosmic::app::message::app), - ]); + // Read the file into our contents buffer. + contents.clear(); + + if let Err(why) = file.read_to_string(&mut contents).await { + return Message::Error(format!("failed to read {path}: {why}")); + } + + contents.shrink_to_fit(); + + // Send this back to the application. + Message::FileRead(url, contents) + }) + .map(cosmic::app::message::app); } // Creates a new open dialog. diff --git a/src/app/mod.rs b/src/app/mod.rs index c2481297..01b7a59d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -240,7 +240,7 @@ pub trait ApplicationExt: Application { } /// Set the title of the main window. - fn set_title(&mut self, title: String) -> iced::Command>; + fn set_window_title(&mut self, title: String) -> iced::Command>; /// View template for the main window. fn view_main(&self) -> Element>; @@ -264,13 +264,13 @@ impl ApplicationExt for App { } #[cfg(feature = "wayland")] - fn set_title(&mut self, title: String) -> iced::Command> { + fn set_window_title(&mut self, title: String) -> iced::Command> { self.core_mut().title = title.clone(); command::set_title(title) } #[cfg(not(feature = "wayland"))] - fn set_title(&mut self, title: String) -> iced::Command> { + fn set_window_title(&mut self, title: String) -> iced::Command> { self.core_mut().title = title.clone(); iced::Command::none() }