From 0e21d901cd88c2810aac58b89db91e64962bc563 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 15 Jan 2025 07:06:51 -0800 Subject: [PATCH] save window state on window close --- src-tauri/src/lib.rs | 128 ++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 28b5de63..79cabb85 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -154,7 +154,7 @@ async fn cmd_render_template( RenderPurpose::Preview, ), ) - .await; + .await; Ok(rendered) } @@ -220,7 +220,7 @@ async fn cmd_grpc_go( RenderPurpose::Send, ), ) - .await; + .await; let mut metadata = BTreeMap::new(); // Add the rest of metadata @@ -269,8 +269,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string())? + .await + .map_err(|e| e.to_string())? }; let conn_id = conn.id.clone(); @@ -322,8 +322,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string())?; + .await + .map_err(|e| e.to_string())?; return Ok(conn_id); } }; @@ -378,7 +378,7 @@ async fn cmd_grpc_go( RenderPurpose::Send, ), ) - .await + .await }) }) }; @@ -396,8 +396,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); }); return; } @@ -413,8 +413,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); }); } Ok(IncomingMsg::Commit) => { @@ -446,7 +446,7 @@ async fn cmd_grpc_go( RenderPurpose::Send, ), ) - .await; + .await; upsert_grpc_event( &window, @@ -458,8 +458,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); async move { let (maybe_stream, maybe_msg) = @@ -497,8 +497,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); } match maybe_msg { @@ -512,14 +512,14 @@ async fn cmd_grpc_go( } else { "Received response with metadata" } - .to_string(), + .to_string(), event_type: GrpcEventType::Info, ..base_event.clone() }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); upsert_grpc_event( &window, &GrpcEvent { @@ -529,8 +529,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); upsert_grpc_event( &window, &GrpcEvent { @@ -541,8 +541,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); } Some(Err(e)) => { upsert_grpc_event( @@ -566,8 +566,8 @@ async fn cmd_grpc_go( }), &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); } None => { // Server streaming doesn't return the initial message @@ -585,14 +585,14 @@ async fn cmd_grpc_go( } else { "Received response with metadata" } - .to_string(), + .to_string(), event_type: GrpcEventType::Info, ..base_event.clone() }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); stream.into_inner() } Some(Err(e)) => { @@ -618,8 +618,8 @@ async fn cmd_grpc_go( }), &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); return; } None => return, @@ -638,8 +638,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); } Ok(None) => { let trailers = @@ -655,8 +655,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); break; } Err(status) => { @@ -671,8 +671,8 @@ async fn cmd_grpc_go( }, &UpdateSource::Window, ) - .await - .unwrap(); + .await + .unwrap(); } } } @@ -930,8 +930,8 @@ async fn cmd_import_data( grpc_requests, &UpdateSource::Import, ) - .await - .map_err(|e| e.to_string())?; + .await + .map_err(|e| e.to_string())?; analytics::track_event( &window, @@ -939,7 +939,7 @@ async fn cmd_import_data( AnalyticsAction::Import, Some(json!({ "plugin": plugin_name })), ) - .await; + .await; Ok(upserted) } @@ -985,7 +985,7 @@ async fn cmd_curl_to_request( AnalyticsAction::Import, Some(json!({ "plugin": plugin_name })), ) - .await; + .await; import_result.resources.http_requests.get(0).ok_or("No curl command found".to_string()).map( |r| { @@ -1170,8 +1170,8 @@ async fn cmd_install_plugin( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string())?; + .await + .map_err(|e| e.to_string())?; Ok(plugin) } @@ -1222,8 +1222,8 @@ async fn cmd_create_cookie_jar( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string()) + .await + .map_err(|e| e.to_string()) } #[tauri::command] @@ -1245,8 +1245,8 @@ async fn cmd_create_environment( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string()) + .await + .map_err(|e| e.to_string()) } #[tauri::command] @@ -1268,8 +1268,8 @@ async fn cmd_create_grpc_request( }, &UpdateSource::Window, ) - .await - .map_err(|e| e.to_string()) + .await + .map_err(|e| e.to_string()) } #[tauri::command] @@ -1508,8 +1508,8 @@ async fn cmd_list_cookie_jars( }, &UpdateSource::Window, ) - .await - .expect("Failed to create CookieJar"); + .await + .expect("Failed to create CookieJar"); Ok(vec![cookie_jar]) } else { Ok(cookie_jars) @@ -1598,8 +1598,8 @@ async fn cmd_list_workspaces(window: WebviewWindow) -> Result, St }, &UpdateSource::Window, ) - .await - .expect("Failed to create Workspace"); + .await + .expect("Failed to create Workspace"); Ok(vec![workspace]) } else { Ok(workspaces) @@ -1954,14 +1954,16 @@ pub fn run() { // Save window state on exit match event { - RunEvent::ExitRequested{..} => { - let handle = app_handle.clone(); - if let Err(e) = handle.save_window_state(StateFlags::all()) { + RunEvent::WindowEvent { + event: WindowEvent::CloseRequested { .. }, + .. + } => { + if let Err(e) = app_handle.save_window_state(StateFlags::all()) { warn!("Failed to save window state {e:?}"); } else { debug!("Saved window state"); }; - }, + } _ => {} }; }); @@ -1987,7 +1989,7 @@ fn create_main_window(handle: &AppHandle, url: &str) -> WebviewWindow { Some(_) => counter += 1, } } - .expect("Failed to generate label for new window"); + .expect("Failed to generate label for new window"); let config = CreateWindowConfig { url, @@ -2222,8 +2224,8 @@ async fn handle_plugin_event( req.request_id.as_str(), req.limit.map(|l| l as i64), ) - .await - .unwrap_or_default(); + .await + .unwrap_or_default(); Some(InternalEventPayload::FindHttpResponsesResponse(FindHttpResponsesResponse { http_responses, })) @@ -2252,7 +2254,7 @@ async fn handle_plugin_event( environment.as_ref(), &cb, ) - .await; + .await; Some(InternalEventPayload::RenderHttpRequestResponse(RenderHttpRequestResponse { http_request, })) @@ -2311,8 +2313,8 @@ async fn handle_plugin_event( req.http_request.id.as_str(), &UpdateSource::Plugin, ) - .await - .unwrap(); + .await + .unwrap(); let result = send_http_request( &window, @@ -2322,7 +2324,7 @@ async fn handle_plugin_event( cookie_jar, &mut tokio::sync::watch::channel(false).1, // No-op cancel channel ) - .await; + .await; let http_response = match result { Ok(r) => r,