feat(api): add defaultWindowIcon to app module (#9979)

This commit is contained in:
Amr Bashir 2024-06-05 19:17:06 +03:00 committed by GitHub
parent 3ab170917e
commit 148f048871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 4 deletions

View File

@ -0,0 +1,7 @@
---
"tauri": "patch:feat"
"@tauri-apps/api": "patch:feat"
---
Add `defaultWindowIcon` to the JS `app` module to retrieve the default window icon in JS.

View File

@ -139,6 +139,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("tauri_version", true), ("tauri_version", true),
("app_show", false), ("app_show", false),
("app_hide", false), ("app_hide", false),
("default_window_icon", false),
], ],
), ),
( (

View File

@ -4,6 +4,8 @@
|`deny-app-hide`|Denies the app_hide command without any pre-configured scope.| |`deny-app-hide`|Denies the app_hide command without any pre-configured scope.|
|`allow-app-show`|Enables the app_show command without any pre-configured scope.| |`allow-app-show`|Enables the app_show command without any pre-configured scope.|
|`deny-app-show`|Denies the app_show command without any pre-configured scope.| |`deny-app-show`|Denies the app_show command without any pre-configured scope.|
|`allow-default-window-icon`|Enables the default_window_icon command without any pre-configured scope.|
|`deny-default-window-icon`|Denies the default_window_icon command without any pre-configured scope.|
|`allow-name`|Enables the name command without any pre-configured scope.| |`allow-name`|Enables the name command without any pre-configured scope.|
|`deny-name`|Denies the name command without any pre-configured scope.| |`deny-name`|Denies the name command without any pre-configured scope.|
|`allow-tauri-version`|Enables the tauri_version command without any pre-configured scope.| |`allow-tauri-version`|Enables the tauri_version command without any pre-configured scope.|

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
use crate::{ use crate::{
command, command,
plugin::{Builder, TauriPlugin}, plugin::{Builder, TauriPlugin},
AppHandle, Runtime, AppHandle, Manager, ResourceId, Runtime, Webview,
}; };
#[command(root = "crate")] #[command(root = "crate")]
@ -39,6 +39,17 @@ pub fn app_hide<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
Ok(()) Ok(())
} }
#[command(root = "crate")]
pub fn default_window_icon<R: Runtime>(
webview: Webview<R>,
app: AppHandle<R>,
) -> Option<ResourceId> {
app.default_window_icon().cloned().map(|icon| {
let mut resources_table = webview.resources_table();
resources_table.add(icon.to_owned())
})
}
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("app") Builder::new("app")
.invoke_handler(crate::generate_handler![ .invoke_handler(crate::generate_handler![
@ -46,7 +57,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
name, name,
tauri_version, tauri_version,
app_show, app_show,
app_hide app_hide,
default_window_icon,
]) ])
.build() .build()
} }

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { invoke } from './core' import { invoke } from './core'
import { Image } from './image'
/** /**
* Application metadata and related APIs. * Application metadata and related APIs.
@ -83,4 +84,21 @@ async function hide(): Promise<void> {
return invoke('plugin:app|app_hide') return invoke('plugin:app|app_hide')
} }
export { getName, getVersion, getTauriVersion, show, hide } /**
* Get the default window icon.
*
* @example
* ```typescript
* import { defaultWindowIcon } from '@tauri-apps/api/app';
* await defaultWindowIcon();
* ```
*
* @since 2.0.0
*/
async function defaultWindowIcon(): Promise<Image | null> {
return invoke<number | null>('plugin:app|default_window_icon').then((rid) =>
rid ? new Image(rid) : null
)
}
export { getName, getVersion, getTauriVersion, show, hide, defaultWindowIcon }