@@ -6,53 +6,39 @@ use tauri::{
66 tray:: { MouseButton , MouseButtonState , TrayIconBuilder , TrayIconEvent } ,
77} ;
88use raw_window_handle:: HasWindowHandle ;
9- // no direct Emitter usage here; native thumbar sends media keys directly
109
1110mod thumbar;
1211
13- // Note: we removed the `native_set_playing` command — the native thumbar
14- // uses static icons now and the renderer/plugin is authoritative for
15- // playback state. Renderer should listen for `thumbar-*` events and act.
16-
1712#[ tauri:: command]
1813fn native_add_thumb_buttons ( ) {
19- // Call into the native module to (re)create the thumbbar buttons.
2014 thumbar:: add_thumb_buttons ( ) ;
2115}
2216
2317#[ tauri:: command]
2418fn native_remove_thumb_buttons ( ) {
25- // Remove the subclass and cleanup native icons.
2619 thumbar:: remove_thumb_buttons ( ) ;
2720}
2821
2922fn main ( ) {
3023 tauri:: Builder :: default ( )
3124 . invoke_handler ( tauri:: generate_handler![ native_add_thumb_buttons, native_remove_thumb_buttons] )
32- . on_page_load ( |_window, _payload| {
33- // When the page finishes loading, create the native thumbbar
34- // buttons for the main window so they appear automatically.
35- // The HWND is stored during `setup` so the native loader will
36- // be able to call ThumbBarAddButtons.
25+ . on_page_load ( |_window, _payload| {
3726 let _ = thumbar:: add_thumb_buttons ( ) ;
3827 } )
3928 . plugin ( tauri_plugin_media:: init ( ) )
40- . plugin ( tauri_plugin_single_instance:: init ( |_app, _args, _cwd| { } ) )
29+ . plugin ( tauri_plugin_single_instance:: init ( |app, _args, _cwd| {
30+ if let Some ( window) = app. get_webview_window ( "main" ) {
31+ let _ = window. unminimize ( ) ;
32+ let _ = window. show ( ) ;
33+ let _ = window. set_focus ( ) ;
34+ }
35+ } ) )
4136 . setup ( |app| {
42- // On Windows, set an explicit AppUserModelID so Explorer
43- // associates this process with the application identity and
44- // (when possible) updates the taskbar/pinned icon. This helps
45- // when icons change during development.
4637 #[ cfg( target_os = "windows" ) ]
4738 {
4839 use windows:: core:: PCWSTR ;
4940 use windows:: Win32 :: UI :: Shell :: SetCurrentProcessExplicitAppUserModelID ;
5041
51- // Use different AppUserModelID for dev vs release builds so Windows
52- // doesn't try to use the icon from the installed app location when
53- // running dev builds. This prevents the "icon not found" issue where
54- // Explorer looks for C:\Program Files\qobuz-player\qobuz-player.exe
55- // which doesn't exist during development.
5642 #[ cfg( debug_assertions) ]
5743 let app_id = "com.leo.qobuz-player.dev" ;
5844 #[ cfg( not( debug_assertions) ) ]
@@ -62,14 +48,11 @@ fn main() {
6248 let pcw = PCWSTR ( id. as_ptr ( ) ) ;
6349 let _ = unsafe { SetCurrentProcessExplicitAppUserModelID ( pcw) } ;
6450 }
65- // Build menu items (only production items). The dev helper was
66- // intentionally removed so development helpers don't clutter the
67- // codebase — continue developing the thumbar feature instead.
51+
6852 let show = MenuItem :: with_id ( app, "show" , "Show" , true , None :: < & str > ) ?;
6953 let quit = MenuItem :: with_id ( app, "quit" , "Quit" , true , None :: < & str > ) ?;
7054 let menu = Menu :: with_items ( app, & [ & show, & quit] ) ?;
7155
72- // Create tray icon
7356 TrayIconBuilder :: new ( )
7457 . icon ( app. default_window_icon ( ) . unwrap ( ) . clone ( ) )
7558 . menu ( & menu)
@@ -95,7 +78,6 @@ fn main() {
9578 } => {
9679 let app = tray. app_handle ( ) ;
9780 if let Some ( window) = app. get_webview_window ( "main" ) {
98- // Toggle: if visible -> hide to tray; otherwise show/restore.
9981 match window. is_visible ( ) {
10082 Ok ( true ) => {
10183 let _ = window. hide ( ) ;
@@ -104,8 +86,7 @@ fn main() {
10486 let _ = window. unminimize ( ) ;
10587 let _ = window. show ( ) ;
10688 let _ = window. set_focus ( ) ;
107- // Reinitialize thumbar for this window in case the
108- // HWND changed during hide/minimize.
89+
10990 #[ cfg( target_os = "windows" ) ]
11091 if let Ok ( wh) = window. window_handle ( ) {
11192 match wh. into ( ) {
@@ -123,13 +104,9 @@ fn main() {
123104 _ => { }
124105 } )
125106 . build ( app) ?;
126- // Initialize the thumbar scaffolding (Windows-only integration point)
127- // Pass the `App` reference so the thumbar module can locate the
128- // main window and emit events via the app handle.
107+
129108 thumbar:: init_thumbar ( app, "main" ) ;
130- // Attempt to store the main webview HWND now so native code can
131- // call ThumbBarAddButtons. This mirrors the logic used when the
132- // tray toggles the window and ensures a stored HWND early.
109+
133110 if let Some ( window) = app. get_webview_window ( "main" ) {
134111 if let Ok ( wh) = window. window_handle ( ) {
135112 match wh. into ( ) {
@@ -140,18 +117,7 @@ fn main() {
140117 }
141118 }
142119 }
143- // Thumbbar clicks are handled by the native module which now
144- // converts them into system media key events. Media state and
145- // SMTC integration are handled by `tauri-plugin-media`.
146- // We'll add the thumbbar buttons once the page loads so buttons
147- // appear automatically. Frontend can still call the commands
148- // `native_set_playing`, `native_add_thumb_buttons` and
149- // `native_remove_thumb_buttons` as needed to update state.
150- // Use `on_page_load` to trigger native creation when the main
151- // webview finishes loading.
152- // Note: we register the on_page_load handler on the Builder below.
153- // Thumbar scaffolding initialized; frontend can be wired to events
154- // once native thumbar implementation is present.
120+
155121 Ok ( ( ) )
156122 } )
157123 . on_window_event ( |app, event| {
0 commit comments