Reconnect the edits websocket if it disconnects (#4391)

* Reconnect the edits websocket if it disconnects

* restart the server if the OS kills it

* fix clippy

* clean up code and add more comments

* cleanups

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2025-07-14 13:39:21 -07:00
1 parent c5b33924ae
commit 3f62cd8fc0
9 files changed
+368 -188

No files matched your search

+3 -2
View File
@@ -132,6 +132,7 @@ fn index_request(
/// multiple webviews in the same application, so that we can send edits to the correct one.
fn module_loader(root_id: &str, headless: bool, edit_state: &WebviewEdits) -> String {
let edits_path = edit_state.wry_queue.edits_path();
let expected_key = edit_state.wry_queue.required_server_key();
format!(
r#"
@@ -143,7 +144,7 @@ fn module_loader(root_id: &str, headless: bool, edit_state: &WebviewEdits) -> St
{NATIVE_JS}
// The native interpreter extends the sledgehammer interpreter with a few extra methods that we use for IPC
window.interpreter = new NativeInterpreter("{edits_path}", "{EVENTS_PATH}");
window.interpreter = new NativeInterpreter("{EVENTS_PATH}", {headless});
// Wait for the page to load before sending the initialize message
window.onload = function() {{
@@ -152,7 +153,7 @@ fn module_loader(root_id: &str, headless: bool, edit_state: &WebviewEdits) -> St
window.interpreter.initialize(root_element);
window.ipc.postMessage(window.interpreter.serializeIpcMessage("initialize"));
}}
window.interpreter.waitForRequest({headless});
window.interpreter.waitForRequest("{edits_path}", "{expected_key}");
}}
</script>
<script type="module">