404 page handler
Discord handles incorrect schemes pretty well but `discord:///settings` is a case where it doesn't, so this may be needed to ensure user experience
This commit is contained in:
		
							parent
							
								
									b3e0d2e5b2
								
							
						
					
					
						commit
						dbe109c44b
					
				
					 4 changed files with 22 additions and 10 deletions
				
			
		|  | @ -18,7 +18,7 @@ import { IpcEvents } from "../shared/IpcEvents"; | ||||||
| import { setBadgeCount } from "./appBadge"; | import { setBadgeCount } from "./appBadge"; | ||||||
| import { autoStart } from "./autoStart"; | import { autoStart } from "./autoStart"; | ||||||
| import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; | import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; | ||||||
| import { mainWin } from "./mainWindow"; | import { loadUrl, mainWin } from "./mainWindow"; | ||||||
| import { Settings, State } from "./settings"; | import { Settings, State } from "./settings"; | ||||||
| import { handle, handleSync } from "./utils/ipcWrappers"; | import { handle, handleSync } from "./utils/ipcWrappers"; | ||||||
| import { PopoutWindows } from "./utils/popout"; | import { PopoutWindows } from "./utils/popout"; | ||||||
|  | @ -135,6 +135,11 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | handle(IpcEvents.FOUROHFOUR_PAGE_HANDLER, _ => { | ||||||
|  |     loadUrl(undefined); | ||||||
|  |     console.warn("caught incomplete uri scheme. dumping to main app"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| function readCss() { | function readCss() { | ||||||
|     return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => ""); |     return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => ""); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -455,25 +455,26 @@ function createMainWindow() { | ||||||
| 
 | 
 | ||||||
|     win.webContents.setUserAgent(BrowserUserAgent); |     win.webContents.setUserAgent(BrowserUserAgent); | ||||||
| 
 | 
 | ||||||
|     const branch = Settings.store.discordBranch; |  | ||||||
|     const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : ""; |  | ||||||
|     const uri = process.argv.find(arg => arg.startsWith("discord://")); |  | ||||||
| 
 |  | ||||||
|     const loadUrl = (url: string | undefined) => { |  | ||||||
|         win.loadURL(`https://${subdomain}discord.com/${url?.replace(RegExp("^discord://[^/]*/?"), "") || "app"}`); |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     let uriFiredDarwin = false; |     let uriFiredDarwin = false; | ||||||
|     app.on("open-url", (_, url) => { |     app.on("open-url", (_, url) => { | ||||||
|         uriFiredDarwin ? restoreVesktop() : loadUrl(url); |         uriFiredDarwin ? restoreVesktop() : loadUrl(url); | ||||||
|         uriFiredDarwin = true; |         uriFiredDarwin = true; | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     const uri = process.argv.find(arg => arg.startsWith("discord://")); | ||||||
|     uriFiredDarwin || loadUrl(uri); |     uriFiredDarwin || loadUrl(uri); | ||||||
|  | 
 | ||||||
|     return win; |     return win; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))); | const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))); | ||||||
| 
 | 
 | ||||||
|  | export function loadUrl(uri: string | undefined) { | ||||||
|  |     const branch = Settings.store.discordBranch; | ||||||
|  |     const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : ""; | ||||||
|  |     mainWin.loadURL(`https://${subdomain}discord.com/${uri?.replace(RegExp("^discord://[^/]*/?"), "") || "app"}`); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function restoreVesktop() { | export function restoreVesktop() { | ||||||
|     if (mainWin) { |     if (mainWin) { | ||||||
|         if (mainWin.isMinimized()) mainWin.restore(); |         if (mainWin.isMinimized()) mainWin.restore(); | ||||||
|  |  | ||||||
|  | @ -24,6 +24,10 @@ const style = document.createElement("style"); | ||||||
| style.id = "vcd-css-core"; | style.id = "vcd-css-core"; | ||||||
| style.textContent = readFileSync(rendererCss, "utf-8"); | style.textContent = readFileSync(rendererCss, "utf-8"); | ||||||
| 
 | 
 | ||||||
|  | document.addEventListener("DOMContentLoaded", () => { | ||||||
|  |     if (document.title === "Page Not Found | Discord") ipcRenderer.invoke(IpcEvents.FOUROHFOUR_PAGE_HANDLER); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| if (document.readyState === "complete") { | if (document.readyState === "complete") { | ||||||
|     document.documentElement.appendChild(style); |     document.documentElement.appendChild(style); | ||||||
| } else { | } else { | ||||||
|  |  | ||||||
|  | @ -50,5 +50,7 @@ export const enum IpcEvents { | ||||||
| 
 | 
 | ||||||
|     ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", |     ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", | ||||||
| 
 | 
 | ||||||
|     CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE" |     CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE", | ||||||
|  | 
 | ||||||
|  |     FOUROHFOUR_PAGE_HANDLER = "VCD_404_PAGE_HANDLER" | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Kylie C
						Kylie C