Skip to content

Commit

Permalink
fix: browser send (isReady)
Browse files Browse the repository at this point in the history
  • Loading branch information
N0chteil committed Jun 17, 2023
1 parent 0444db2 commit 56913dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/managers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Browser {
send(channel: string, ...args: any[]) {
setTimeout(
() => this.window.webContents.send(channel, ...args),
this.isReady ? 0 : 2500
this.isReady ? 200 : 2500
);
}

Expand Down Expand Up @@ -155,13 +155,24 @@ export class Browser {
}

static send(channel: string, create: boolean = false, ...args: any[]) {
if (create || (Browser.instance && Browser.instance.isReady))
if (create) {
Browser.awaitsSend.push({ channel, args });

Browser.getInstance();
} else if (Browser.instance && Browser.instance.isReady) {
Browser.getInstance().send(channel, ...args);
else Browser.awaitsSend.push({ channel, args });
} else {
Browser.awaitsSend.push({ channel, args });
}
}

static setTheme(theme: string) {
if (config.get("colorTheme") === "auto")
Browser.send("update-system-theme", false, theme);
}

static setReady(ready: boolean = true) {
Browser.getInstance().isReady = ready;
Browser.getInstance().checkAwaits();
}
}
2 changes: 1 addition & 1 deletion src/managers/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function init() {
});

ipcMain.handle("isReady", (_e, isReady: boolean) => {
Browser.getInstance().isReady = isReady;
Browser.setReady(isReady);
});

ipcMain.handle("checkAppDependencies", () => {
Expand Down

0 comments on commit 56913dc

Please sign in to comment.