change the icon relative to the theme
This commit is contained in:
parent
58c3d40713
commit
0fa1f37474
2 changed files with 45 additions and 12 deletions
|
|
@ -78,16 +78,25 @@ pub fn run() {
|
||||||
))
|
))
|
||||||
.manage(Mutex::new(ShortcutToggleStates::default()))
|
.manage(Mutex::new(ShortcutToggleStates::default()))
|
||||||
.setup(move |app| {
|
.setup(move |app| {
|
||||||
// Log the current system theme
|
// Get the current theme to set the appropriate initial icon
|
||||||
if let Some(main_window) = app.get_webview_window("main") {
|
let initial_theme = if let Some(main_window) = app.get_webview_window("main") {
|
||||||
if let Ok(theme) = main_window.theme() {
|
main_window.theme().unwrap_or(tauri::Theme::Dark)
|
||||||
println!("System theme: {:?}", theme);
|
} else {
|
||||||
}
|
tauri::Theme::Dark
|
||||||
}
|
};
|
||||||
|
|
||||||
|
println!("Initial system theme: {:?}", initial_theme);
|
||||||
|
|
||||||
|
// Choose the appropriate initial icon based on theme
|
||||||
|
let initial_icon_path = match initial_theme {
|
||||||
|
tauri::Theme::Dark => "resources/tray_idle.png",
|
||||||
|
tauri::Theme::Light => "resources/tray_idle_dark.png",
|
||||||
|
_ => "resources/tray_idle.png", // Default fallback
|
||||||
|
};
|
||||||
|
|
||||||
let tray = TrayIconBuilder::new()
|
let tray = TrayIconBuilder::new()
|
||||||
.icon(Image::from_path(app.path().resolve(
|
.icon(Image::from_path(app.path().resolve(
|
||||||
"resources/tray_idle_dark.png",
|
initial_icon_path,
|
||||||
tauri::path::BaseDirectory::Resource,
|
tauri::path::BaseDirectory::Resource,
|
||||||
)?)?)
|
)?)?)
|
||||||
.show_menu_on_left_click(true)
|
.show_menu_on_left_click(true)
|
||||||
|
|
@ -158,6 +167,11 @@ pub fn run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tauri::WindowEvent::ThemeChanged(theme) => {
|
||||||
|
println!("Theme changed to: {:?}", theme);
|
||||||
|
// Update tray icon to match new theme, maintaining idle state
|
||||||
|
utils::change_tray_icon(&window.app_handle(), utils::TrayIconState::Idle);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use std::thread;
|
||||||
use tauri::image::Image;
|
use tauri::image::Image;
|
||||||
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
|
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
|
||||||
use tauri::tray::TrayIcon;
|
use tauri::tray::TrayIcon;
|
||||||
use tauri::{AppHandle, Emitter, Manager, WebviewWindowBuilder};
|
use tauri::{AppHandle, Emitter, Manager, Theme, WebviewWindowBuilder};
|
||||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||||
|
|
||||||
/// Sends a paste command (Cmd+V or Ctrl+V) using platform-specific virtual key codes.
|
/// Sends a paste command (Cmd+V or Ctrl+V) using platform-specific virtual key codes.
|
||||||
|
|
@ -82,13 +82,32 @@ pub enum TrayIconState {
|
||||||
Transcribing,
|
Transcribing,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the current system theme, defaulting to Dark if unavailable
|
||||||
|
fn get_current_theme(app: &AppHandle) -> Theme {
|
||||||
|
if let Some(main_window) = app.get_webview_window("main") {
|
||||||
|
main_window.theme().unwrap_or(Theme::Dark)
|
||||||
|
} else {
|
||||||
|
Theme::Dark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn change_tray_icon(app: &AppHandle, icon: TrayIconState) {
|
pub fn change_tray_icon(app: &AppHandle, icon: TrayIconState) {
|
||||||
let tray = app.state::<TrayIcon>();
|
let tray = app.state::<TrayIcon>();
|
||||||
|
let theme = get_current_theme(app);
|
||||||
|
|
||||||
let icon_path = match icon {
|
let icon_path = match (theme, &icon) {
|
||||||
TrayIconState::Idle => "resources/tray_idle.png",
|
// Dark theme uses regular icons (lighter colored for visibility)
|
||||||
TrayIconState::Recording => "resources/tray_recording.png",
|
(Theme::Dark, TrayIconState::Idle) => "resources/tray_idle.png",
|
||||||
TrayIconState::Transcribing => "resources/tray_transcribing.png",
|
(Theme::Dark, TrayIconState::Recording) => "resources/tray_recording.png",
|
||||||
|
(Theme::Dark, TrayIconState::Transcribing) => "resources/tray_transcribing.png",
|
||||||
|
// Light theme uses dark icons (darker colored for visibility)
|
||||||
|
(Theme::Light, TrayIconState::Idle) => "resources/tray_idle_dark.png",
|
||||||
|
(Theme::Light, TrayIconState::Recording) => "resources/tray_recording_dark.png",
|
||||||
|
(Theme::Light, TrayIconState::Transcribing) => "resources/tray_transcribing_dark.png",
|
||||||
|
// Fallback for any other theme variants
|
||||||
|
(_, TrayIconState::Idle) => "resources/tray_idle.png",
|
||||||
|
(_, TrayIconState::Recording) => "resources/tray_recording.png",
|
||||||
|
(_, TrayIconState::Transcribing) => "resources/tray_transcribing.png",
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = tray.set_icon(Some(
|
let _ = tray.set_icon(Some(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue