From e5213640d7b7b38cd3a207db1f9a1517019dd712 Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Wed, 28 Aug 2024 06:28:02 +0000 Subject: [PATCH] Open new window from taskbar --- src/services/window.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/services/window.ts b/src/services/window.ts index e22ca382b..89415f74d 100644 --- a/src/services/window.ts +++ b/src/services/window.ts @@ -7,7 +7,7 @@ import log from "./log.js"; import sqlInit from "./sql_init.js"; import cls from "./cls.js"; import keyboardActionsService from "./keyboard_actions.js"; -import remoteMain from "@electron/remote/main/index.js" +import remoteMain from "@electron/remote/main/index.js"; import { App, BrowserWindow, WebContents, ipcMain } from 'electron'; import { fileURLToPath } from "url"; @@ -46,6 +46,17 @@ ipcMain.on('create-extra-window', (event, arg) => { }); async function createMainWindow(app: App) { + app.setUserTasks([ + { + program: process.execPath, + arguments: '--new-window', + iconPath: process.execPath, + iconIndex: 0, + title: 'Open New Window', + description: 'Open new window' + } + ]); + const windowStateKeeper = (await import('electron-window-state')).default; // should not be statically imported const mainWindowState = windowStateKeeper({ @@ -57,7 +68,7 @@ async function createMainWindow(app: App) { const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled'); const { BrowserWindow } = (await import('electron')); // should not be statically imported - + mainWindow = new BrowserWindow({ x: mainWindowState.x, y: mainWindowState.y, @@ -82,10 +93,12 @@ async function createMainWindow(app: App) { configureWebContents(mainWindow.webContents, spellcheckEnabled); - app.on('second-instance', () => { - // Someone tried to run a second instance, we should focus our window. - // see www.ts "requestSingleInstanceLock" for the rest of this logic with explanation - if (mainWindow) { + app.on('second-instance', (event, commandLine) => { + if (commandLine.includes('--new-window')) { + createExtraWindow(""); + } else if (mainWindow) { + // Someone tried to run a second instance, we should focus our window. + // see www.ts "requestSingleInstanceLock" for the rest of this logic with explanation if (mainWindow.isMinimized()) { mainWindow.restore(); }