Skip to content

Commit

Permalink
Fix macOS auto theme
Browse files Browse the repository at this point in the history
  • Loading branch information
wyhaya committed Sep 14, 2024
1 parent 0858170 commit af846aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-theme"
links = "tauri-plugin-theme"
version = "2.1.0"
version = "2.1.1"
edition = "2021"
license = "MIT"
repository = "https://github.com/wyhaya/tauri-plugin-theme"
Expand Down Expand Up @@ -32,4 +32,4 @@ webview2-com = "0.33"
windows = "0.58"
windows-core = "0.58"
windows-version = "0.1"


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://github.com/wyhaya/tauri-plugin-theme/assets/23690145/2422ce95-418d-4f07-
## Install

```bash
cargo add tauri-plugin-theme@2.1.0
cargo add tauri-plugin-theme@2.1.1
```

```rust
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CONFIG_FILENAME: &str = "tauri-plugin-theme";
const ERROR_MESSAGE: &str = "Get app config dir failed";

pub fn init<R: Runtime>(config: &mut Config) -> TauriPlugin<R> {
#[cfg(any(target_os = "macos", target_os = "windows"))]
#[cfg(target_os = "windows")]
{
let theme = saved_theme_value_from_config(config);
for window in &mut config.app.windows {
Expand All @@ -26,9 +26,9 @@ pub fn init<R: Runtime>(config: &mut Config) -> TauriPlugin<R> {
Builder::new("theme")
.invoke_handler(generate_handler![get_theme, set_theme])
.on_event(|app, e| {
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
if let tauri::RunEvent::Ready = e {
if let Err(err) = set_theme(app.clone(), saved_theme_value(&app)) {
if let Err(err) = set_theme(app.clone(), saved_theme_value(app)) {
eprintln!("Failed to set theme: {}", err);
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ fn get_theme<R: Runtime>(app: AppHandle<R>) -> Result<Theme, ()> {
Ok(theme)
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
#[cfg(target_os = "windows")]
fn saved_theme_value_from_config(config: &Config) -> Theme {
if let Some(dir) = dirs_next::config_dir() {
let p = dir.join(&config.identifier).join(CONFIG_FILENAME);
Expand Down

0 comments on commit af846aa

Please sign in to comment.