Skip to content

Commit e7d4db9

Browse files
authoredNov 11, 2024
Merge pull request #876 from nextcloud/fix/instant-second-instance
fix: open second instance in edge cases
2 parents 7276690 + 00bc9e2 commit e7d4db9

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed
 

‎src/main.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,27 @@ app.whenReady().then(async () => {
132132

133133
setupMenu()
134134

135-
const focusMainWindow = () => {
135+
/**
136+
* Focus the main window. Restore/re-create it if needed.
137+
*/
138+
function focusMainWindow() {
139+
// There is no main window at all, the app is not initialized yet - ignore
140+
if (!createMainWindow) {
141+
return
142+
}
143+
144+
// There is no window (possible on macOS) - create
145+
if (!mainWindow || mainWindow.isDestroyed()) {
146+
mainWindow = createMainWindow()
147+
mainWindow.once('ready-to-show', () => mainWindow.show())
148+
return
149+
}
150+
151+
// The window is minimized - restore
136152
if (mainWindow.isMinimized()) {
137153
mainWindow.restore()
138154
}
155+
139156
// Show the window in case it is hidden in the system tray and focus it
140157
mainWindow.show()
141158
}
@@ -214,10 +231,13 @@ app.whenReady().then(async () => {
214231
*/
215232
})
216233

217-
const welcomeWindow = createWelcomeWindow()
218-
welcomeWindow.once('ready-to-show', () => welcomeWindow.show())
234+
mainWindow = createWelcomeWindow()
235+
createMainWindow = createWelcomeWindow
236+
mainWindow.once('ready-to-show', () => mainWindow.show())
219237

220238
ipcMain.once('appData:receive', async (event, appData) => {
239+
const welcomeWindow = mainWindow
240+
221241
if (appData.credentials) {
222242
// User is authenticated - setup and start main window
223243
enableWebRequestInterceptor(appData.serverUrl, {

0 commit comments

Comments
 (0)