From 1980606e03731a7c1d20bcf1f54dfa5fb6471236 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 5 Apr 2023 17:55:49 +0200 Subject: [PATCH] Add about page & setting to open links with electron --- src/main/about.ts | 18 ++++++++++++ src/main/mainWindow.ts | 35 ++++------------------- src/main/settings.ts | 3 +- src/main/splash.ts | 3 +- src/main/utils/makeLinksOpenExternally.ts | 32 +++++++++++++++++++++ static/about.html | 34 ++++++++++++++++++++++ 6 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 src/main/about.ts create mode 100644 src/main/utils/makeLinksOpenExternally.ts create mode 100644 static/about.html diff --git a/src/main/about.ts b/src/main/about.ts new file mode 100644 index 0000000..099eab4 --- /dev/null +++ b/src/main/about.ts @@ -0,0 +1,18 @@ +import { BrowserWindow } from "electron"; +import { join } from "path"; +import { ICON_PATH, STATIC_DIR } from "shared/paths"; +import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; + +export function createAboutWindow() { + const about = new BrowserWindow({ + center: true, + autoHideMenuBar: true, + icon: ICON_PATH + }); + + makeLinksOpenExternally(about); + + about.loadFile(join(STATIC_DIR, "about.html")); + + return about; +} diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index be86056..9077db7 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -1,7 +1,9 @@ -import { BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray, app, shell } from "electron"; +import { BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray, app } from "electron"; import { join } from "path"; import { ICON_PATH } from "../shared/paths"; +import { createAboutWindow } from "./about"; import { Settings } from "./settings"; +import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; import { downloadVencordFiles } from "./utils/vencordLoader"; let isQuitting = false; @@ -12,33 +14,6 @@ app.on("before-quit", () => { export let mainWin: BrowserWindow; -function initWindowOpenHandler(win: BrowserWindow) { - win.webContents.setWindowOpenHandler(({ url }) => { - switch (url) { - case "about:blank": - case "https://discord.com/popout": - return { action: "allow" }; - } - - try { - var protocol = new URL(url).protocol; - } catch { - return { action: "deny" }; - } - - switch (protocol) { - case "http:": - case "https:": - case "mailto:": - case "steam:": - case "spotify:": - shell.openExternal(url); - } - - return { action: "deny" }; - }); -} - function initTray(win: BrowserWindow) { const trayMenu = Menu.buildFromTemplate([ { @@ -79,7 +54,7 @@ function initMenuBar(win: BrowserWindow) { submenu: [ { label: "About Vencord Desktop", - role: "about" + click: createAboutWindow }, { label: "Force Update Vencord", @@ -241,7 +216,7 @@ export function createMainWindow() { initWindowBoundsListeners(win); initTray(win); initMenuBar(win); - initWindowOpenHandler(win); + makeLinksOpenExternally(win); const subdomain = Settings.discordBranch === "canary" || Settings.discordBranch === "ptb" ? `${Settings.discordBranch}.` diff --git a/src/main/settings.ts b/src/main/settings.ts index 14ab407..e00e452 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -13,7 +13,8 @@ interface Settings { width: number; height: number; }; - discordBranch: "stable" | "canary" | "ptb"; + discordBranch?: "stable" | "canary" | "ptb"; + openLinksWithElectron?: boolean; } export let PlainSettings = {} as Settings; diff --git a/src/main/splash.ts b/src/main/splash.ts index ad4502a..d426b52 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -1,5 +1,6 @@ import { BrowserWindow } from "electron"; import { join } from "path"; +import { STATIC_DIR } from "shared/paths"; export function createSplashWindow() { const splash = new BrowserWindow({ @@ -12,7 +13,7 @@ export function createSplashWindow() { maximizable: false }); - splash.loadFile(join(__dirname, "..", "..", "static", "splash.html")); + splash.loadFile(join(STATIC_DIR, "splash.html")); return splash; } diff --git a/src/main/utils/makeLinksOpenExternally.ts b/src/main/utils/makeLinksOpenExternally.ts new file mode 100644 index 0000000..bfd83b2 --- /dev/null +++ b/src/main/utils/makeLinksOpenExternally.ts @@ -0,0 +1,32 @@ +import { BrowserWindow, shell } from "electron"; +import { Settings } from "../settings"; + +export function makeLinksOpenExternally(win: BrowserWindow) { + win.webContents.setWindowOpenHandler(({ url }) => { + switch (url) { + case "about:blank": + case "https://discord.com/popout": + return { action: "allow" }; + } + + try { + var protocol = new URL(url).protocol; + } catch { + return { action: "deny" }; + } + + switch (protocol) { + case "http:": + case "https:": + if (Settings.openLinksWithElectron) { + return { action: "allow" }; + } + case "mailto:": + case "steam:": + case "spotify:": + shell.openExternal(url); + } + + return { action: "deny" }; + }); +} diff --git a/static/about.html b/static/about.html new file mode 100644 index 0000000..5e1d694 --- /dev/null +++ b/static/about.html @@ -0,0 +1,34 @@ + + + + + +

About Vencord Desktop

+

+ Vencord Desktop is a free/libre cross platform desktop app aiming to give you a snappier Discord experience with + Vencord pre-installed +

+ +

Links

+ +