From 44698e27686c3de75b6d6b4befc7a05b04b8d155 Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Sun, 21 May 2023 23:14:56 -0500
Subject: [PATCH] Confirm when reloading page with unsaved changes
---
src/lib/ComfyNodeDef.ts | 4 ++--
src/lib/components/ComfyApp.svelte | 14 ++++++++++++++
src/lib/stores/configState.ts | 6 +++++-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/lib/ComfyNodeDef.ts b/src/lib/ComfyNodeDef.ts
index 7a9a25d..8dbf24e 100644
--- a/src/lib/ComfyNodeDef.ts
+++ b/src/lib/ComfyNodeDef.ts
@@ -22,14 +22,14 @@ export type ComfyNodeDefInput = [ComfyNodeDefInputType, ComfyNodeDefInputOptions
/**
* - Array: Combo widget. Usually the values are strings but they can also be other stuff like booleans.
* - "INT"/"FLOAT"/etc.: Non-combo type widgets. See ComfyWidgets type.
- * - other string: Must be an input type, usually something lke "IMAGE" or "LATENT".
+ * - other string: Must be a backend input type, usually something lke "IMAGE" or "LATENT".
*/
export type ComfyNodeDefInputType = any[] | keyof typeof ComfyWidgets | string
export type ComfyNodeDefInputOptions = {
forceInput?: boolean;
- // NOTE: For COMBO type inputs, the default value is always the first entry the list.
+ // NOTE: For COMBO type inputs, the default value is always the first entry in the list.
default?: any,
// INT/FLOAT options
diff --git a/src/lib/components/ComfyApp.svelte b/src/lib/components/ComfyApp.svelte
index bab2f5c..2d45fcb 100644
--- a/src/lib/components/ComfyApp.svelte
+++ b/src/lib/components/ComfyApp.svelte
@@ -2,6 +2,8 @@
import { ListIcon as List, ImageIcon as Image, SettingsIcon as Settings } from "svelte-feather-icons";
import ComfyApp, { type A1111PromptAndInfo, type SerializedAppState } from "./ComfyApp";
import uiState from "$lib/stores/uiState";
+ import configState from "$lib/stores/configState";
+ import workflowState from "$lib/stores/workflowState";
import { SvelteToast, toast } from '@zerodevx/svelte-toast'
import LightboxModal from "./LightboxModal.svelte";
@@ -34,6 +36,16 @@
document.getElementById("app-root").classList.remove("dark")
}
+ function handleBeforeUnload(event: BeforeUnloadEvent) {
+ if (!$configState.confirmWhenUnloadingUnsavedChanges)
+ return;
+
+ const unsavedChanges = $workflowState.openedWorkflows.some(w => w.isModified);
+ if (unsavedChanges) {
+ event.preventDefault();
+ event.returnValue = '';
+ }
+ }