Skip to content

Commit 6d94ce4

Browse files
authored
feat(core): theme is now implemented on macOS (#4380)
1 parent 7be997b commit 6d94ce4

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

.changes/theme-api-macos.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
"tauri-runtime-wry": patch
5+
---
6+
7+
The theme API is now implemented on macOS 10.14+.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl WindowBuilder for WindowBuilderWrapper {
905905

906906
#[allow(unused_variables, unused_mut)]
907907
fn theme(mut self, theme: Option<Theme>) -> Self {
908-
#[cfg(windows)]
908+
#[cfg(any(windows, target_os = "macos"))]
909909
{
910910
self.inner = self.inner.with_theme(if let Some(t) = theme {
911911
match t {
@@ -916,6 +916,7 @@ impl WindowBuilder for WindowBuilderWrapper {
916916
None
917917
});
918918
}
919+
919920
self
920921
}
921922

@@ -2322,7 +2323,7 @@ fn handle_user_message<T: UserEvent>(
23222323
))]
23232324
WindowMessage::GtkWindow(tx) => tx.send(GtkWindow(window.gtk_window().clone())).unwrap(),
23242325
WindowMessage::Theme(tx) => {
2325-
#[cfg(windows)]
2326+
#[cfg(any(windows, target_os = "macos"))]
23262327
tx.send(map_theme(&window.theme())).unwrap();
23272328
#[cfg(not(windows))]
23282329
tx.send(Theme::Light).unwrap();

core/tauri-utils/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ pub struct WindowConfig {
600600
/// Whether or not the window icon should be added to the taskbar.
601601
#[serde(default)]
602602
pub skip_taskbar: bool,
603-
/// The initial window theme. Defaults to the system theme. Only implemented on Windows.
603+
/// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
604604
pub theme: Option<crate::Theme>,
605605
}
606606

core/tauri/src/window.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
349349
///
350350
/// ## Platform-specific
351351
///
352-
/// - **macOS / Linux**: Not implemented, the value is ignored.
352+
/// - **macOS**: Only supported on macOS 10.14+.
353+
/// - **Linux**: Not implemented, the value is ignored.
353354
#[must_use]
354355
pub fn theme(mut self, theme: Option<Theme>) -> Self {
355356
self.window_builder = self.window_builder.theme(theme);
@@ -879,7 +880,8 @@ impl<R: Runtime> Window<R> {
879880
///
880881
/// ## Platform-specific
881882
///
882-
/// - **macOS / Linux**: Not implemented, always return [`Theme::Light`].
883+
/// - **macOS**: Only supported on macOS 10.14+.
884+
/// - **Linux**: Not implemented, always return [`Theme::Light`].
883885
pub fn theme(&self) -> crate::Result<Theme> {
884886
self.window.dispatcher.theme().map_err(Into::into)
885887
}

tooling/api/src/window.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,17 @@ class WindowManager extends WebviewWindowHandle {
651651
}
652652

653653
/**
654-
* Gets the window's current visible state.
654+
* Gets the window's current theme.
655+
*
656+
* Only implemented on Windows and macOS 10.14+.
657+
*
655658
* @example
656659
* ```typescript
657660
* import { appWindow } from '@tauri-apps/api/window';
658661
* const theme = await appWindow.theme();
659662
* ```
660663
*
661-
* @returns The system theme.
664+
* @returns The window theme.
662665
* */
663666
async theme(): Promise<Theme | null> {
664667
return invokeTauriCommand({
@@ -1674,9 +1677,9 @@ interface WindowOptions {
16741677
*/
16751678
fileDropEnabled?: boolean
16761679
/**
1677-
* The initial window theme. Defaults to the system theme.
1680+
* The initial window theme. Defaults to the system theme.
16781681
*
1679-
* Only implemented on Windows.
1682+
* Only implemented on Windows and macOS 10.14+.
16801683
*/
16811684
theme?: Theme
16821685
}

tooling/cli/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
"type": "boolean"
608608
},
609609
"theme": {
610-
"description": "The initial window theme. Defaults to the system theme. Only implemented on Windows.",
610+
"description": "The initial window theme. Defaults to the system theme. Only implemented on Windows and macOs 10.14+.",
611611
"anyOf": [
612612
{
613613
"$ref": "#/definitions/Theme"

0 commit comments

Comments
 (0)