From 4616cb19e2aaeb91fd36e2684faa1eaecfc4f5cf Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 24 Mar 2025 19:50:48 +0100 Subject: [PATCH] Fix logout & clean command --- plug-api/syscalls/editor.ts | 11 +++++++++++ plugs/editor/clean.ts | 2 +- web/syscalls/debug.ts | 19 ++++++++----------- web/syscalls/editor.ts | 3 +++ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/plug-api/syscalls/editor.ts b/plug-api/syscalls/editor.ts index 64f8d4e0..d89fa3ee 100644 --- a/plug-api/syscalls/editor.ts +++ b/plug-api/syscalls/editor.ts @@ -334,6 +334,17 @@ export function confirm( return syscall("editor.confirm", message); } +/** + * Prompt the user for confirmation + * @param message the message to show in the confirmation dialog + * @returns + */ +export function alert( + message: string, +): Promise { + return syscall("editor.alert", message); +} + /** * Get the value of a UI option * @param key the key of the UI option to get diff --git a/plugs/editor/clean.ts b/plugs/editor/clean.ts index b19140f3..8a42690b 100644 --- a/plugs/editor/clean.ts +++ b/plugs/editor/clean.ts @@ -10,5 +10,5 @@ export async function cleanCommand() { } await editor.flashNotification("Now wiping all state and logging out..."); await debug.cleanup(); - await editor.openUrl("/.logout", true); + await editor.alert("Cleanup done. Please close this window."); } diff --git a/web/syscalls/debug.ts b/web/syscalls/debug.ts index cb788946..ef0462cd 100644 --- a/web/syscalls/debug.ts +++ b/web/syscalls/debug.ts @@ -47,25 +47,22 @@ export function debugSyscalls(client: Client): SysCallMapping { location.reload(); }, "debug.cleanup": async () => { - if (client.spaceKV) { - console.log("Wiping the entire space KV store"); - // In sync mode, we can just delete the whole space - const allKeys: KvKey[] = []; - for await (const { key } of client.spaceKV.query({})) { - allKeys.push(key); - } - await client.spaceKV.batchDelete(allKeys); + console.log("Wiping the entire space KV store"); + // In sync mode, we can just delete the whole space + let allKeys: KvKey[] = []; + for await (const { key } of client.spaceKV.query({})) { + allKeys.push(key); } + await client.spaceKV.batchDelete(allKeys); localStorage.clear(); console.log("Wiping the entire state KV store"); - const allKeys: KvKey[] = []; + allKeys = []; for await ( - const { key } of await client.stateDataStore.luaQuery([], {}) + const { key } of client.stateDataStore.kv.query({}) ) { allKeys.push(key); } await client.stateDataStore.batchDelete(allKeys); - console.log("Done"); }, }; } diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index e2f3fb14..6e03e8aa 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -348,6 +348,9 @@ export function editorSyscalls(client: Client): SysCallMapping { "editor.confirm": (_ctx, message: string): Promise => { return client.confirm(message); }, + "editor.alert": (_ctx, message: string) => { + alert(message); + }, "editor.getUiOption": (_ctx, key: string): any => { return (client.ui.viewState.uiOptions as any)[key]; },