Skip the web page close confirmation when crashed or in debug mode
This commit is contained in:
parent
6da903011a
commit
dd8cd4a2fa
|
|
@ -160,6 +160,12 @@ export function createInputManager(editor: EditorState, container: HTMLElement,
|
||||||
};
|
};
|
||||||
|
|
||||||
const onBeforeUnload = (e: BeforeUnloadEvent) => {
|
const onBeforeUnload = (e: BeforeUnloadEvent) => {
|
||||||
|
// Skip the message if the editor crashed, since work is already lost
|
||||||
|
if (editor.instance.has_crashed()) return;
|
||||||
|
|
||||||
|
// Skip the message during development, since it's annoying when testing
|
||||||
|
if (process.env.NODE_ENV === "development") return;
|
||||||
|
|
||||||
const allDocumentsSaved = document.state.documents.reduce((acc, doc) => acc && doc.isSaved, true);
|
const allDocumentsSaved = document.state.documents.reduce((acc, doc) => acc && doc.isSaved, true);
|
||||||
if (!allDocumentsSaved) {
|
if (!allDocumentsSaved) {
|
||||||
e.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";
|
e.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ impl JsEditorHandle {
|
||||||
// Sends a message to the dispatcher in the Editor Backend
|
// Sends a message to the dispatcher in the Editor Backend
|
||||||
fn dispatch<T: Into<Message>>(&self, message: T) {
|
fn dispatch<T: Into<Message>>(&self, message: T) {
|
||||||
// Process no further messages after a crash to avoid spamming the console
|
// Process no further messages after a crash to avoid spamming the console
|
||||||
let has_crashed = EDITOR_HAS_CRASHED.with(|crash_state| crash_state.borrow().clone());
|
let possible_crash_message = EDITOR_HAS_CRASHED.with(|crash_state| crash_state.borrow().clone());
|
||||||
if let Some(message) = has_crashed {
|
if let Some(message) = possible_crash_message {
|
||||||
if !self.instance_received_crashed.get() {
|
if !self.instance_received_crashed.get() {
|
||||||
self.handle_response(message);
|
self.handle_response(message);
|
||||||
self.instance_received_crashed.set(true);
|
self.instance_received_crashed.set(true);
|
||||||
|
|
@ -82,6 +82,15 @@ impl JsEditorHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// Create JS -> Rust wrapper functions below
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
|
pub fn has_crashed(&self) -> JsValue {
|
||||||
|
let has_crashed = EDITOR_HAS_CRASHED.with(|crash_state| crash_state.borrow().is_some());
|
||||||
|
has_crashed.into()
|
||||||
|
}
|
||||||
|
|
||||||
/// Modify the currently selected tool in the document state store
|
/// Modify the currently selected tool in the document state store
|
||||||
pub fn select_tool(&self, tool: String) -> Result<(), JsValue> {
|
pub fn select_tool(&self, tool: String) -> Result<(), JsValue> {
|
||||||
match translate_tool_type(&tool) {
|
match translate_tool_type(&tool) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue