Skip to content

Commit f21cbec

Browse files
authored
feat(core): implement theme APIs for Linux (#4808)
1 parent 331f346 commit f21cbec

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

.changes/linux-theme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-runtime-wry": patch
3+
"tauri": patch
4+
---
5+
6+
Implement theme APIs for Linux.

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -907,17 +907,14 @@ impl WindowBuilder for WindowBuilderWrapper {
907907

908908
#[allow(unused_variables, unused_mut)]
909909
fn theme(mut self, theme: Option<Theme>) -> Self {
910-
#[cfg(any(windows, target_os = "macos"))]
911-
{
912-
self.inner = self.inner.with_theme(if let Some(t) = theme {
913-
match t {
914-
Theme::Dark => Some(WryTheme::Dark),
915-
_ => Some(WryTheme::Light),
916-
}
917-
} else {
918-
None
919-
});
920-
}
910+
self.inner = self.inner.with_theme(if let Some(t) = theme {
911+
match t {
912+
Theme::Dark => Some(WryTheme::Dark),
913+
_ => Some(WryTheme::Light),
914+
}
915+
} else {
916+
None
917+
});
921918

922919
self
923920
}
@@ -2304,10 +2301,7 @@ fn handle_user_message<T: UserEvent>(
23042301
.send(RawWindowHandle(window.raw_window_handle()))
23052302
.unwrap(),
23062303
WindowMessage::Theme(tx) => {
2307-
#[cfg(any(windows, target_os = "macos"))]
23082304
tx.send(map_theme(&window.theme())).unwrap();
2309-
#[cfg(not(any(windows, target_os = "macos")))]
2310-
tx.send(Theme::Light).unwrap();
23112305
}
23122306
// Setters
23132307
WindowMessage::Center => {

core/tauri-runtime/src/window.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ pub enum WindowEvent {
6262
/// The system window theme has changed.
6363
///
6464
/// Applications might wish to react to this to change the theme of the content of the window when the system changes the window theme.
65-
///
66-
/// At the moment this is only supported on Windows.
6765
ThemeChanged(Theme),
6866
}
6967

core/tauri/src/app.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,13 @@ pub enum WindowEvent {
119119
},
120120
/// An event associated with the file drop action.
121121
FileDrop(FileDropEvent),
122-
/// The system window theme has changed.
122+
/// The system window theme has changed. Only delivered if the window [`theme`](`crate::window::WindowBuilder#method.theme`) is `None`.
123123
///
124124
/// Applications might wish to react to this to change the theme of the content of the window when the system changes the window theme.
125125
///
126126
/// ## Platform-specific
127127
///
128-
/// - **macOS / Linux**: Not supported.
129-
/// - **Windows**: Only delivered if the window [`theme`](`crate::window::WindowBuilder#method.theme`) is `None`.
128+
/// - **Linux**: Not supported.
130129
ThemeChanged(Theme),
131130
}
132131

core/tauri/src/window.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
352352
/// ## Platform-specific
353353
///
354354
/// - **macOS**: Only supported on macOS 10.14+.
355-
/// - **Linux**: Not implemented, the value is ignored.
356355
#[must_use]
357356
pub fn theme(mut self, theme: Option<Theme>) -> Self {
358357
self.window_builder = self.window_builder.theme(theme);
@@ -937,7 +936,6 @@ impl<R: Runtime> Window<R> {
937936
/// ## Platform-specific
938937
///
939938
/// - **macOS**: Only supported on macOS 10.14+.
940-
/// - **Linux**: Not implemented, always return [`Theme::Light`].
941939
pub fn theme(&self) -> crate::Result<Theme> {
942940
self.window.dispatcher.theme().map_err(Into::into)
943941
}

0 commit comments

Comments
 (0)