mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): theme is now implemented on macOS (#4380)
This commit is contained in:
committed by
GitHub
parent
7be997b974
commit
6d94ce4235
7
.changes/theme-api-macos.md
Normal file
7
.changes/theme-api-macos.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri": patch
|
||||
"tauri-runtime": patch
|
||||
"tauri-runtime-wry": patch
|
||||
---
|
||||
|
||||
The theme API is now implemented on macOS 10.14+.
|
||||
@@ -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();
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user