Merge pull request #373 from SiriusXT/New_window_from_taskbar

Open New window from taskbar
This commit is contained in:
Elian Doran 2024-08-30 22:24:38 +03:00 committed by GitHub
commit b7ed153b14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@ import log from "./log.js";
import sqlInit from "./sql_init.js"; import sqlInit from "./sql_init.js";
import cls from "./cls.js"; import cls from "./cls.js";
import keyboardActionsService from "./keyboard_actions.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 { App, BrowserWindow, WebContents, ipcMain } from 'electron';
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
@ -46,6 +46,17 @@ ipcMain.on('create-extra-window', (event, arg) => {
}); });
async function createMainWindow(app: App) { 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 windowStateKeeper = (await import('electron-window-state')).default; // should not be statically imported
const mainWindowState = windowStateKeeper({ const mainWindowState = windowStateKeeper({
@ -82,10 +93,12 @@ async function createMainWindow(app: App) {
configureWebContents(mainWindow.webContents, spellcheckEnabled); configureWebContents(mainWindow.webContents, spellcheckEnabled);
app.on('second-instance', () => { app.on('second-instance', (event, commandLine) => {
// Someone tried to run a second instance, we should focus our window. if (commandLine.includes('--new-window')) {
// see www.ts "requestSingleInstanceLock" for the rest of this logic with explanation createExtraWindow("");
if (mainWindow) { } 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()) { if (mainWindow.isMinimized()) {
mainWindow.restore(); mainWindow.restore();
} }