Skip to content

Commit

Permalink
命名の修正漏れを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
shm11C3 committed Jan 25, 2024
1 parent 9f70a24 commit cceee02
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
24 changes: 12 additions & 12 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
})
);
Expand All @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/browser/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
},
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 });
Expand All @@ -692,7 +692,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
async action({ commit }) {
try {
const workspace: WorkspaceType = await window.electron
.getTempProject()
.getWorkspace()
.then(getValueOrThrow);

await commit("SET_WORKSPACE", { workspace });
Expand Down
6 changes: 3 additions & 3 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ export type IpcIHData = {
return: ConfigType[keyof ConfigType];
};

GET_TEMP_PROJECT: {
GET_WORKSPACE: {
args: [];
return: Result<WorkspaceType>;
};

SET_TEMP_PROJECT: {
args: [tempProject: WorkspaceType];
SAVE_WORKSPACE: {
args: [workspace: WorkspaceType];
return: Result<undefined>;
};

Expand Down
4 changes: 2 additions & 2 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export interface Sandbox {
key: Key,
newValue: ConfigType[Key]
): Promise<ConfigType[Key]>;
getTempProject(): Promise<Result<WorkspaceType>>;
setTempProject(tempProject: WorkspaceType): Promise<Result<undefined>>;
getWorkspace(): Promise<Result<WorkspaceType>>;
saveWorkspace(workspace: WorkspaceType): Promise<Result<undefined>>;
getFileModifiedAt(filePath: string): Promise<Result<number>>;
setEngineSetting(
engineId: EngineId,
Expand Down

0 comments on commit cceee02

Please sign in to comment.