#113 reshow hidden windows when clicking app icon in dock

This commit is contained in:
dragonwocky 2020-11-01 15:00:22 +11:00
parent 6b161eb403
commit ba8163a456
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D

View File

@ -7,6 +7,8 @@
'use strict'; 'use strict';
const { start } = require('repl');
let tray, enhancer_menu; let tray, enhancer_menu;
module.exports = (store, __exports) => { module.exports = (store, __exports) => {
@ -16,7 +18,17 @@ module.exports = (store, __exports) => {
is_win = process.platform === 'win32', is_win = process.platform === 'win32',
helpers = require('../../pkg/helpers.js'); helpers = require('../../pkg/helpers.js');
electron.app.on('ready', () => { electron.app.on('second-instance', (event, args, workingDirectory) => {
if (!store().openhidden) {
electron.BrowserWindow.getAllWindows().forEach((window) => {
window.show();
window.focus();
if (store().maximized) window.maximize();
});
}
});
electron.app.once('ready', () => {
// tray // tray
tray = new electron.Tray( tray = new electron.Tray(
@ -215,30 +227,27 @@ module.exports = (store, __exports) => {
// hotkey // hotkey
function showWindows() { function showWindows(windows) {
const windows = electron.BrowserWindow.getAllWindows();
if (is_mac) electron.app.show(); if (is_mac) electron.app.show();
if (store().maximized) windows.forEach((win) => [win.maximize()]); if (store().maximized) windows.forEach((win) => [win.maximize()]);
else windows.forEach((win) => win.show()); else windows.forEach((win) => win.show());
electron.app.focus({ steal: true }); electron.app.focus({ steal: true });
} }
function hideWindows() { function hideWindows(windows) {
const windows = electron.BrowserWindow.getAllWindows();
windows.forEach((win) => [win.isFocused() && win.blur(), win.hide()]); windows.forEach((win) => [win.isFocused() && win.blur(), win.hide()]);
if (is_mac) electron.app.hide(); if (is_mac) electron.app.hide();
} }
function toggleWindows() { function toggleWindows() {
const windows = electron.BrowserWindow.getAllWindows(); const windows = electron.BrowserWindow.getAllWindows();
if (windows.some((win) => win.isVisible())) hideWindows(); if (windows.some((win) => win.isVisible())) hideWindows(windows);
else showWindows(); else showWindows(windows);
} }
tray.on('click', toggleWindows); tray.on('click', toggleWindows);
electron.globalShortcut.register(store().hotkey, () => { electron.globalShortcut.register(store().hotkey, () => {
const windows = electron.BrowserWindow.getAllWindows(); const windows = electron.BrowserWindow.getAllWindows();
if (windows.some((win) => win.isFocused() && win.isVisible())) if (windows.some((win) => win.isFocused() && win.isVisible()))
hideWindows(); hideWindows(windows);
else showWindows(); else showWindows(windows);
}); });
}); });
}; };