Skip to content

Commit

Permalink
fix: iPC handlers where being set twice, now they del previous handle…
Browse files Browse the repository at this point in the history
…r when creating new one (#476)
  • Loading branch information
AlexDygma authored Aug 2, 2023
1 parent 95558d1 commit 8cef57a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/main/setup/configureIPCs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,49 @@ const configureIPCs = () => {
const globalRecording = GlobalRecording.getInstance();
const window = Window.getWindow();

ipcMain.on("start-recording", (event, arg) => {
ipcMain.removeHandler("start-recording");
ipcMain.on("start-recording", () => {
console.log("start-recording");
globalRecording.setRecording(true);
uIOhook.on("keydown", sendkeyDown);
uIOhook.on("keyup", sendKeyUp);
uIOhook.start();
});

ipcMain.on("stop-recording", (event, arg) => {
ipcMain.removeHandler("stop-recording");
ipcMain.on("stop-recording", () => {
console.log("stop-recording");
globalRecording.setRecording(false);
uIOhook.off("keydown", sendkeyDown);
uIOhook.off("keyup", sendKeyUp);
uIOhook.stop();
});

ipcMain.removeHandler("list-drives");
ipcMain.handle("list-drives", async (event, options) => {
const data = listDrivesHandler(event, options);
return data;
});

ipcMain.removeHandler("open-dialog");
ipcMain.handle("open-dialog", async (event, options) => {
const data = await dialog.showOpenDialog(window, options);
return data;
});

ipcMain.removeHandler("save-dialog");
ipcMain.handle("save-dialog", async (event, options) => {
const data = dialog.showSaveDialogSync(window, options);
return data;
});

ipcMain.handle("is-devtools-opened", async (event, someArgument) => {
ipcMain.removeHandler("is-devtools-opened");
ipcMain.handle("is-devtools-opened", async () => {
const data = window.webContents.isDevToolsOpened();
return data;
});

ipcMain.removeHandler("manage-devtools");
ipcMain.handle("manage-devtools", (event, action) => {
if (action === true) {
window.webContents.openDevTools();
Expand All @@ -52,16 +60,20 @@ const configureIPCs = () => {
}
});

ipcMain.removeHandler("get-userPath");
ipcMain.handle("get-userPath", (event, path) => app.getPath(path));

ipcMain.removeHandler("openExternal");
ipcMain.handle("openExternal", (event, URI) => shell.openExternal(URI));

ipcMain.handle("get-Locale", (event, someArgument) => {
ipcMain.removeHandler("get-Locale");
ipcMain.handle("get-Locale", () => {
const locale = app.getLocale();
return locale;
});

ipcMain.handle("get-NativeTheme", (event, someArgument) => nativeTheme.shouldUseDarkColors);
ipcMain.removeHandler("get-NativeTheme");
ipcMain.handle("get-NativeTheme", () => nativeTheme.shouldUseDarkColors);
};

export default configureIPCs;
6 changes: 4 additions & 2 deletions src/main/utils/listDrivesHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const drivelist = require("drivelist");
import delay from "./delay";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const drivelist = require("drivelist");

const listDrivesHandler = async (_event: any, _someArgument: any) => {
let drives;
let result: undefined | any;
Expand All @@ -10,7 +12,7 @@ const listDrivesHandler = async (_event: any, _someArgument: any) => {
console.log("drive info", drive.description, drive.mountpoints);
if (drive.description.includes("RPI RP2") || drive.description.includes("RPI-RP2")) {
while (drive.mountpoints[0] === undefined || drive.mountpoints.length === 0) {
delay(100);
await delay(100);
drives = await drivelist.list();
result = drives[index].mountpoints[0];
console.log(result);
Expand Down

0 comments on commit 8cef57a

Please # to comment.