Skip to content

Commit d98ada3

Browse files
committed
tray for mac & better mac fullscreen
1 parent 02997de commit d98ada3

File tree

3 files changed

+99
-61
lines changed

3 files changed

+99
-61
lines changed

main.js

Lines changed: 99 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ function alarmSet() {
7777
}
7878
}
7979

80+
function setFullScreenMode(flag) {
81+
if (win != null) {
82+
if (process.platform == "darwin") win.setSimpleFullScreen(flag);
83+
else win.setFullScreen(flag)
84+
}
85+
}
86+
8087
//before quit
8188
app.on('will-quit', () => {
8289
globalShortcut.unregisterAll()
@@ -153,59 +160,9 @@ app.on('ready', () => {
153160
}
154161

155162
if (process.platform == "win32") tray = new Tray(path.join(__dirname, '\\res\\icons\\iconWin.ico'));
156-
else if (process.platform != "darwin") tray = new Tray(path.join(__dirname, '\\res\\icons\\wnrIcon.png'));
157-
contextMenu = Menu.buildFromTemplate([
158-
{
159-
label: 'wnr' + i18n.__('v') + require("./package.json").version
160-
}, {
161-
type: 'separator'
162-
}, {
163-
label: i18n.__('start-or-stop'),
164-
enabled: false,
165-
click: function () {
166-
if (win != null) win.webContents.send('start-or-stop')
167-
}
168-
}, {
169-
type: 'separator'
170-
}, {
171-
label: i18n.__('website'),
172-
click: function () {
173-
shell.openExternal('https://wnr.scris.top/');
174-
}
175-
}, {
176-
label: i18n.__('help-page'),
177-
click: function () {
178-
shell.openExternal('https://wnr.scris.top/help.html');
179-
}
180-
}, {
181-
label: i18n.__('github'),
182-
click: function () {
183-
shell.openExternal('https://github.com/RoderickQiu/wnr/');
184-
}
185-
}, {
186-
type: 'separator'
187-
}, {
188-
label: i18n.__('show-or-hide'), click: () => {
189-
if (win != null) win.isVisible() ? win.hide() : win.show();
190-
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
191-
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
192-
if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show();
193-
}
194-
}, {
195-
label: i18n.__('exit'), click: () => { windowCloseChk() }
196-
}
197-
]);
198-
if (tray != null) {
199-
tray.setToolTip('wnr');
200-
tray.setContextMenu(contextMenu);
201-
tray.on('click', () => {
202-
if (win != null) win.isVisible() ? win.hide() : win.show();
203-
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
204-
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
205-
if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show();
206-
});//tray
207-
}
208-
163+
else if (process.platform == "darwin") tray = new Tray(path.join(__dirname, '/res/icons/trayIconMacTemplate.png'));
164+
if (tray != null) tray.setToolTip('wnr');
165+
traySolution(false);
209166
macOSFullscreenSolution(false);
210167
isDarkMode();
211168

@@ -253,6 +210,82 @@ app.on('ready', () => {
253210
}//alternated the former default time settings
254211
})
255212

213+
function traySolution(isFullScreen) {
214+
if (app.isReady()) {
215+
if (!isFullScreen) {
216+
if (process.platform == "darwin") app.dock.show();
217+
contextMenu = Menu.buildFromTemplate([
218+
{
219+
label: 'wnr' + i18n.__('v') + require("./package.json").version
220+
}, {
221+
type: 'separator'
222+
}, {
223+
label: i18n.__('start-or-stop'),
224+
enabled: false,
225+
click: function () {
226+
if (win != null) win.webContents.send('start-or-stop')
227+
}
228+
}, {
229+
type: 'separator'
230+
},
231+
{
232+
label: i18n.__('website'),
233+
click: function () {
234+
shell.openExternal('https://wnr.scris.top/');
235+
}
236+
}, {
237+
label: i18n.__('help-page'),
238+
click: function () {
239+
shell.openExternal('https://wnr.scris.top/help.html');
240+
}
241+
}, {
242+
label: i18n.__('github'),
243+
click: function () {
244+
shell.openExternal('https://github.com/RoderickQiu/wnr/');
245+
}
246+
}, {
247+
type: 'separator'
248+
}, {
249+
label: i18n.__('show-or-hide'), click: () => {
250+
if (win != null) win.isVisible() ? win.hide() : win.show();
251+
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
252+
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
253+
if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show();
254+
}
255+
}, {
256+
label: i18n.__('exit'), click: () => { windowCloseChk() }
257+
}
258+
]);
259+
if (tray != null) {
260+
tray.on('click', () => {
261+
if (win != null) win.isVisible() ? win.hide() : win.show();
262+
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
263+
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
264+
if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show();
265+
});//tray
266+
tray.setContextMenu(contextMenu);
267+
}
268+
} else {
269+
if (process.platform == "darwin") app.dock.hide();
270+
contextMenu = Menu.buildFromTemplate([
271+
{
272+
label: 'wnr' + i18n.__('v') + require("./package.json").version
273+
}, {
274+
type: 'separator'
275+
}, {
276+
label: i18n.__('start-or-stop'),
277+
click: function () {
278+
if (win != null) win.webContents.send('start-or-stop')
279+
}
280+
}]);
281+
if (tray != null) {
282+
tray.setContextMenu(contextMenu);
283+
tray.on('click', () => { ; })
284+
}
285+
}
286+
}
287+
}
288+
256289
function macOSFullscreenSolution(isFullScreen) {
257290
if (app.isReady()) {
258291
if (process.platform === 'darwin') {
@@ -334,8 +367,7 @@ function macOSFullscreenSolution(isFullScreen) {
334367
}]
335368
}];
336369
var osxMenu = Menu.buildFromTemplate(template);
337-
Menu.setApplicationMenu(osxMenu);
338-
app.dock.setMenu(osxMenu)
370+
Menu.setApplicationMenu(osxMenu)
339371
}//dock menu for mac os
340372
}
341373
}
@@ -386,8 +418,9 @@ app.on('activate', () => {
386418

387419
ipcMain.on('focus-first', function () {
388420
if (store.get("top") != true && win != null) win.setAlwaysOnTop(true);//always on top when full screen
389-
if (win != null) win.setFullScreen(true);
421+
if (win != null) setFullScreenMode(true);
390422
macOSFullscreenSolution(true);
423+
traySolution(true);
391424
isWorkMode = true;
392425
store.set("fullscreen-protection", true);
393426
})
@@ -402,12 +435,14 @@ ipcMain.on('warning-giver-workend', function () {
402435
win.flashFrame(true);
403436
if (store.get("fullscreen") == true) {
404437
if (store.get("top") != true) win.setAlwaysOnTop(true);//always on top when full screen
405-
win.setFullScreen(true);
438+
setFullScreenMode(true);
406439
macOSFullscreenSolution(true);
440+
traySolution(true);
407441
} else {
408442
if (store.get("top") != true) win.setAlwaysOnTop(false);//cancel unnecessary always-on-top
409-
win.setFullScreen(false);
443+
setFullScreenMode(false);
410444
macOSFullscreenSolution(false);
445+
traySolution(false);
411446
}
412447
setTimeout(function () {
413448
dialog.showMessageBox(win, {
@@ -430,12 +465,14 @@ ipcMain.on('warning-giver-restend', function () {
430465
win.flashFrame(true);
431466
if (store.get("fullscreen-work") == true) {
432467
if (store.get("top") != true) win.setAlwaysOnTop(true);//always on top when full screen
433-
win.setFullScreen(true);
468+
setFullScreenMode(true);
434469
macOSFullscreenSolution(true);
470+
traySolution(true);
435471
} else {
436472
if (store.get("top") != true) win.setAlwaysOnTop(false);//cancel unnecessary always-on-top
437-
win.setFullScreen(false);
473+
setFullScreenMode(false);
438474
macOSFullscreenSolution(false);
475+
traySolution(false);
439476
}
440477
setTimeout(function () {
441478
dialog.showMessageBox(win, {
@@ -458,8 +495,9 @@ ipcMain.on('warning-giver-all-task-end', function () {
458495
win.flashFrame(true);
459496
if (store.get("fullscreen") == true) {
460497
if (store.get("top") != true) win.setAlwaysOnTop(false);//cancel unnecessary always-on-top
461-
win.setFullScreen(false);
498+
setFullScreenMode(false);
462499
macOSFullscreenSolution(false);
500+
traySolution(false);
463501
}
464502
setTimeout(function () {
465503
dialog.showMessageBox(win, {

res/icons/trayIconMacTemplate.png

673 Bytes
Loading

res/icons/[email protected]

1.36 KB
Loading

0 commit comments

Comments
 (0)