Skip to content

Commit

Permalink
Merge pull request #876 from nextcloud/fix/instant-second-instance
Browse files Browse the repository at this point in the history
fix: open second instance in edge cases
  • Loading branch information
ShGKme authored Nov 11, 2024
2 parents 7276690 + 00bc9e2 commit e7d4db9
Showing 1 changed file with 23 additions and 3 deletions.
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

0 comments on commit e7d4db9

Please sign in to comment.