Skip to content

Commit 97f1cdf

Browse files
committed
1st approach to make a tray-app out of it
1 parent 2c31746 commit 97f1cdf

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

main.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const {app, BrowserWindow, globalShortcut } = require('electron/main');
1+
const {app, BrowserWindow, Tray, Menu, globalShortcut } = require('electron/main');
22
const path = require('node:path');
33
const {ipcMain} = require('electron')
44
const http = require('http');
55
const xml = require("xml2js");
66
const net = require('net');
77

8+
let tray;
89
let s_mainWindow;
910
let msgbacklog=[];
1011
var WServer;
@@ -50,7 +51,7 @@ function createWindow () {
5051
}
5152
});
5253
if (app.isPackaged) {
53-
mainWindow.setMenu(null);
54+
mainWindow.setMenu(null);
5455
}
5556

5657

@@ -133,6 +134,7 @@ ipcMain.on("setCAT", async (event,arg) => {
133134
});
134135

135136
ipcMain.on("quit", async (event,arg) => {
137+
app.isQuitting = true;
136138
app.quit();
137139
event.returnValue=true;
138140
});
@@ -157,6 +159,12 @@ ipcMain.on("test", async (event,arg) => {
157159
}
158160
});
159161

162+
app.on('before-quit', () => {
163+
if (tray) {
164+
tray.destroy();
165+
}
166+
});
167+
160168
app.whenReady().then(() => {
161169
s_mainWindow=createWindow();
162170
createAdvancedWindow(s_mainWindow);
@@ -169,10 +177,40 @@ app.whenReady().then(() => {
169177
s_mainWindow.webContents.send('updateMsg',msgbacklog.pop());
170178
}
171179
});
180+
181+
// Create the tray icon
182+
tray = new Tray('icon1616.png');
183+
184+
const contextMenu = Menu.buildFromTemplate([
185+
{ label: 'Show App', click: () => s_mainWindow.show() },
186+
{ label: 'Quit', click: () => {
187+
console.log("Exiting");
188+
app.isQuitting = true;
189+
app.quit();
190+
}
191+
},
192+
]);
193+
194+
tray.setContextMenu(contextMenu);
195+
tray.setToolTip(require('./package.json').name + " V" + require('./package.json').version);
196+
197+
s_mainWindow.on('minimize', (event) => {
198+
event.preventDefault();
199+
s_mainWindow.hide(); // Hides the window instead of minimizing it to the taskbar
200+
});
201+
202+
s_mainWindow.on('close', (event) => {
203+
if (!app.isQuitting) {
204+
event.preventDefault();
205+
s_mainWindow.hide();
206+
}
207+
});
208+
209+
app.dock.hide();
172210
})
173211

174212
app.on('window-all-closed', function () {
175-
if (process.platform !== 'darwin') app.quit()
213+
if (process.platform !== 'darwin') app.quit();
176214
app.quit();
177215
})
178216

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Gateway for connecting WSJT-* and FLRig to Wavelog",
55
"keywords": [],
66
"main": "./main.js",
7-
"version": "1.1.4",
7+
"version": "1.1.5",
88
"author": "DJ7NT",
99
"scripts": {
1010
"start": "electron-forge start",

0 commit comments

Comments
 (0)