Skip to content

Commit 148f048

Browse files
authored
feat(api): add defaultWindowIcon to app module (#9979)
1 parent 3ab1709 commit 148f048

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": "patch:feat"
3+
"@tauri-apps/api": "patch:feat"
4+
---
5+
6+
Add `defaultWindowIcon` to the JS `app` module to retrieve the default window icon in JS.
7+

core/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
139139
("tauri_version", true),
140140
("app_show", false),
141141
("app_hide", false),
142+
("default_window_icon", false),
142143
],
143144
),
144145
(

core/tauri/permissions/app/autogenerated/reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
|`deny-app-hide`|Denies the app_hide command without any pre-configured scope.|
55
|`allow-app-show`|Enables the app_show command without any pre-configured scope.|
66
|`deny-app-show`|Denies the app_show command without any pre-configured scope.|
7+
|`allow-default-window-icon`|Enables the default_window_icon command without any pre-configured scope.|
8+
|`deny-default-window-icon`|Denies the default_window_icon command without any pre-configured scope.|
79
|`allow-name`|Enables the name command without any pre-configured scope.|
810
|`deny-name`|Denies the name command without any pre-configured scope.|
911
|`allow-tauri-version`|Enables the tauri_version command without any pre-configured scope.|

core/tauri/scripts/bundle.global.js

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

core/tauri/src/app/plugin.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::{
66
command,
77
plugin::{Builder, TauriPlugin},
8-
AppHandle, Runtime,
8+
AppHandle, Manager, ResourceId, Runtime, Webview,
99
};
1010

1111
#[command(root = "crate")]
@@ -39,14 +39,26 @@ pub fn app_hide<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
3939
Ok(())
4040
}
4141

42+
#[command(root = "crate")]
43+
pub fn default_window_icon<R: Runtime>(
44+
webview: Webview<R>,
45+
app: AppHandle<R>,
46+
) -> Option<ResourceId> {
47+
app.default_window_icon().cloned().map(|icon| {
48+
let mut resources_table = webview.resources_table();
49+
resources_table.add(icon.to_owned())
50+
})
51+
}
52+
4253
pub fn init<R: Runtime>() -> TauriPlugin<R> {
4354
Builder::new("app")
4455
.invoke_handler(crate::generate_handler![
4556
version,
4657
name,
4758
tauri_version,
4859
app_show,
49-
app_hide
60+
app_hide,
61+
default_window_icon,
5062
])
5163
.build()
5264
}

tooling/api/src/app.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: MIT
44

55
import { invoke } from './core'
6+
import { Image } from './image'
67

78
/**
89
* Application metadata and related APIs.
@@ -83,4 +84,21 @@ async function hide(): Promise<void> {
8384
return invoke('plugin:app|app_hide')
8485
}
8586

86-
export { getName, getVersion, getTauriVersion, show, hide }
87+
/**
88+
* Get the default window icon.
89+
*
90+
* @example
91+
* ```typescript
92+
* import { defaultWindowIcon } from '@tauri-apps/api/app';
93+
* await defaultWindowIcon();
94+
* ```
95+
*
96+
* @since 2.0.0
97+
*/
98+
async function defaultWindowIcon(): Promise<Image | null> {
99+
return invoke<number | null>('plugin:app|default_window_icon').then((rid) =>
100+
rid ? new Image(rid) : null
101+
)
102+
}
103+
104+
export { getName, getVersion, getTauriVersion, show, hide, defaultWindowIcon }

0 commit comments

Comments
 (0)