From 6d94ce42353204a02fe9c82ed397d349439f75ef Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 17 Jun 2022 10:08:35 -0700 Subject: [PATCH] feat(core): theme is now implemented on macOS (#4380) --- .changes/theme-api-macos.md | 7 +++++++ core/tauri-runtime-wry/src/lib.rs | 5 +++-- core/tauri-utils/src/config.rs | 2 +- core/tauri/src/window.rs | 6 ++++-- tooling/api/src/window.ts | 11 +++++++---- tooling/cli/schema.json | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 .changes/theme-api-macos.md diff --git a/.changes/theme-api-macos.md b/.changes/theme-api-macos.md new file mode 100644 index 000000000..9150546f2 --- /dev/null +++ b/.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+. diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 5b137a69c..0f2126e6e 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/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) -> 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( ))] 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(); diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 47c89c608..98ab613cf 100644 --- a/core/tauri-utils/src/config.rs +++ b/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, } diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index e55d10b2b..d7171e2d1 100644 --- a/core/tauri/src/window.rs +++ b/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) -> Self { self.window_builder = self.window_builder.theme(theme); @@ -879,7 +880,8 @@ impl Window { /// /// ## 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 { self.window.dispatcher.theme().map_err(Into::into) } diff --git a/tooling/api/src/window.ts b/tooling/api/src/window.ts index ef5d03fdc..22dc587c5 100644 --- a/tooling/api/src/window.ts +++ b/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 { 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 } diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index 33376cab6..4168449c9 100644 --- a/tooling/cli/schema.json +++ b/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"