Skip to content

fix: open second instance in edge cases #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,27 @@ app.whenReady().then(async () => {

setupMenu()

const focusMainWindow = () => {
/**
* Focus the main window. Restore/re-create it if needed.
*/
function focusMainWindow() {
// There is no main window at all, the app is not initialized yet - ignore
if (!createMainWindow) {
return
}

// There is no window (possible on macOS) - create
if (!mainWindow || mainWindow.isDestroyed()) {
mainWindow = createMainWindow()
mainWindow.once('ready-to-show', () => mainWindow.show())
return
}

// The window is minimized - restore
if (mainWindow.isMinimized()) {
mainWindow.restore()
}

// Show the window in case it is hidden in the system tray and focus it
mainWindow.show()
}
Expand Down Expand Up @@ -214,10 +231,13 @@ app.whenReady().then(async () => {
*/
})

const welcomeWindow = createWelcomeWindow()
welcomeWindow.once('ready-to-show', () => welcomeWindow.show())
mainWindow = createWelcomeWindow()
createMainWindow = createWelcomeWindow
mainWindow.once('ready-to-show', () => mainWindow.show())

ipcMain.once('appData:receive', async (event, appData) => {
const welcomeWindow = mainWindow

if (appData.credentials) {
// User is authenticated - setup and start main window
enableWebRequestInterceptor(appData.serverUrl, {
Expand Down