Commit 11f50478 by bubblepipe42

tray

parent 834ab29a
...@@ -110,8 +110,43 @@ function waitForServer(resolve, reject, retries = 30) { ...@@ -110,8 +110,43 @@ function waitForServer(resolve, reject, retries = 30) {
req.end(); req.end();
} }
function createWindow() {
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
},
title: 'New API',
icon: path.join(__dirname, 'icon.png')
});
mainWindow.loadURL(`http://localhost:${PORT}`);
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
// Close to tray instead of quitting
mainWindow.on('close', (event) => {
if (!app.isQuitting) {
event.preventDefault();
mainWindow.hide();
if (process.platform === 'darwin') {
app.dock.hide();
}
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
}
function createTray() { function createTray() {
tray = new Tray(path.join(__dirname, 'tray-icon.png')); tray = new Tray(path.join(__dirname, 'tray-iconTemplate.png'));
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
...@@ -140,7 +175,7 @@ function createTray() { ...@@ -140,7 +175,7 @@ function createTray() {
tray.setToolTip('New API'); tray.setToolTip('New API');
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
// On macOS, clicking the tray icon shows the menu // On macOS, clicking the tray icon shows the window
tray.on('click', () => { tray.on('click', () => {
if (mainWindow === null) { if (mainWindow === null) {
createWindow(); createWindow();
...@@ -153,41 +188,6 @@ function createTray() { ...@@ -153,41 +188,6 @@ function createTray() {
}); });
} }
function createWindow() {
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
},
title: 'New API',
icon: path.join(__dirname, 'icon.png')
});
mainWindow.loadURL(`http://localhost:${PORT}`);
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
// Close to tray instead of quitting
mainWindow.on('close', (event) => {
if (!app.isQuitting) {
event.preventDefault();
mainWindow.hide();
if (process.platform === 'darwin') {
app.dock.hide();
}
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(async () => { app.whenReady().then(async () => {
try { try {
await startServer(); await startServer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment