fix open duplicate notion windows when click dock notion icon on macos bigsur (#487)

This commit is contained in:
Solirpa 2021-12-02 15:53:08 +08:00 committed by GitHub
parent b1b1a1b725
commit 895334c640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -9,6 +9,7 @@
module.exports = (store, __exports) => { module.exports = (store, __exports) => {
const electron = require('electron'), const electron = require('electron'),
is_mac = process.platform === 'darwin',
allWindows = () => allWindows = () =>
electron.BrowserWindow.getAllWindows().filter( electron.BrowserWindow.getAllWindows().filter(
(win) => win.getTitle() !== 'notion-enhancer menu' (win) => win.getTitle() !== 'notion-enhancer menu'
@ -17,7 +18,7 @@ module.exports = (store, __exports) => {
path = require('path'), path = require('path'),
helpers = require('../../pkg/helpers.js'); helpers = require('../../pkg/helpers.js');
__exports.createWindow = function (relativeUrl, focused_window) { __exports.createWindow = function (relativeUrl, focused_window, force = false) {
if (!relativeUrl) relativeUrl = ''; if (!relativeUrl) relativeUrl = '';
const window_state = require(`${helpers const window_state = require(`${helpers
.getNotionResources() .getNotionResources()
@ -41,6 +42,12 @@ module.exports = (store, __exports) => {
rect.width = focused_window.getSize()[0]; rect.width = focused_window.getSize()[0];
rect.height = focused_window.getSize()[1]; rect.height = focused_window.getSize()[1];
} }
const windows = electron.BrowserWindow.getAllWindows();
if (is_mac && !force && windows.length) {
return;
}
let window = new electron.BrowserWindow({ let window = new electron.BrowserWindow({
show: false, show: false,
backgroundColor: '#ffffff', backgroundColor: '#ffffff',

View File

@ -164,7 +164,7 @@ module.exports = (store, __exports) => {
intl.formatMessage(menuMessages.newWindow) intl.formatMessage(menuMessages.newWindow)
), ),
accelerator: 'CmdOrCtrl+Shift+N', accelerator: 'CmdOrCtrl+Shift+N',
click: () => createWindow.createWindow(), click: () => createWindow.createWindow('', '', true),
}, },
...(tabsEnabled ...(tabsEnabled
? [ ? [