Skip to content

Commit 233e43b

Browse files
feat: add title getter on window, closes #5023 (#5515)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent d0d873e commit 233e43b

File tree

11 files changed

+87
-83
lines changed

11 files changed

+87
-83
lines changed

.changes/title-getter.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": "minor"
3+
"api": "minor"
4+
"tauri-runtime": "minor"
5+
"tauri-runtime-wry": "minor"
6+
---
7+
8+
Add `title` getter on window.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ pub enum WindowMessage {
10281028
IsDecorated(Sender<bool>),
10291029
IsResizable(Sender<bool>),
10301030
IsVisible(Sender<bool>),
1031+
Title(Sender<String>),
10311032
IsMenuVisible(Sender<bool>),
10321033
CurrentMonitor(Sender<Option<MonitorHandle>>),
10331034
PrimaryMonitor(Sender<Option<MonitorHandle>>),
@@ -1262,6 +1263,10 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
12621263
window_getter!(self, WindowMessage::IsVisible)
12631264
}
12641265

1266+
fn title(&self) -> Result<String> {
1267+
window_getter!(self, WindowMessage::Title)
1268+
}
1269+
12651270
fn is_menu_visible(&self) -> Result<bool> {
12661271
window_getter!(self, WindowMessage::IsMenuVisible)
12671272
}
@@ -2349,6 +2354,7 @@ fn handle_user_message<T: UserEvent>(
23492354
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
23502355
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),
23512356
WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(),
2357+
WindowMessage::Title(tx) => tx.send(window.title()).unwrap(),
23522358
WindowMessage::IsMenuVisible(tx) => tx.send(window.is_menu_visible()).unwrap(),
23532359
WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
23542360
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),

core/tauri-runtime/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
536536

537537
/// Gets the window's current visibility state.
538538
fn is_visible(&self) -> Result<bool>;
539+
/// Gets the window's current title.
540+
fn title(&self) -> Result<String>;
539541

540542
/// Gets the window menu current visibility state.
541543
fn is_menu_visible(&self) -> Result<bool>;

core/tauri/scripts/bundle.global.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/endpoints/window.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub enum WindowManagerCmd {
6868
IsDecorated,
6969
IsResizable,
7070
IsVisible,
71+
Title,
7172
CurrentMonitor,
7273
PrimaryMonitor,
7374
AvailableMonitors,
@@ -259,6 +260,7 @@ impl Cmd {
259260
WindowManagerCmd::IsDecorated => return Ok(window.is_decorated()?.into()),
260261
WindowManagerCmd::IsResizable => return Ok(window.is_resizable()?.into()),
261262
WindowManagerCmd::IsVisible => return Ok(window.is_visible()?.into()),
263+
WindowManagerCmd::Title => return Ok(window.title()?.into()),
262264
WindowManagerCmd::CurrentMonitor => return Ok(window.current_monitor()?.into()),
263265
WindowManagerCmd::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
264266
WindowManagerCmd::AvailableMonitors => return Ok(window.available_monitors()?.into()),

core/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
379379
Ok(true)
380380
}
381381

382+
fn title(&self) -> Result<String> {
383+
Ok(String::new())
384+
}
385+
382386
fn is_menu_visible(&self) -> Result<bool> {
383387
Ok(true)
384388
}

core/tauri/src/window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,11 @@ impl<R: Runtime> Window<R> {
913913
self.window.dispatcher.is_visible().map_err(Into::into)
914914
}
915915

916+
/// Gets the window's current title.
917+
pub fn title(&self) -> crate::Result<String> {
918+
self.window.dispatcher.title().map_err(Into::into)
919+
}
920+
916921
/// Returns the monitor on which the window currently resides.
917922
///
918923
/// Returns None if current monitor can't be detected.

examples/api/dist/assets/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/dist/assets/index.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/Cargo.lock

Lines changed: 15 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)