From 5ce70f4e033cc9b511dad8b0bae84ea71eda9b2d Mon Sep 17 00:00:00 2001 From: covidisahoax Date: Tue, 3 Dec 2024 10:00:04 -0800 Subject: [PATCH] fix window/app focusing --- src/main/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index ab0b59075b4dd..27f4e4d0290cb 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -256,7 +256,13 @@ function runApp() { // Someone tried to run a second instance, we should focus our window if (mainWindow && typeof commandLine !== 'undefined') { if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() + process.platform === 'darwin' ? app.focus({ steal: true }) : app.focus() + mainWindow.setAlwaysOnTop(true) + mainWindow.show() + setTimeout(function() { mainWindow.focus() }, 100) + mainWindow.moveTop() + process.platform === 'darwin' ? app.focus({ steal: true }) : app.focus() + mainWindow.setAlwaysOnTop(false) const url = getLinkUrl(commandLine) if (url) { @@ -797,8 +803,13 @@ function runApp() { return } + process.platform === 'darwin' ? app.focus({ steal: true }) : app.focus() + newWindow.setAlwaysOnTop(true) newWindow.show() - newWindow.focus() + setTimeout(function() { newWindow.focus() }, 100) + newWindow.moveTop() + process.platform === 'darwin' ? app.focus({ steal: true }) : app.focus() + newWindow.setAlwaysOnTop(false) if (process.env.NODE_ENV === 'development') { newWindow.webContents.openDevTools({ activate: false })