feat: use beforeunload to make sure graph is saved

This commit is contained in:
2026-05-07 21:12:23 +02:00
parent 3c5f897b26
commit f0f4c00137
+16 -13
View File
@@ -7,7 +7,7 @@
import { debugNode } from '$lib/node-registry/debugNode'; import { debugNode } from '$lib/node-registry/debugNode';
import { groupNode } from '$lib/node-registry/groupNode.js'; import { groupNode } from '$lib/node-registry/groupNode.js';
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index'; import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
import NodeStore from '$lib/node-store/NodeStore.svelte';
import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte'; import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte';
import { ProjectManager } from '$lib/project-manager/project-manager.svelte'; import { ProjectManager } from '$lib/project-manager/project-manager.svelte';
import ProjectManagerEl from '$lib/project-manager/ProjectManager.svelte'; import ProjectManagerEl from '$lib/project-manager/ProjectManager.svelte';
@@ -35,6 +35,7 @@
let performanceStore = createPerformanceStore(); let performanceStore = createPerformanceStore();
let planty = $state<ReturnType<typeof Planty>>(); let planty = $state<ReturnType<typeof Planty>>();
let pendingSave = false;
const { data } = $props(); const { data } = $props();
@@ -52,8 +53,8 @@
); );
$effect(() => { $effect(() => {
workerRuntime.useRegistryCache = appSettings.value.debug.cache.useRuntimeCache; workerRuntime.useRegistryCache = appSettings.value.debug.cache.useRegistryCache;
workerRuntime.useRuntimeCache = appSettings.value.debug.cache.useRegistryCache; workerRuntime.useRuntimeCache = appSettings.value.debug.cache.useRuntimeCache;
if (appSettings.value.debug.cache.useRegistryCache) { if (appSettings.value.debug.cache.useRegistryCache) {
nodeRegistry.cache = registryCache; nodeRegistry.cache = registryCache;
@@ -68,6 +69,16 @@
} }
}); });
$effect(() => {
const handler = (e: BeforeUnloadEvent) => {
if (pendingSave) {
e.preventDefault();
}
};
window.addEventListener('beforeunload', handler);
return () => window.removeEventListener('beforeunload', handler);
});
let activeNode = $state<NodeInstance | undefined>(undefined); let activeNode = $state<NodeInstance | undefined>(undefined);
let scene = $state<Group>(null!); let scene = $state<Group>(null!);
let isExecuting = $state(false); let isExecuting = $state(false);
@@ -288,7 +299,7 @@
bind:showHelp={appSettings.value.nodeInterface.showHelp} bind:showHelp={appSettings.value.nodeInterface.showHelp}
bind:settings={graphSettings} bind:settings={graphSettings}
bind:settingTypes={graphSettingTypes} bind:settingTypes={graphSettingTypes}
onsave={(g) => pm.saveGraph(g)} onsave={async (g) => { pendingSave = true; await pm.saveGraph(g); pendingSave = false; }}
onresult={(result) => handleUpdate(result as Graph)} onresult={(result) => handleUpdate(result as Graph)}
/> />
{/key} {/key}
@@ -317,15 +328,7 @@
<Panel id="exports" title="Exporter" icon="i-[tabler--package-export]"> <Panel id="exports" title="Exporter" icon="i-[tabler--package-export]">
<ExportSettings {scene} /> <ExportSettings {scene} />
</Panel> </Panel>
{#if 0 > 1}
<Panel
id="node-store"
title="Node Store"
icon="i-[tabler--database] bg-green-400"
>
<NodeStore registry={nodeRegistry} />
</Panel>
{/if}
<Panel <Panel
id="performance" id="performance"
title="Performance" title="Performance"