mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 13:45:09 +00:00
Make URLs open in browser instead of a new Electron window
This commit is contained in:
parent
1c20f35460
commit
d7020a8501
1 changed files with 55 additions and 23 deletions
|
@ -1,22 +1,41 @@
|
||||||
import { BrowserWindow, Menu, Tray, app } from "electron";
|
import { BrowserWindow, Menu, Tray, app, shell } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { ICON_PATH } from "../shared/paths";
|
import { ICON_PATH } from "../shared/paths";
|
||||||
|
|
||||||
export function createMainWindow() {
|
|
||||||
let isQuitting = false;
|
let isQuitting = false;
|
||||||
|
|
||||||
const win = new BrowserWindow({
|
app.on("before-quit", () => {
|
||||||
show: false,
|
isQuitting = true;
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: false,
|
|
||||||
sandbox: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
devTools: true,
|
|
||||||
preload: join(__dirname, "preload.js")
|
|
||||||
},
|
|
||||||
icon: ICON_PATH
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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([
|
const trayMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: "Open",
|
label: "Open",
|
||||||
|
@ -39,8 +58,27 @@ export function createMainWindow() {
|
||||||
tray.setContextMenu(trayMenu);
|
tray.setContextMenu(trayMenu);
|
||||||
tray.on("click", () => win.show());
|
tray.on("click", () => win.show());
|
||||||
|
|
||||||
app.on("before-quit", () => {
|
win.on("show", () => {
|
||||||
isQuitting = true;
|
trayMenu.items[0].enabled = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
win.on("hide", () => {
|
||||||
|
trayMenu.items[0].enabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMainWindow() {
|
||||||
|
const win = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: false,
|
||||||
|
sandbox: false,
|
||||||
|
contextIsolation: true,
|
||||||
|
devTools: true,
|
||||||
|
preload: join(__dirname, "preload.js")
|
||||||
|
},
|
||||||
|
icon: ICON_PATH
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on("close", e => {
|
win.on("close", e => {
|
||||||
|
@ -52,14 +90,8 @@ export function createMainWindow() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on("show", () => {
|
initTray(win);
|
||||||
trayMenu.items[0].enabled = false;
|
initWindowOpenHandler(win);
|
||||||
});
|
|
||||||
|
|
||||||
win.on("hide", () => {
|
|
||||||
trayMenu.items[0].enabled = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
win.loadURL("https://discord.com/app");
|
win.loadURL("https://discord.com/app");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue