@@ -36,6 +36,7 @@ import {
36
36
MIN_WIDTH ,
37
37
VENCORD_FILES_DIR
38
38
} from "./constants" ;
39
+ import { darwinURL } from "./index" ;
39
40
import { sendRendererCommand } from "./ipcCommands" ;
40
41
import { Settings , State , VencordSettings } from "./settings" ;
41
42
import { createSplashWindow } from "./splash" ;
@@ -454,18 +455,20 @@ function createMainWindow() {
454
455
455
456
win . webContents . setUserAgent ( BrowserUserAgent ) ;
456
457
457
- const subdomain =
458
- Settings . store . discordBranch === "canary" || Settings . store . discordBranch === "ptb"
459
- ? `${ Settings . store . discordBranch } .`
460
- : "" ;
461
-
462
- win . loadURL ( `https://${ subdomain } discord.com/app` ) ;
458
+ // if the open-url event is fired (in index.ts) while starting up, darwinURL will be set. If not fall back to checking the process args (which Windows and Linux use for URI calling.)
459
+ loadUrl ( darwinURL || process . argv . find ( arg => arg . startsWith ( "discord://" ) ) ) ;
463
460
464
461
return win ;
465
462
}
466
463
467
464
const runVencordMain = once ( ( ) => require ( join ( VENCORD_FILES_DIR , "vencordDesktopMain.js" ) ) ) ;
468
465
466
+ export function loadUrl ( uri : string | undefined ) {
467
+ const branch = Settings . store . discordBranch ;
468
+ const subdomain = branch === "canary" || branch === "ptb" ? `${ branch } .` : "" ;
469
+ mainWin . loadURL ( `https://${ subdomain } discord.com/${ uri ? new URL ( uri ) . pathname . slice ( 1 ) || "app" : "app" } ` ) ;
470
+ }
471
+
469
472
export async function createWindows ( ) {
470
473
const startMinimized = process . argv . includes ( "--start-minimized" ) ;
471
474
const splash = createSplashWindow ( startMinimized ) ;
@@ -498,5 +501,13 @@ export async function createWindows() {
498
501
} ) ;
499
502
} ) ;
500
503
504
+ mainWin . webContents . on ( "did-navigate" , ( _ , url : string , responseCode : number ) => {
505
+ // check url to ensure app doesn't loop
506
+ if ( responseCode >= 300 && new URL ( url ) . pathname !== `/app` ) {
507
+ loadUrl ( undefined ) ;
508
+ console . warn ( `'did-navigate': Caught bad page response: ${ responseCode } , redirecting to main app` ) ;
509
+ }
510
+ } ) ;
511
+
501
512
initArRPC ( ) ;
502
513
}
0 commit comments