Эх сурвалжийг харах

feat(core): theme is now implemented on macOS (#4380)

Lucas Fernandes Nogueira 3 жил өмнө
parent
commit
6d94ce4235

+ 7 - 0
.changes/theme-api-macos.md

@@ -0,0 +1,7 @@
+---
+"tauri": patch
+"tauri-runtime": patch
+"tauri-runtime-wry": patch
+---
+
+The theme API is now implemented on macOS 10.14+.

+ 3 - 2
core/tauri-runtime-wry/src/lib.rs

@@ -905,7 +905,7 @@ impl WindowBuilder for WindowBuilderWrapper {
 
   #[allow(unused_variables, unused_mut)]
   fn theme(mut self, theme: Option<Theme>) -> Self {
-    #[cfg(windows)]
+    #[cfg(any(windows, target_os = "macos"))]
     {
       self.inner = self.inner.with_theme(if let Some(t) = theme {
         match t {
@@ -916,6 +916,7 @@ impl WindowBuilder for WindowBuilderWrapper {
         None
       });
     }
+
     self
   }
 
@@ -2322,7 +2323,7 @@ fn handle_user_message<T: UserEvent>(
           ))]
           WindowMessage::GtkWindow(tx) => tx.send(GtkWindow(window.gtk_window().clone())).unwrap(),
           WindowMessage::Theme(tx) => {
-            #[cfg(windows)]
+            #[cfg(any(windows, target_os = "macos"))]
             tx.send(map_theme(&window.theme())).unwrap();
             #[cfg(not(windows))]
             tx.send(Theme::Light).unwrap();

+ 1 - 1
core/tauri-utils/src/config.rs

@@ -600,7 +600,7 @@ pub struct WindowConfig {
   /// Whether or not the window icon should be added to the taskbar.
   #[serde(default)]
   pub skip_taskbar: bool,
-  /// The initial window theme. Defaults to the system theme. Only implemented on Windows.
+  /// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
   pub theme: Option<crate::Theme>,
 }
 

+ 4 - 2
core/tauri/src/window.rs

@@ -349,7 +349,8 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
   ///
   /// ## Platform-specific
   ///
-  /// - **macOS / Linux**: Not implemented, the value is ignored.
+  /// - **macOS**: Only supported on macOS 10.14+.
+  /// - **Linux**: Not implemented, the value is ignored.
   #[must_use]
   pub fn theme(mut self, theme: Option<Theme>) -> Self {
     self.window_builder = self.window_builder.theme(theme);
@@ -879,7 +880,8 @@ impl<R: Runtime> Window<R> {
   ///
   /// ## Platform-specific
   ///
-  /// - **macOS / Linux**: Not implemented, always return [`Theme::Light`].
+  /// - **macOS**: Only supported on macOS 10.14+.
+  /// - **Linux**: Not implemented, always return [`Theme::Light`].
   pub fn theme(&self) -> crate::Result<Theme> {
     self.window.dispatcher.theme().map_err(Into::into)
   }

+ 7 - 4
tooling/api/src/window.ts

@@ -651,14 +651,17 @@ class WindowManager extends WebviewWindowHandle {
   }
 
   /**
-   * Gets the window's current visible state.
+   * Gets the window's current theme.
+   *
+   * Only implemented on Windows and macOS 10.14+.
+   *
    * @example
    * ```typescript
    * import { appWindow } from '@tauri-apps/api/window';
    * const theme = await appWindow.theme();
    * ```
    *
-   * @returns The system theme.
+   * @returns The window theme.
    * */
   async theme(): Promise<Theme | null> {
     return invokeTauriCommand({
@@ -1674,9 +1677,9 @@ interface WindowOptions {
    */
   fileDropEnabled?: boolean
   /**
-   *  The initial window theme. Defaults to the system theme.
+   * The initial window theme. Defaults to the system theme.
    *
-   * Only implemented on Windows.
+   * Only implemented on Windows and macOS 10.14+.
    */
   theme?: Theme
 }

+ 1 - 1
tooling/cli/schema.json

@@ -607,7 +607,7 @@
           "type": "boolean"
         },
         "theme": {
-          "description": "The initial window theme. Defaults to the system theme. Only implemented on Windows.",
+          "description": "The initial window theme. Defaults to the system theme. Only implemented on Windows and macOs 10.14+.",
           "anyOf": [
             {
               "$ref": "#/definitions/Theme"