mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 16:48:30 +02:00
save window state on window close
This commit is contained in:
@@ -154,7 +154,7 @@ async fn cmd_render_template<R: Runtime>(
|
|||||||
RenderPurpose::Preview,
|
RenderPurpose::Preview,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
Ok(rendered)
|
Ok(rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
RenderPurpose::Send,
|
RenderPurpose::Send,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let mut metadata = BTreeMap::new();
|
let mut metadata = BTreeMap::new();
|
||||||
|
|
||||||
// Add the rest of metadata
|
// Add the rest of metadata
|
||||||
@@ -269,8 +269,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
|
|
||||||
let conn_id = conn.id.clone();
|
let conn_id = conn.id.clone();
|
||||||
@@ -322,8 +322,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
return Ok(conn_id);
|
return Ok(conn_id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -378,7 +378,7 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
RenderPurpose::Send,
|
RenderPurpose::Send,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@@ -396,8 +396,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -413,8 +413,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(IncomingMsg::Commit) => {
|
Ok(IncomingMsg::Commit) => {
|
||||||
@@ -446,7 +446,7 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
RenderPurpose::Send,
|
RenderPurpose::Send,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
upsert_grpc_event(
|
upsert_grpc_event(
|
||||||
&window,
|
&window,
|
||||||
@@ -458,8 +458,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let (maybe_stream, maybe_msg) =
|
let (maybe_stream, maybe_msg) =
|
||||||
@@ -497,8 +497,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
match maybe_msg {
|
match maybe_msg {
|
||||||
@@ -512,14 +512,14 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
} else {
|
} else {
|
||||||
"Received response with metadata"
|
"Received response with metadata"
|
||||||
}
|
}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
event_type: GrpcEventType::Info,
|
event_type: GrpcEventType::Info,
|
||||||
..base_event.clone()
|
..base_event.clone()
|
||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
upsert_grpc_event(
|
upsert_grpc_event(
|
||||||
&window,
|
&window,
|
||||||
&GrpcEvent {
|
&GrpcEvent {
|
||||||
@@ -529,8 +529,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
upsert_grpc_event(
|
upsert_grpc_event(
|
||||||
&window,
|
&window,
|
||||||
&GrpcEvent {
|
&GrpcEvent {
|
||||||
@@ -541,8 +541,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
upsert_grpc_event(
|
upsert_grpc_event(
|
||||||
@@ -566,8 +566,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
}),
|
}),
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Server streaming doesn't return the initial message
|
// Server streaming doesn't return the initial message
|
||||||
@@ -585,14 +585,14 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
} else {
|
} else {
|
||||||
"Received response with metadata"
|
"Received response with metadata"
|
||||||
}
|
}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
event_type: GrpcEventType::Info,
|
event_type: GrpcEventType::Info,
|
||||||
..base_event.clone()
|
..base_event.clone()
|
||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
stream.into_inner()
|
stream.into_inner()
|
||||||
}
|
}
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
@@ -618,8 +618,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
}),
|
}),
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
None => return,
|
None => return,
|
||||||
@@ -638,8 +638,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
let trailers =
|
let trailers =
|
||||||
@@ -655,8 +655,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(status) => {
|
Err(status) => {
|
||||||
@@ -671,8 +671,8 @@ async fn cmd_grpc_go<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -930,8 +930,8 @@ async fn cmd_import_data<R: Runtime>(
|
|||||||
grpc_requests,
|
grpc_requests,
|
||||||
&UpdateSource::Import,
|
&UpdateSource::Import,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
analytics::track_event(
|
analytics::track_event(
|
||||||
&window,
|
&window,
|
||||||
@@ -939,7 +939,7 @@ async fn cmd_import_data<R: Runtime>(
|
|||||||
AnalyticsAction::Import,
|
AnalyticsAction::Import,
|
||||||
Some(json!({ "plugin": plugin_name })),
|
Some(json!({ "plugin": plugin_name })),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(upserted)
|
Ok(upserted)
|
||||||
}
|
}
|
||||||
@@ -985,7 +985,7 @@ async fn cmd_curl_to_request<R: Runtime>(
|
|||||||
AnalyticsAction::Import,
|
AnalyticsAction::Import,
|
||||||
Some(json!({ "plugin": plugin_name })),
|
Some(json!({ "plugin": plugin_name })),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
import_result.resources.http_requests.get(0).ok_or("No curl command found".to_string()).map(
|
import_result.resources.http_requests.get(0).ok_or("No curl command found".to_string()).map(
|
||||||
|r| {
|
|r| {
|
||||||
@@ -1170,8 +1170,8 @@ async fn cmd_install_plugin<R: Runtime>(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
Ok(plugin)
|
Ok(plugin)
|
||||||
}
|
}
|
||||||
@@ -1222,8 +1222,8 @@ async fn cmd_create_cookie_jar(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -1245,8 +1245,8 @@ async fn cmd_create_environment(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -1268,8 +1268,8 @@ async fn cmd_create_grpc_request(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -1508,8 +1508,8 @@ async fn cmd_list_cookie_jars(
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create CookieJar");
|
.expect("Failed to create CookieJar");
|
||||||
Ok(vec![cookie_jar])
|
Ok(vec![cookie_jar])
|
||||||
} else {
|
} else {
|
||||||
Ok(cookie_jars)
|
Ok(cookie_jars)
|
||||||
@@ -1598,8 +1598,8 @@ async fn cmd_list_workspaces(window: WebviewWindow) -> Result<Vec<Workspace>, St
|
|||||||
},
|
},
|
||||||
&UpdateSource::Window,
|
&UpdateSource::Window,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create Workspace");
|
.expect("Failed to create Workspace");
|
||||||
Ok(vec![workspace])
|
Ok(vec![workspace])
|
||||||
} else {
|
} else {
|
||||||
Ok(workspaces)
|
Ok(workspaces)
|
||||||
@@ -1954,14 +1954,16 @@ pub fn run() {
|
|||||||
|
|
||||||
// Save window state on exit
|
// Save window state on exit
|
||||||
match event {
|
match event {
|
||||||
RunEvent::ExitRequested{..} => {
|
RunEvent::WindowEvent {
|
||||||
let handle = app_handle.clone();
|
event: WindowEvent::CloseRequested { .. },
|
||||||
if let Err(e) = handle.save_window_state(StateFlags::all()) {
|
..
|
||||||
|
} => {
|
||||||
|
if let Err(e) = app_handle.save_window_state(StateFlags::all()) {
|
||||||
warn!("Failed to save window state {e:?}");
|
warn!("Failed to save window state {e:?}");
|
||||||
} else {
|
} else {
|
||||||
debug!("Saved window state");
|
debug!("Saved window state");
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -1987,7 +1989,7 @@ fn create_main_window(handle: &AppHandle, url: &str) -> WebviewWindow {
|
|||||||
Some(_) => counter += 1,
|
Some(_) => counter += 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.expect("Failed to generate label for new window");
|
.expect("Failed to generate label for new window");
|
||||||
|
|
||||||
let config = CreateWindowConfig {
|
let config = CreateWindowConfig {
|
||||||
url,
|
url,
|
||||||
@@ -2222,8 +2224,8 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
req.request_id.as_str(),
|
req.request_id.as_str(),
|
||||||
req.limit.map(|l| l as i64),
|
req.limit.map(|l| l as i64),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
Some(InternalEventPayload::FindHttpResponsesResponse(FindHttpResponsesResponse {
|
Some(InternalEventPayload::FindHttpResponsesResponse(FindHttpResponsesResponse {
|
||||||
http_responses,
|
http_responses,
|
||||||
}))
|
}))
|
||||||
@@ -2252,7 +2254,7 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
environment.as_ref(),
|
environment.as_ref(),
|
||||||
&cb,
|
&cb,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
Some(InternalEventPayload::RenderHttpRequestResponse(RenderHttpRequestResponse {
|
Some(InternalEventPayload::RenderHttpRequestResponse(RenderHttpRequestResponse {
|
||||||
http_request,
|
http_request,
|
||||||
}))
|
}))
|
||||||
@@ -2311,8 +2313,8 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
req.http_request.id.as_str(),
|
req.http_request.id.as_str(),
|
||||||
&UpdateSource::Plugin,
|
&UpdateSource::Plugin,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let result = send_http_request(
|
let result = send_http_request(
|
||||||
&window,
|
&window,
|
||||||
@@ -2322,7 +2324,7 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
cookie_jar,
|
cookie_jar,
|
||||||
&mut tokio::sync::watch::channel(false).1, // No-op cancel channel
|
&mut tokio::sync::watch::channel(false).1, // No-op cancel channel
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let http_response = match result {
|
let http_response = match result {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
|
|||||||
Reference in New Issue
Block a user