Add about page & setting to open links with electron

This commit is contained in:
Vendicated
2023-04-05 17:55:49 +02:00
parent 17150503d2
commit 1980606e03
6 changed files with 93 additions and 32 deletions

18
src/main/about.ts Normal file
View File

@@ -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;
}

View File

@@ -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}.`

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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" };
});
}