@@ -60,8 +60,11 @@ impl EventState {
6060 . cloned ( )
6161 }
6262
63- pub fn get ( ) -> crate :: Result < Arc < Self > > {
64- Ok ( EVENT_STATE . get ( ) . ok_or ( EventError :: NotInitialized ) ?. clone ( ) )
63+ pub fn get ( ) -> Arc < Self > {
64+ EVENT_STATE
65+ . get ( )
66+ . expect ( "should be initialized when used" )
67+ . clone ( )
6568 }
6669
6770 #[ cfg( feature = "tauri" ) ]
@@ -78,15 +81,15 @@ impl EventState {
7881 // Values provided should not be used directly, as they are clones and are not guaranteed to be up-to-date
7982 pub async fn list_progress_bars ( ) -> crate :: Result < DashMap < Uuid , LoadingBar > >
8083 {
81- let value = Self :: get ( ) ? ;
84+ let value = Self :: get ( ) ;
8285 Ok ( value. loading_bars . clone ( ) )
8386 }
8487
8588 #[ cfg( feature = "tauri" ) ]
8689 pub async fn get_main_window ( ) -> crate :: Result < Option < tauri:: WebviewWindow > >
8790 {
8891 use tauri:: Manager ;
89- let value = Self :: get ( ) ? ;
92+ let value = Self :: get ( ) ;
9093 Ok ( value. app . get_webview_window ( "main" ) )
9194 }
9295}
@@ -225,42 +228,40 @@ impl Drop for LoadingBarId {
225228 fn drop ( & mut self ) {
226229 let loader_uuid = self . 0 ;
227230 tokio:: spawn ( async move {
228- if let Ok ( event_state) = EventState :: get ( ) {
229- #[ cfg( any( feature = "tauri" , feature = "cli" ) ) ]
230- if let Some ( ( _, bar) ) =
231- event_state. loading_bars . remove ( & loader_uuid)
231+ let event_state = EventState :: get ( ) ;
232+ #[ cfg( any( feature = "tauri" , feature = "cli" ) ) ]
233+ if let Some ( ( _, bar) ) =
234+ event_state. loading_bars . remove ( & loader_uuid)
235+ {
236+ #[ cfg( feature = "tauri" ) ]
232237 {
233- #[ cfg( feature = "tauri" ) ]
234- {
235- let loader_uuid = bar. loading_bar_uuid ;
236- let event = bar. bar_type . clone ( ) ;
237- let fraction = bar. current / bar. total ;
238-
239- let _ = event_state. send ( AppEvent :: Loading (
240- LoadingPayload {
241- fraction : None ,
242- message : "Completed" . to_string ( ) ,
243- event,
244- loader_uuid : loader_uuid. to_string ( ) ,
245- } ,
246- ) ) ;
247- tracing:: trace!(
248- "Exited at {fraction} for loading bar: {:?}" ,
249- loader_uuid
250- ) ;
251- }
252-
253- // Emit event to indicatif progress bar arc
254- #[ cfg( feature = "cli" ) ]
255- {
256- let cli_progress_bar = bar. cli_progress_bar ;
257- cli_progress_bar. finish ( ) ;
258- }
238+ let loader_uuid = bar. loading_bar_uuid ;
239+ let event = bar. bar_type . clone ( ) ;
240+ let fraction = bar. current / bar. total ;
241+
242+ let _ =
243+ event_state. send ( AppEvent :: Loading ( LoadingPayload {
244+ fraction : None ,
245+ message : "Completed" . to_string ( ) ,
246+ event,
247+ loader_uuid : loader_uuid. to_string ( ) ,
248+ } ) ) ;
249+ tracing:: trace!(
250+ "Exited at {fraction} for loading bar: {:?}" ,
251+ loader_uuid
252+ ) ;
259253 }
260254
261- #[ cfg( not( any( feature = "tauri" , feature = "cli" ) ) ) ]
262- event_state. loading_bars . remove ( & loader_uuid) ;
255+ // Emit event to indicatif progress bar arc
256+ #[ cfg( feature = "cli" ) ]
257+ {
258+ let cli_progress_bar = bar. cli_progress_bar ;
259+ cli_progress_bar. finish ( ) ;
260+ }
263261 }
262+
263+ #[ cfg( not( any( feature = "tauri" , feature = "cli" ) ) ) ]
264+ event_state. loading_bars . remove ( & loader_uuid) ;
264265 } ) ;
265266 }
266267}
@@ -546,9 +547,6 @@ mod log_types {
546547
547548#[ derive( Debug , thiserror:: Error ) ]
548549pub enum EventError {
549- #[ error( "Event state was not properly initialized" ) ]
550- NotInitialized ,
551-
552550 #[ error( "Non-existent loading bar of key: {0}" ) ]
553551 NoLoadingBar ( Uuid ) ,
554552
0 commit comments