Skip to content

Commit

Permalink
feat: add confirmation when actioning game files
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLish committed Sep 23, 2021
1 parent 2d74522 commit 48ef824
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 30 deletions.
88 changes: 60 additions & 28 deletions src/components/GameFolderFiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,46 +76,78 @@ import { ipcRenderer } from "electron";
})
export default class GameFolderFiles extends Vue {
async handleCopyGameFiles() {
try {
await ipcRenderer.invoke(IPCEvents.COPY_GAME_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error copying game files",
error: (error as Error).message,
});
const { response } = await ipcRenderer.invoke(IPCEvents.CONFIRMATION, {
message:
"Copying game files will overwrite any game files in the Skyrim directory. Are you sure?",
buttons: ["Cancel", "Copy game files"],
});
if (response === 1) {
try {
await ipcRenderer.invoke(IPCEvents.COPY_GAME_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error copying game files",
error: (error as Error).message,
});
}
}
}
async handleDeleteGameFiles() {
try {
await ipcRenderer.invoke(IPCEvents.DELETE_GAME_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error deleting game files",
error: (error as Error).message,
});
const { response } = await ipcRenderer.invoke(IPCEvents.CONFIRMATION, {
message:
"Deleting game files will delete any game files in the Skyrim directory. Are you sure?",
buttons: ["Cancel", "Delete game files"],
});
if (response === 1) {
try {
await ipcRenderer.invoke(IPCEvents.DELETE_GAME_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error deleting game files",
error: (error as Error).message,
});
}
}
}
async handleCopyEnbFiles() {
try {
await ipcRenderer.invoke(IPCEvents.COPY_ENB_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error copying enb files",
error: (error as Error).message,
});
const { response } = await ipcRenderer.invoke(IPCEvents.CONFIRMATION, {
message:
"Copying enb files will overwrite any enb files in the Skyrim directory. Are you sure?",
buttons: ["Cancel", "Copy enb files"],
});
if (response === 1) {
try {
await ipcRenderer.invoke(IPCEvents.COPY_ENB_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error copying enb files",
error: (error as Error).message,
});
}
}
}
async handleDeleteEnbFiles() {
try {
await ipcRenderer.invoke(IPCEvents.DELETE_ENB_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error deleting enb files",
error: (error as Error).message,
});
const { response } = await ipcRenderer.invoke(IPCEvents.CONFIRMATION, {
message:
"Deleting enb files will delete any enb files in the Skyrim directory. Are you sure?",
buttons: ["Cancel", "Delete enb files"],
});
if (response === 1) {
try {
await ipcRenderer.invoke(IPCEvents.DELETE_ENB_FILES);
} catch (error) {
await ipcRenderer.invoke(IPCEvents.ERROR, {
title: "Error deleting enb files",
error: (error as Error).message,
});
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/enums/IPCEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const enum IPCEvents {
CLOSE = "close",
MINIMIZE = "MINIMIZE",

SHOW_OPEN_DIALOG = "SHOW_OPEN_DIALOG",

LAUNCH_MO2 = "LAUNCH_MO2",
LAUNCH_GAME = "LAUNCH_GAME",

SHOW_OPEN_DIALOG = "SHOW_OPEN_DIALOG",
ERROR = "ERROR",
MESSAGE = "MESSAGE",
CONFIRMATION = "CONFIRMATION",

GET_PRESETS = "GET_PRESETS",
CHECK_MOD_DIRECTORY = "CHECK_MOD_DIRECTORY",
Expand Down
8 changes: 8 additions & 0 deletions src/main/ipcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export function registerHandlers() {
return dialog.showOpenDialog({ properties: ["openDirectory"] });
});

// Returns the index of the button pressed
ipcMain.handle(
IPCEvents.CONFIRMATION,
async (event, { message, buttons }) => {
return await dialog.showMessageBox({ message, buttons });
}
);

ipcMain.handle(IPCEvents.MESSAGE, async (event, message: string) => {
await dialog.showMessageBox({ message });
});
Expand Down

0 comments on commit 48ef824

Please sign in to comment.