From 895334c640b3a23b269a60ea65a9ad9bce0d3f0d Mon Sep 17 00:00:00 2001 From: Solirpa Date: Thu, 2 Dec 2021 15:53:08 +0800 Subject: [PATCH] fix open duplicate notion windows when click dock notion icon on macos bigsur (#487) --- mods/core/createWindow.js | 9 ++++++++- mods/core/systemMenu.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/core/createWindow.js b/mods/core/createWindow.js index c9883f7..7cafbf9 100644 --- a/mods/core/createWindow.js +++ b/mods/core/createWindow.js @@ -9,6 +9,7 @@ module.exports = (store, __exports) => { const electron = require('electron'), + is_mac = process.platform === 'darwin', allWindows = () => electron.BrowserWindow.getAllWindows().filter( (win) => win.getTitle() !== 'notion-enhancer menu' @@ -17,7 +18,7 @@ module.exports = (store, __exports) => { path = require('path'), helpers = require('../../pkg/helpers.js'); - __exports.createWindow = function (relativeUrl, focused_window) { + __exports.createWindow = function (relativeUrl, focused_window, force = false) { if (!relativeUrl) relativeUrl = ''; const window_state = require(`${helpers .getNotionResources() @@ -41,6 +42,12 @@ module.exports = (store, __exports) => { rect.width = focused_window.getSize()[0]; rect.height = focused_window.getSize()[1]; } + + const windows = electron.BrowserWindow.getAllWindows(); + if (is_mac && !force && windows.length) { + return; + } + let window = new electron.BrowserWindow({ show: false, backgroundColor: '#ffffff', diff --git a/mods/core/systemMenu.js b/mods/core/systemMenu.js index 2fb0535..82fb7bd 100644 --- a/mods/core/systemMenu.js +++ b/mods/core/systemMenu.js @@ -164,7 +164,7 @@ module.exports = (store, __exports) => { intl.formatMessage(menuMessages.newWindow) ), accelerator: 'CmdOrCtrl+Shift+N', - click: () => createWindow.createWindow(), + click: () => createWindow.createWindow('', '', true), }, ...(tabsEnabled ? [