Skip to content

Commit

Permalink
faster window reopen (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambarvm authored May 12, 2022
1 parent b214963 commit 81fb013
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/desktop/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ const width = 800;
/** @type {Tray} */
let tray;

/** @type {BrowserWindow} */
let mainWindow;

function createWindow() {
if (mainWindow) {
mainWindow.show();
return;
}

// Create the browser window.
const window = new BrowserWindow({
mainWindow = new BrowserWindow({
title: appName,
width,
height,
Expand All @@ -25,16 +33,24 @@ function createWindow() {
},
});

mainWindow.on('close', e => {
e.preventDefault();
mainWindow.hide();
});
mainWindow.on('closed', () => {
mainWindow = null;
});

const port = process.env.UI_PORT || 3000;
const url = isDev
? `http://localhost:${port}`
: join(__dirname, '../src/out/index.html');

// and load the index.html of the app.
if (isDev) {
window?.loadURL(url);
mainWindow?.loadURL(url);
} else {
window?.loadFile(url);
mainWindow?.loadFile(url);
}
}

Expand All @@ -50,7 +66,12 @@ app.whenReady().then(() => {
tray.on('click', () => createWindow());
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open', click: () => createWindow() },
{ label: 'Close', click: () => app.quit() },
{
label: 'Close',
click: () => {
app.quit();
},
},
]);

tray.setContextMenu(contextMenu);
Expand Down

0 comments on commit 81fb013

Please sign in to comment.