Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

change the icon relative to the theme

CJ Pais0fa1f37474b6
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 436ab3c8..11d54ba3 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -78,16 +78,25 @@ pub fn run() {
))
.manage(Mutex::new(ShortcutToggleStates::default()))
.setup(move |app| {
- // Log the current system theme
- if let Some(main_window) = app.get_webview_window("main") {
- if let Ok(theme) = main_window.theme() {
- println!("System theme: {:?}", theme);
- }
- }
+ // Get the current theme to set the appropriate initial icon
+ let initial_theme = if let Some(main_window) = app.get_webview_window("main") {
+ main_window.theme().unwrap_or(tauri::Theme::Dark)
+ } 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()
.icon(Image::from_path(app.path().resolve(
- "resources/tray_idle_dark.png",
+ initial_icon_path,
tauri::path::BaseDirectory::Resource,
)?)?)
.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![
diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs
index eae3d250..f7ffe34d 100644
--- a/src-tauri/src/utils.rs
+++ b/src-tauri/src/utils.rs
@@ -14,7 +14,7 @@ use std::thread;
use tauri::image::Image;
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
use tauri::tray::TrayIcon;
-use tauri::{AppHandle, Emitter, Manager, WebviewWindowBuilder};
+use tauri::{AppHandle, Emitter, Manager, Theme, WebviewWindowBuilder};
use tauri_plugin_clipboard_manager::ClipboardExt;
/// Sends a paste command (Cmd+V or Ctrl+V) using platform-specific virtual key codes.
@@ -82,13 +82,32 @@ pub enum TrayIconState {
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) {
let tray = app.state::<TrayIcon>();
-
- let icon_path = match icon {
- TrayIconState::Idle => "resources/tray_idle.png",
- TrayIconState::Recording => "resources/tray_recording.png",
- TrayIconState::Transcribing => "resources/tray_transcribing.png",
+ let theme = get_current_theme(app);
+
+ let icon_path = match (theme, &icon) {
+ // Dark theme uses regular icons (lighter colored for visibility)
+ (Theme::Dark, TrayIconState::Idle) => "resources/tray_idle.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(