Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add title getter on window, closes #5023 #5515

Merged
merged 8 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/title-getter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"tauri": "minor"
"api": "minor"
"tauri-runtime": "minor"
"tauri-runtime-wry": "minor"
---

Add `title` getter on window.
6 changes: 6 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ pub enum WindowMessage {
IsDecorated(Sender<bool>),
IsResizable(Sender<bool>),
IsVisible(Sender<bool>),
Title(Sender<String>),
IsMenuVisible(Sender<bool>),
CurrentMonitor(Sender<Option<MonitorHandle>>),
PrimaryMonitor(Sender<Option<MonitorHandle>>),
Expand Down Expand Up @@ -1262,6 +1263,10 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
window_getter!(self, WindowMessage::IsVisible)
}

fn title(&self) -> Result<String> {
window_getter!(self, WindowMessage::Title)
}

fn is_menu_visible(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsMenuVisible)
}
Expand Down Expand Up @@ -2349,6 +2354,7 @@ fn handle_user_message<T: UserEvent>(
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),
WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(),
WindowMessage::Title(tx) => tx.send(window.title()).unwrap(),
WindowMessage::IsMenuVisible(tx) => tx.send(window.is_menu_visible()).unwrap(),
WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
Expand Down
2 changes: 2 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static

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

/// Gets the window menu current visibility state.
fn is_menu_visible(&self) -> Result<bool>;
Expand Down
8 changes: 4 additions & 4 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/tauri/src/endpoints/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum WindowManagerCmd {
IsDecorated,
IsResizable,
IsVisible,
Title,
CurrentMonitor,
PrimaryMonitor,
AvailableMonitors,
Expand Down Expand Up @@ -259,6 +260,7 @@ impl Cmd {
WindowManagerCmd::IsDecorated => return Ok(window.is_decorated()?.into()),
WindowManagerCmd::IsResizable => return Ok(window.is_resizable()?.into()),
WindowManagerCmd::IsVisible => return Ok(window.is_visible()?.into()),
WindowManagerCmd::Title => return Ok(window.title()?.into()),
WindowManagerCmd::CurrentMonitor => return Ok(window.current_monitor()?.into()),
WindowManagerCmd::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
WindowManagerCmd::AvailableMonitors => return Ok(window.available_monitors()?.into()),
Expand Down
4 changes: 4 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Ok(true)
}

fn title(&self) -> Result<String> {
Ok(String::new())
}

fn is_menu_visible(&self) -> Result<bool> {
Ok(true)
}
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ impl<R: Runtime> Window<R> {
self.window.dispatcher.is_visible().map_err(Into::into)
}

/// Gets the window's current title.
pub fn title(&self) -> crate::Result<String> {
self.window.dispatcher.title().map_err(Into::into)
}

/// Returns the monitor on which the window currently resides.
///
/// Returns None if current monitor can't be detected.
Expand Down
2 changes: 1 addition & 1 deletion examples/api/dist/assets/index.css

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions examples/api/dist/assets/index.js

Large diffs are not rendered by default.

78 changes: 15 additions & 63 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 40 additions & 15 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,31 @@ class WindowManager extends WebviewWindowHandle {
})
}

/**
* Gets the window's current title.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const title = await appWindow.title();
* ```
*
* @since 1.3.0
* */
async title(): Promise<string> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
label: this.label,
cmd: {
type: 'title'
}
}
}
})
}

/**
* Gets the window's current theme.
*
Expand Down Expand Up @@ -1184,12 +1209,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMinSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
}
}
Expand Down Expand Up @@ -1226,12 +1251,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMaxSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
}
}
Expand Down Expand Up @@ -2091,11 +2116,11 @@ function mapMonitor(m: Monitor | null): Monitor | null {
return m === null
? null
: {
name: m.name,
scaleFactor: m.scaleFactor,
position: new PhysicalPosition(m.position.x, m.position.y),
size: new PhysicalSize(m.size.width, m.size.height)
}
name: m.name,
scaleFactor: m.scaleFactor,
position: new PhysicalPosition(m.position.x, m.position.y),
size: new PhysicalSize(m.size.width, m.size.height)
}
}

/**
Expand Down