From cceee020daddea59102178b5ce6f16d1b16ef463 Mon Sep 17 00:00:00 2001 From: shm Date: Thu, 25 Jan 2024 23:39:23 +0900 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=BC=8F=E3=82=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 24 ++++++++++++------------ src/browser/sandbox.ts | 8 ++++---- src/electron/preload.ts | 8 ++++---- src/store/project.ts | 4 ++-- src/type/ipc.ts | 6 +++--- src/type/preload.ts | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/background.ts b/src/background.ts index d697cd3021..4c70787faa 100644 --- a/src/background.ts +++ b/src/background.ts @@ -139,14 +139,14 @@ protocol.registerSchemesAsPrivileged([ const firstUrl = process.env.VITE_DEV_SERVER_URL ?? "app://./index.html"; -const tempProjectPath = path.join(fixedUserDataDir, "project.tmp.json"); +const workspaceFilePath = path.join(fixedUserDataDir, "workspace.json"); -const setTempProject = async (tempProject: WorkspaceType) => { +const saveWorkspace = async (workspace: WorkspaceType) => { try { - const buf = new TextEncoder().encode(JSON.stringify(tempProject)).buffer; + const buf = new TextEncoder().encode(JSON.stringify(workspace)).buffer; - await fs.promises.writeFile(tempProjectPath + ".bk", new DataView(buf)); - await fs.promises.rename(tempProjectPath + ".bk", tempProjectPath); + await fs.promises.writeFile(workspaceFilePath + ".bk", new DataView(buf)); + await fs.promises.rename(workspaceFilePath + ".bk", workspaceFilePath); return success(undefined); } catch (e) { @@ -846,18 +846,18 @@ ipcMainHandle("SET_SETTING", (_, key, newValue) => { return configManager.get(key); }); -ipcMainHandle("GET_TEMP_PROJECT", async () => { +ipcMainHandle("GET_WORKSPACE", async () => { try { - if (!fs.existsSync(tempProjectPath)) { - const defaultTempProject: WorkspaceType = { + if (!fs.existsSync(workspaceFilePath)) { + const defaultWorkspace: WorkspaceType = { state: "none", }; - await setTempProject(defaultTempProject); + await saveWorkspace(defaultWorkspace); } const workspace: WorkspaceType = JSON.parse( - await fs.promises.readFile(tempProjectPath, { + await fs.promises.readFile(workspaceFilePath, { encoding: "utf-8", }) ); @@ -879,8 +879,8 @@ ipcMainHandle("GET_TEMP_PROJECT", async () => { } }); -ipcMainHandle("SET_TEMP_PROJECT", (_, tempProject) => { - return setTempProject(tempProject); +ipcMainHandle("SAVE_WORKSPACE", (_, workspace) => { + return saveWorkspace(workspace); }); ipcMainHandle("GET_FILE_MODIFIED_AT", async (_, filePath) => { diff --git a/src/browser/sandbox.ts b/src/browser/sandbox.ts index cd70b79988..da41495526 100644 --- a/src/browser/sandbox.ts +++ b/src/browser/sandbox.ts @@ -294,11 +294,11 @@ export const api: Sandbox = { configManager.set(key, newValue); return newValue; }, - getTempProject() { - throw new Error("Not supported on Browser version: getTempProject"); + getWorkspace() { + throw new Error("Not supported on Browser version: getWorkspace"); }, - setTempProject(/* tempProject: WorkspaceType */) { - throw new Error("Not supported on Browser version: setTempProject"); + saveWorkspace(/* workspace: WorkspaceType */) { + throw new Error("Not supported on Browser version: saveWorkspace"); }, getFileModifiedAt(/* getFileModifiedAt: number */) { throw new Error("Not supported on Browser version: getFileModifiedAt"); diff --git a/src/electron/preload.ts b/src/electron/preload.ts index 8a24f2e903..c79421988f 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -255,12 +255,12 @@ const api: Sandbox = { ); }, - getTempProject: async () => { - return await ipcRendererInvoke("GET_TEMP_PROJECT"); + getWorkspace: async () => { + return await ipcRendererInvoke("GET_WORKSPACE"); }, - setTempProject: async (tempProject) => { - return await ipcRendererInvoke("SET_TEMP_PROJECT", tempProject); + saveWorkspace: async (workspace) => { + return await ipcRendererInvoke("SAVE_WORKSPACE", workspace); }, getFileModifiedAt: async (filePath) => { diff --git a/src/store/project.ts b/src/store/project.ts index e90d78ee38..63b2c02458 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -681,7 +681,7 @@ export const projectStore = createPartialStore({ }, async action({ commit }, { workspace }) { await window.electron - .setTempProject(JSON.parse(JSON.stringify(workspace))) + .saveWorkspace(JSON.parse(JSON.stringify(workspace))) .then(getValueOrThrow); commit("SET_WORKSPACE", { workspace }); @@ -692,7 +692,7 @@ export const projectStore = createPartialStore({ async action({ commit }) { try { const workspace: WorkspaceType = await window.electron - .getTempProject() + .getWorkspace() .then(getValueOrThrow); await commit("SET_WORKSPACE", { workspace }); diff --git a/src/type/ipc.ts b/src/type/ipc.ts index 1a1a9a612a..6a6f2c29df 100644 --- a/src/type/ipc.ts +++ b/src/type/ipc.ts @@ -260,13 +260,13 @@ export type IpcIHData = { return: ConfigType[keyof ConfigType]; }; - GET_TEMP_PROJECT: { + GET_WORKSPACE: { args: []; return: Result; }; - SET_TEMP_PROJECT: { - args: [tempProject: WorkspaceType]; + SAVE_WORKSPACE: { + args: [workspace: WorkspaceType]; return: Result; }; diff --git a/src/type/preload.ts b/src/type/preload.ts index 3dc8aed2a4..383d803059 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -235,8 +235,8 @@ export interface Sandbox { key: Key, newValue: ConfigType[Key] ): Promise; - getTempProject(): Promise>; - setTempProject(tempProject: WorkspaceType): Promise>; + getWorkspace(): Promise>; + saveWorkspace(workspace: WorkspaceType): Promise>; getFileModifiedAt(filePath: string): Promise>; setEngineSetting( engineId: EngineId,