mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-16 19:30:27 +03:00
feat(api): add defaultWindowIcon
to app
module (#9979)
This commit is contained in:
parent
3ab170917e
commit
148f048871
7
.changes/api-app-defaultWindowIcon.md
Normal file
7
.changes/api-app-defaultWindowIcon.md
Normal 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.
|
||||
|
@ -139,6 +139,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
|
||||
("tauri_version", true),
|
||||
("app_show", false),
|
||||
("app_hide", false),
|
||||
("default_window_icon", false),
|
||||
],
|
||||
),
|
||||
(
|
||||
|
@ -4,6 +4,8 @@
|
||||
|`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.|
|
||||
|`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.|
|
||||
|`deny-name`|Denies the name 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
@ -5,7 +5,7 @@
|
||||
use crate::{
|
||||
command,
|
||||
plugin::{Builder, TauriPlugin},
|
||||
AppHandle, Runtime,
|
||||
AppHandle, Manager, ResourceId, Runtime, Webview,
|
||||
};
|
||||
|
||||
#[command(root = "crate")]
|
||||
@ -39,6 +39,17 @@ pub fn app_hide<R: Runtime>(app: AppHandle<R>) -> crate::Result<()> {
|
||||
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> {
|
||||
Builder::new("app")
|
||||
.invoke_handler(crate::generate_handler![
|
||||
@ -46,7 +57,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
name,
|
||||
tauri_version,
|
||||
app_show,
|
||||
app_hide
|
||||
app_hide,
|
||||
default_window_icon,
|
||||
])
|
||||
.build()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from './core'
|
||||
import { Image } from './image'
|
||||
|
||||
/**
|
||||
* Application metadata and related APIs.
|
||||
@ -83,4 +84,21 @@ async function hide(): Promise<void> {
|
||||
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 }
|
||||
|
Loading…
Reference in New Issue
Block a user