@@ -58,7 +58,6 @@ fn main() {
5858 let cli = Cli :: parse ( ) ;
5959 let mut state = State :: load ( ) . unwrap ( ) ;
6060
61- // Special handling for the 'stop' command, which doesn't need the full manager setup.
6261 if let Some ( Commands :: Stop ) = cli. command {
6362 handle_command ! ( kill_process_group( & mut state) ) ;
6463 return ;
@@ -95,13 +94,16 @@ fn main() {
9594 // Handle unclean ends where possible.
9695 let original_hook = panic:: take_hook ( ) ;
9796 panic:: set_hook ( Box :: new ( move |panic_info| {
98- let mut state = State :: load ( ) . unwrap ( ) ;
99- state. process_group_id = None ;
100- state. save ( ) . unwrap ( ) ;
97+ if let Ok ( mut state) = State :: load ( ) {
98+ state. process_group_id = None ;
99+ if let Err ( e) = state. save ( ) {
100+ eprintln ! ( "Failed to save state in panic hook: {e}" ) ;
101+ }
102+ }
101103 original_hook ( panic_info) ;
102104 } ) ) ;
103105
104- let mut flatpak_manager = FlatpakManager :: new ( state) . unwrap ( ) ;
106+ let mut flatpak_manager = FlatpakManager :: new ( & mut state) . unwrap ( ) ;
105107 match & cli. command {
106108 Some ( Commands :: Completions { shell } ) => {
107109 use clap_complete:: generate;
@@ -128,7 +130,6 @@ fn main() {
128130 }
129131
130132 // Clean up pgid in the state file on normal exit.
131- let mut state = State :: load ( ) . unwrap ( ) ;
132133 state. process_group_id = None ;
133134 state. save ( ) . unwrap ( ) ;
134135}
0 commit comments