Просмотр исходного кода

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

Amr Bashir 1 год назад
Родитель
Сommit
148f048871

+ 7 - 0
.changes/api-app-defaultWindowIcon.md

@@ -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 - 0
core/tauri/build.rs

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

+ 2 - 0
core/tauri/permissions/app/autogenerated/reference.md

@@ -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.|

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
core/tauri/scripts/bundle.global.js


+ 14 - 2
core/tauri/src/app/plugin.rs

@@ -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()
 }

+ 19 - 1
tooling/api/src/app.ts

@@ -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 }

Некоторые файлы не были показаны из-за большого количества измененных файлов