Skip to content

Commit 17e82aa

Browse files
authored
Merge pull request #73 from int2001/no_more_tray
Remove Tray, it confuses the people
2 parents 592504a + 45b892b commit 17e82aa

File tree

1 file changed

+18
-51
lines changed

1 file changed

+18
-51
lines changed

main.js

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {app, BrowserWindow, Tray, Notification, Menu, globalShortcut, powerSaveBlocker } = require('electron/main');
1+
const {app, BrowserWindow, globalShortcut, Notification, powerSaveBlocker } = require('electron/main');
22
const path = require('node:path');
33
const {ipcMain} = require('electron')
44
const http = require('http');
@@ -8,7 +8,6 @@ const net = require('net');
88
const gotTheLock = app.requestSingleInstanceLock();
99

1010
let powerSaveBlockerId;
11-
let tray;
1211
let s_mainWindow;
1312
let msgbacklog=[];
1413
let httpServer;
@@ -145,14 +144,18 @@ ipcMain.on("quit", async (event,arg) => {
145144
});
146145

147146
function show_noti(arg) {
148-
try {
149-
const notification = new Notification({
150-
title: 'Wavelog',
151-
body: arg
152-
});
153-
notification.show();
154-
} catch(e) {
155-
console.log("No notification possible on this system / ignoring");
147+
if (Notification.isSupported()) {
148+
try {
149+
const notification = new Notification({
150+
title: 'Wavelog',
151+
body: arg
152+
});
153+
notification.show();
154+
} catch(e) {
155+
console.log("No notification possible on this system / ignoring");
156+
}
157+
} else {
158+
console.log("Notifications are not supported on this platform");
156159
}
157160
}
158161

@@ -185,9 +188,6 @@ app.on('before-quit', () => {
185188
if (httpServer) {
186189
httpServer.close();
187190
}
188-
if (tray) {
189-
tray.destroy();
190-
}
191191
});
192192

193193
process.on('SIGINT', () => {
@@ -217,45 +217,12 @@ if (!gotTheLock) {
217217
app.on('activate', function () {
218218
if (BrowserWindow.getAllWindows().length === 0) createWindow()
219219
});
220-
s_mainWindow.webContents.once('dom-ready', function() {
221-
if (msgbacklog.length>0) {
222-
s_mainWindow.webContents.send('updateMsg',msgbacklog.pop());
223-
}
224-
});
225-
226-
// Create the tray icon
227-
const path = require('path');
228-
const iconPath = path.join(__dirname, 'icon1616.png');
229-
tray = new Tray(iconPath);
230-
231-
const contextMenu = Menu.buildFromTemplate([
232-
{ label: 'Show App', click: () => s_mainWindow.show() },
233-
{ label: 'Quit', click: () => {
234-
console.log("Exiting");
235-
app.isQuitting = true;
236-
app.quit();
237-
}
238-
},
239-
]);
240-
241-
tray.setContextMenu(contextMenu);
242-
tray.setToolTip(require('./package.json').name + " V" + require('./package.json').version);
243-
244-
s_mainWindow.on('minimize', (event) => {
245-
event.preventDefault();
246-
s_mainWindow.hide(); // Hides the window instead of minimizing it to the taskbar
247-
});
248-
249-
s_mainWindow.on('close', (event) => {
250-
if (!app.isQuitting) {
251-
event.preventDefault();
252-
s_mainWindow.hide();
253-
}
220+
s_mainWindow.webContents.once('dom-ready', function() {
221+
if (msgbacklog.length>0) {
222+
s_mainWindow.webContents.send('updateMsg',msgbacklog.pop());
223+
}
224+
});
254225
});
255-
if (app.isPackaged && (process.platform === 'darwin')) {
256-
app.dock.hide();
257-
}
258-
})
259226
}
260227

261228
app.on('window-all-closed', function () {

0 commit comments

Comments
 (0)