Skip to content

Commit

Permalink
feat(api): add defaultWindowIcon to app module (#9979)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Jun 5, 2024
1 parent 3ab1709 commit 148f048
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/api-app-defaultWindowIcon.md
Original file line number Diff line number Diff line change
@@ -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.

1 change: 1 addition & 0 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("tauri_version", true),
("app_show", false),
("app_hide", false),
("default_window_icon", false),
],
),
(
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/permissions/app/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions core/tauri/src/app/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::{
command,
plugin::{Builder, TauriPlugin},
AppHandle, Runtime,
AppHandle, Manager, ResourceId, Runtime, Webview,
};

#[command(root = "crate")]
Expand Down Expand Up @@ -39,14 +39,26 @@ 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![
version,
name,
tauri_version,
app_show,
app_hide
app_hide,
default_window_icon,
])
.build()
}
20 changes: 19 additions & 1 deletion tooling/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

import { invoke } from './core'
import { Image } from './image'

/**
* Application metadata and related APIs.
Expand Down Expand Up @@ -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 }

0 comments on commit 148f048

Please sign in to comment.