Skip to content
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

Fixed issues with loading the app from cold when deep linking #3201

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/main/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function handleAppSecondInstance(event: Event, argv: string[]) {

// Protocol handler for win32
// argv: An array of the second instance’s (command line / deep linked) arguments
MainWindow.show();
const deeplinkingURL = getDeeplinkingURL(argv);
if (deeplinkingURL) {
openDeepLink(deeplinkingURL);
Expand Down
10 changes: 7 additions & 3 deletions src/main/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {BrowserWindow, Rectangle} from 'electron';
import {app, Menu, session, dialog, nativeImage, screen} from 'electron';
import isDev from 'electron-is-dev';

import {APP_MENU_WILL_CLOSE} from 'common/communication';
import {APP_MENU_WILL_CLOSE, MAIN_WINDOW_CREATED} from 'common/communication';
import Config from 'common/config';
import JsonFileManager from 'common/JsonFileManager';
import {Logger} from 'common/log';
Expand Down Expand Up @@ -38,8 +38,12 @@ const log = new Logger('App.Utils');

export function openDeepLink(deeplinkingUrl: string) {
try {
MainWindow.show();
ViewManager.handleDeepLink(deeplinkingUrl);
if (MainWindow.get()) {
MainWindow.show();
ViewManager.handleDeepLink(deeplinkingUrl);
} else {
MainWindow.on(MAIN_WINDOW_CREATED, () => ViewManager.handleDeepLink(deeplinkingUrl));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any race conditions at play? (Could MainWindow get created between our get and on registration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I went to go double-check, I found another instance where we're calling show() before app.ready() which is really not good.

However, other callers of this are also waiting for the ready event, so as long as we're calling it after that there shouldn't be any race conditions as that's when we expect the window to be registered.

The ready event docs if you're interested: https://www.electronjs.org/docs/latest/api/app#event-ready

larkox marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (err) {
log.error(`There was an error opening the deeplinking url: ${err}`);
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/views/viewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ export class ViewManager {
}

private init = () => {
LoadingScreen.show();
ServerManager.getAllServers().forEach((server) => this.loadServer(server));
this.showInitial();
if (ServerManager.hasServers()) {
LoadingScreen.show();
ServerManager.getAllServers().forEach((server) => this.loadServer(server));
this.showInitial();
}
};

private handleDeveloperModeUpdated = (json: DeveloperSettings) => {
Expand Down
Loading