Skip to content

Commit

Permalink
feat(core): implement theme APIs for Linux (#4808)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 2, 2022
1 parent 331f346 commit f21cbec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changes/linux-theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-runtime-wry": patch
"tauri": patch
---

Implement theme APIs for Linux.
22 changes: 8 additions & 14 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,14 @@ impl WindowBuilder for WindowBuilderWrapper {

#[allow(unused_variables, unused_mut)]
fn theme(mut self, theme: Option<Theme>) -> Self {
#[cfg(any(windows, target_os = "macos"))]
{
self.inner = self.inner.with_theme(if let Some(t) = theme {
match t {
Theme::Dark => Some(WryTheme::Dark),
_ => Some(WryTheme::Light),
}
} else {
None
});
}
self.inner = self.inner.with_theme(if let Some(t) = theme {
match t {
Theme::Dark => Some(WryTheme::Dark),
_ => Some(WryTheme::Light),
}
} else {
None
});

self
}
Expand Down Expand Up @@ -2304,10 +2301,7 @@ fn handle_user_message<T: UserEvent>(
.send(RawWindowHandle(window.raw_window_handle()))
.unwrap(),
WindowMessage::Theme(tx) => {
#[cfg(any(windows, target_os = "macos"))]
tx.send(map_theme(&window.theme())).unwrap();
#[cfg(not(any(windows, target_os = "macos")))]
tx.send(Theme::Light).unwrap();
}
// Setters
WindowMessage::Center => {
Expand Down
2 changes: 0 additions & 2 deletions core/tauri-runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ pub enum WindowEvent {
/// The system window theme has changed.
///
/// Applications might wish to react to this to change the theme of the content of the window when the system changes the window theme.
///
/// At the moment this is only supported on Windows.
ThemeChanged(Theme),
}

Expand Down
5 changes: 2 additions & 3 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ pub enum WindowEvent {
},
/// An event associated with the file drop action.
FileDrop(FileDropEvent),
/// The system window theme has changed.
/// The system window theme has changed. Only delivered if the window [`theme`](`crate::window::WindowBuilder#method.theme`) is `None`.
///
/// Applications might wish to react to this to change the theme of the content of the window when the system changes the window theme.
///
/// ## Platform-specific
///
/// - **macOS / Linux**: Not supported.
/// - **Windows**: Only delivered if the window [`theme`](`crate::window::WindowBuilder#method.theme`) is `None`.
/// - **Linux**: Not supported.
ThemeChanged(Theme),
}

Expand Down
2 changes: 0 additions & 2 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
/// ## Platform-specific
///
/// - **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 @@ -937,7 +936,6 @@ impl<R: Runtime> Window<R> {
/// ## Platform-specific
///
/// - **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

0 comments on commit f21cbec

Please sign in to comment.