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
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
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" };
});
}

34
static/about.html Normal file
View file

@ -0,0 +1,34 @@
<head>
<style>
body {
padding: 2em;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
"Open Sans", "Helvetica Neue", sans-serif;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>About Vencord Desktop</h1>
<p>
Vencord Desktop is a free/libre cross platform desktop app aiming to give you a snappier Discord experience with
Vencord pre-installed
</p>
<h2>Links</h2>
<ul>
<li>
<a href="https://vencord.dev">Vencord Website</a>
</li>
<li>
<a href="https://github.com/Vencord/Desktop" target="_blank">Source Code</a>
</li>
<li>
<a href="https://github.com/Vencord/Desktop/issues" target="_blank">Report bugs / Request features</a>
</li>
</ul>
</body>