Merge 59e51d3f8a
into 5d675efb64
This commit is contained in:
commit
98b9f9e020
3 changed files with 42 additions and 12 deletions
|
@ -71,6 +71,12 @@
|
||||||
"package.json",
|
"package.json",
|
||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
|
"protocols": {
|
||||||
|
"name": "Discord",
|
||||||
|
"schemes": [
|
||||||
|
"discord"
|
||||||
|
]
|
||||||
|
},
|
||||||
"beforePack": "scripts/build/sandboxFix.js",
|
"beforePack": "scripts/build/sandboxFix.js",
|
||||||
"linux": {
|
"linux": {
|
||||||
"icon": "build/icon.icns",
|
"icon": "build/icon.icns",
|
||||||
|
@ -111,7 +117,8 @@
|
||||||
"GenericName": "Internet Messenger",
|
"GenericName": "Internet Messenger",
|
||||||
"Type": "Application",
|
"Type": "Application",
|
||||||
"Categories": "Network;InstantMessaging;Chat;",
|
"Categories": "Network;InstantMessaging;Chat;",
|
||||||
"Keywords": "discord;vencord;electron;chat;"
|
"Keywords": "discord;vencord;electron;chat;",
|
||||||
|
"MimeType": "x-scheme-handler/discord"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mac": {
|
"mac": {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { autoUpdater } from "electron-updater";
|
||||||
|
|
||||||
import { DATA_DIR } from "./constants";
|
import { DATA_DIR } from "./constants";
|
||||||
import { createFirstLaunchTour } from "./firstLaunch";
|
import { createFirstLaunchTour } from "./firstLaunch";
|
||||||
import { createWindows, mainWin } from "./mainWindow";
|
import { createWindows, restoreVesktop } from "./mainWindow";
|
||||||
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
||||||
import { registerScreenShareHandler } from "./screenShare";
|
import { registerScreenShareHandler } from "./screenShare";
|
||||||
import { Settings, State } from "./settings";
|
import { Settings, State } from "./settings";
|
||||||
|
@ -27,6 +27,8 @@ if (IS_DEV) {
|
||||||
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
|
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
app.setAsDefaultProtocolClient("discord");
|
||||||
|
|
||||||
const { disableSmoothScroll, hardwareAcceleration } = Settings.store;
|
const { disableSmoothScroll, hardwareAcceleration } = Settings.store;
|
||||||
|
|
||||||
const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(",");
|
const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(",");
|
||||||
|
@ -71,11 +73,7 @@ function init() {
|
||||||
|
|
||||||
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
||||||
if (data.IS_DEV) app.quit();
|
if (data.IS_DEV) app.quit();
|
||||||
else if (mainWin) {
|
else restoreVesktop();
|
||||||
if (mainWin.isMinimized()) mainWin.restore();
|
|
||||||
if (!mainWin.isVisible()) mainWin.show();
|
|
||||||
mainWin.focus();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
|
|
@ -455,18 +455,35 @@ function createMainWindow() {
|
||||||
|
|
||||||
win.webContents.setUserAgent(BrowserUserAgent);
|
win.webContents.setUserAgent(BrowserUserAgent);
|
||||||
|
|
||||||
const subdomain =
|
let uriFiredDarwin = false;
|
||||||
Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb"
|
app.on("open-url", (_, url) => {
|
||||||
? `${Settings.store.discordBranch}.`
|
if (uriFiredDarwin) restoreVesktop();
|
||||||
: "";
|
else loadUrl(url);
|
||||||
|
uriFiredDarwin = true;
|
||||||
|
});
|
||||||
|
|
||||||
win.loadURL(`https://${subdomain}discord.com/app`);
|
const uri = process.argv.find(arg => arg.startsWith("discord://"));
|
||||||
|
if (!uriFiredDarwin) loadUrl(uri);
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
||||||
|
|
||||||
|
function loadUrl(uri: string | undefined) {
|
||||||
|
const branch = Settings.store.discordBranch;
|
||||||
|
const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
|
||||||
|
mainWin.loadURL(`https://${subdomain}discord.com/${uri ? new URL(uri).pathname.slice(1) || "app" : "app"}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function restoreVesktop() {
|
||||||
|
if (mainWin) {
|
||||||
|
if (mainWin.isMinimized()) mainWin.restore();
|
||||||
|
if (!mainWin.isVisible()) mainWin.show();
|
||||||
|
mainWin.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function createWindows() {
|
export async function createWindows() {
|
||||||
const startMinimized = process.argv.includes("--start-minimized");
|
const startMinimized = process.argv.includes("--start-minimized");
|
||||||
const splash = createSplashWindow(startMinimized);
|
const splash = createSplashWindow(startMinimized);
|
||||||
|
@ -499,6 +516,14 @@ export async function createWindows() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mainWin.webContents.on("did-navigate", (_, url: string, responseCode: number) => {
|
||||||
|
// check url to ensure app doesn't loop
|
||||||
|
if (new URL(url).pathname !== `/app` && responseCode >= 300) {
|
||||||
|
loadUrl(undefined);
|
||||||
|
console.warn(`Caught bad page response: ${responseCode}, dumping to main app`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// evil hack to fix electron 32 regression that makes devtools always light theme
|
// evil hack to fix electron 32 regression that makes devtools always light theme
|
||||||
// https://github.com/electron/electron/issues/43367
|
// https://github.com/electron/electron/issues/43367
|
||||||
// TODO: remove once fixed
|
// TODO: remove once fixed
|
||||||
|
|
Reference in a new issue