fix closing new window, closes #2502

This commit is contained in:
zadam 2022-01-02 21:35:02 +01:00
parent 003fec4b11
commit faf81ae056

View file

@ -16,7 +16,10 @@ let mainWindow;
let setupWindow; let setupWindow;
async function createExtraWindow(notePath, hoistedNoteId = 'root') { async function createExtraWindow(notePath, hoistedNoteId = 'root') {
const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled');
const {BrowserWindow} = require('electron'); const {BrowserWindow} = require('electron');
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 1000, width: 1000,
height: 800, height: 800,
@ -25,7 +28,7 @@ async function createExtraWindow(notePath, hoistedNoteId = 'root') {
enableRemoteModule: true, enableRemoteModule: true,
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, contextIsolation: false,
spellcheck: optionService.getOptionBool('spellCheckEnabled') spellcheck: spellcheckEnabled
}, },
frame: optionService.getOptionBool('nativeTitleBarVisible'), frame: optionService.getOptionBool('nativeTitleBarVisible'),
icon: getIcon() icon: getIcon()
@ -33,6 +36,8 @@ async function createExtraWindow(notePath, hoistedNoteId = 'root') {
win.setMenuBarVisibility(false); win.setMenuBarVisibility(false);
win.loadURL('http://127.0.0.1:' + await port + '/?extra=1&extraHoistedNoteId=' + hoistedNoteId + '#' + notePath); win.loadURL('http://127.0.0.1:' + await port + '/?extra=1&extraHoistedNoteId=' + hoistedNoteId + '#' + notePath);
configureWebContents(win.webContents, spellcheckEnabled);
} }
ipcMain.on('create-extra-window', (event, arg) => { ipcMain.on('create-extra-window', (event, arg) => {
@ -74,8 +79,10 @@ async function createMainWindow() {
mainWindow.loadURL('http://127.0.0.1:' + await port); mainWindow.loadURL('http://127.0.0.1:' + await port);
mainWindow.on('closed', () => mainWindow = null); mainWindow.on('closed', () => mainWindow = null);
const {webContents} = mainWindow; configureWebContents(mainWindow.webContents, spellcheckEnabled);
}
function configureWebContents(webContents, spellcheckEnabled) {
require("@electron/remote/main").enable(webContents); require("@electron/remote/main").enable(webContents);
webContents.on('new-window', (e, url) => { webContents.on('new-window', (e, url) => {