File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ fn run_tray_app(
136136 }
137137
138138 let proxy = event_loop. create_proxy ( ) ;
139+ let signal_proxy = event_loop. create_proxy ( ) ;
139140
140141 // Command channel: tray UI → background daemon.
141142 let ( cmd_tx, cmd_rx) = tokio:: sync:: mpsc:: channel :: < DaemonCommand > ( 8 ) ;
@@ -168,7 +169,7 @@ fn run_tray_app(
168169 }
169170
170171 // Catch SIGTERM (sent by launchd on service stop / system shutdown)
171- // and trigger a graceful shutdown through the daemon command channel .
172+ // and trigger a graceful shutdown through both the daemon and the event loop .
172173 {
173174 let sigterm_tx = cmd_tx. clone ( ) ;
174175 std:: thread:: Builder :: new ( )
@@ -191,10 +192,10 @@ fn run_tray_app(
191192 tokio:: signal:: ctrl_c ( ) . await . ok ( ) ;
192193 }
193194 info ! ( "received shutdown signal" ) ;
194- if sigterm_tx . send ( DaemonCommand :: Shutdown ) . await . is_err ( ) {
195- // Daemon already exited — nothing to shut down.
196- std :: process :: exit ( 0 ) ;
197- }
195+ // Tell the daemon to clean up HID resources.
196+ let _ = sigterm_tx . send ( DaemonCommand :: Shutdown ) . await ;
197+ // Tell the event loop to exit (works even if daemon already exited).
198+ let _ = signal_proxy . send_event ( DaemonEvent :: Shutdown ) ;
198199 } ) ;
199200 } )
200201 . expect ( "signal handler thread" ) ;
You can’t perform that action at this time.
0 commit comments