#113 only open a new window from the dock if already visible

This commit is contained in:
dragonwocky 2020-11-01 21:04:26 +11:00
parent f4d269bcdc
commit b985217611

View File

@ -7,8 +7,6 @@
'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,11 +14,25 @@ module.exports = (store, __exports) => {
path = require('path'), path = require('path'),
is_mac = process.platform === 'darwin', is_mac = process.platform === 'darwin',
is_win = process.platform === 'win32', is_win = process.platform === 'win32',
helpers = require('../../pkg/helpers.js'); helpers = require('../../pkg/helpers.js'),
getAllWindows = electron.BrowserWindow.getAllWindows;
function newWindow() {
require('./createWindow.js')(
store,
require(path.resolve(`${helpers.__notion}/app/main/createWindow.js`))
)(
'',
getAllWindows().find((win) => win !== enhancer_menu)
);
}
electron.app.on('second-instance', (event, args, workingDirectory) => { electron.app.on('second-instance', (event, args, workingDirectory) => {
if (!store().openhidden) { const windows = getAllWindows();
electron.BrowserWindow.getAllWindows().forEach((window) => { if (windows.some((win) => win.isVisible())) {
newWindow();
} else {
windows.forEach((window) => {
window.show(); window.show();
window.focus(); window.focus();
if (store().maximized) window.maximize(); if (store().maximized) window.maximize();
@ -186,19 +198,7 @@ module.exports = (store, __exports) => {
{ {
type: 'normal', type: 'normal',
label: 'New Window', label: 'New Window',
click: () => { click: newWindow(),
require('./createWindow.js')(
store,
require(path.resolve(
`${helpers.__notion}/app/main/createWindow.js`
))
)(
'',
electron.BrowserWindow.getAllWindows().find(
(win) => win !== enhancer_menu
)
);
},
accelerator: 'CommandOrControl+Shift+N', accelerator: 'CommandOrControl+Shift+N',
}, },
{ {
@ -238,13 +238,13 @@ module.exports = (store, __exports) => {
if (is_mac) electron.app.hide(); if (is_mac) electron.app.hide();
} }
function toggleWindows() { function toggleWindows() {
const windows = electron.BrowserWindow.getAllWindows(); const windows = getAllWindows();
if (windows.some((win) => win.isVisible())) hideWindows(windows); if (windows.some((win) => win.isVisible())) hideWindows(windows);
else showWindows(windows); 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 = getAllWindows();
if (windows.some((win) => win.isFocused() && win.isVisible())) if (windows.some((win) => win.isFocused() && win.isVisible()))
hideWindows(windows); hideWindows(windows);
else showWindows(windows); else showWindows(windows);