Skip to content

Commit

Permalink
fix: fix not being able to open preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjbutler committed Feb 19, 2022
1 parent ea38649 commit 2ad3232
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/main/src/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const pageUrl = import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== u
? import.meta.env.VITE_DEV_SERVER_URL
: new URL('../renderer/dist/index.html', 'file://' + __dirname).toString();

let windowId: number | undefined;

async function createWindow() {
const browserWindow = new BrowserWindow({
width: 1050,
Expand All @@ -29,6 +31,8 @@ async function createWindow() {
},
});

windowId = browserWindow.id;

/**
* If you install `show: true` then it can cause issues when trying to close the window.
* Use `show: false` and listener events `ready-to-show` to fix these issues.
Expand All @@ -54,9 +58,12 @@ async function createWindow() {
* Restore existing BrowserWindow or Create new BrowserWindow
*/
export async function restoreOrCreateWindow() {
let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed() && w.webContents.getURL() === pageUrl);
let window: BrowserWindow | null = null;
if (windowId) {
window = BrowserWindow.fromId(windowId);
}

if (window === undefined) {
if (!window) {
window = await createWindow();
}

Expand Down

0 comments on commit 2ad3232

Please sign in to comment.