Skip to content

Commit

Permalink
feat(core): theme is now implemented on macOS (#4380)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 17, 2022
1 parent 7be997b commit 6d94ce4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changes/theme-api-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

The theme API is now implemented on macOS 10.14+.
5 changes: 3 additions & 2 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -916,6 +916,7 @@ impl WindowBuilder for WindowBuilderWrapper {
None
});
}

self
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down
6 changes: 4 additions & 2 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 7 additions & 4 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6d94ce4

Please sign in to comment.