forked from mirror/Vesktop
Add about page & setting to open links with electron
This commit is contained in:
parent
17150503d2
commit
1980606e03
6 changed files with 93 additions and 32 deletions
18
src/main/about.ts
Normal file
18
src/main/about.ts
Normal 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;
|
||||||
|
}
|
|
@ -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 { join } from "path";
|
||||||
import { ICON_PATH } from "../shared/paths";
|
import { ICON_PATH } from "../shared/paths";
|
||||||
|
import { createAboutWindow } from "./about";
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
|
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||||
import { downloadVencordFiles } from "./utils/vencordLoader";
|
import { downloadVencordFiles } from "./utils/vencordLoader";
|
||||||
|
|
||||||
let isQuitting = false;
|
let isQuitting = false;
|
||||||
|
@ -12,33 +14,6 @@ app.on("before-quit", () => {
|
||||||
|
|
||||||
export let mainWin: BrowserWindow;
|
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) {
|
function initTray(win: BrowserWindow) {
|
||||||
const trayMenu = Menu.buildFromTemplate([
|
const trayMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
|
@ -79,7 +54,7 @@ function initMenuBar(win: BrowserWindow) {
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: "About Vencord Desktop",
|
label: "About Vencord Desktop",
|
||||||
role: "about"
|
click: createAboutWindow
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Force Update Vencord",
|
label: "Force Update Vencord",
|
||||||
|
@ -241,7 +216,7 @@ export function createMainWindow() {
|
||||||
initWindowBoundsListeners(win);
|
initWindowBoundsListeners(win);
|
||||||
initTray(win);
|
initTray(win);
|
||||||
initMenuBar(win);
|
initMenuBar(win);
|
||||||
initWindowOpenHandler(win);
|
makeLinksOpenExternally(win);
|
||||||
|
|
||||||
const subdomain = Settings.discordBranch === "canary" || Settings.discordBranch === "ptb"
|
const subdomain = Settings.discordBranch === "canary" || Settings.discordBranch === "ptb"
|
||||||
? `${Settings.discordBranch}.`
|
? `${Settings.discordBranch}.`
|
||||||
|
|
|
@ -13,7 +13,8 @@ interface Settings {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
discordBranch: "stable" | "canary" | "ptb";
|
discordBranch?: "stable" | "canary" | "ptb";
|
||||||
|
openLinksWithElectron?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let PlainSettings = {} as Settings;
|
export let PlainSettings = {} as Settings;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { BrowserWindow } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import { STATIC_DIR } from "shared/paths";
|
||||||
|
|
||||||
export function createSplashWindow() {
|
export function createSplashWindow() {
|
||||||
const splash = new BrowserWindow({
|
const splash = new BrowserWindow({
|
||||||
|
@ -12,7 +13,7 @@ export function createSplashWindow() {
|
||||||
maximizable: false
|
maximizable: false
|
||||||
});
|
});
|
||||||
|
|
||||||
splash.loadFile(join(__dirname, "..", "..", "static", "splash.html"));
|
splash.loadFile(join(STATIC_DIR, "splash.html"));
|
||||||
|
|
||||||
return splash;
|
return splash;
|
||||||
}
|
}
|
||||||
|
|
32
src/main/utils/makeLinksOpenExternally.ts
Normal file
32
src/main/utils/makeLinksOpenExternally.ts
Normal 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
34
static/about.html
Normal 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>
|
Loading…
Add table
Reference in a new issue