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",
|
||||
"LICENSE"
|
||||
],
|
||||
"protocols": {
|
||||
"name": "Discord",
|
||||
"schemes": [
|
||||
"discord"
|
||||
]
|
||||
},
|
||||
"beforePack": "scripts/build/sandboxFix.js",
|
||||
"linux": {
|
||||
"icon": "build/icon.icns",
|
||||
|
@ -111,7 +117,8 @@
|
|||
"GenericName": "Internet Messenger",
|
||||
"Type": "Application",
|
||||
"Categories": "Network;InstantMessaging;Chat;",
|
||||
"Keywords": "discord;vencord;electron;chat;"
|
||||
"Keywords": "discord;vencord;electron;chat;",
|
||||
"MimeType": "x-scheme-handler/discord"
|
||||
}
|
||||
},
|
||||
"mac": {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { autoUpdater } from "electron-updater";
|
|||
|
||||
import { DATA_DIR } from "./constants";
|
||||
import { createFirstLaunchTour } from "./firstLaunch";
|
||||
import { createWindows, mainWin } from "./mainWindow";
|
||||
import { createWindows, restoreVesktop } from "./mainWindow";
|
||||
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
||||
import { registerScreenShareHandler } from "./screenShare";
|
||||
import { Settings, State } from "./settings";
|
||||
|
@ -27,6 +27,8 @@ if (IS_DEV) {
|
|||
process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
|
||||
|
||||
function init() {
|
||||
app.setAsDefaultProtocolClient("discord");
|
||||
|
||||
const { disableSmoothScroll, hardwareAcceleration } = Settings.store;
|
||||
|
||||
const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(",");
|
||||
|
@ -71,11 +73,7 @@ function init() {
|
|||
|
||||
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
||||
if (data.IS_DEV) app.quit();
|
||||
else if (mainWin) {
|
||||
if (mainWin.isMinimized()) mainWin.restore();
|
||||
if (!mainWin.isVisible()) mainWin.show();
|
||||
mainWin.focus();
|
||||
}
|
||||
else restoreVesktop();
|
||||
});
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
|
|
|
@ -455,18 +455,35 @@ function createMainWindow() {
|
|||
|
||||
win.webContents.setUserAgent(BrowserUserAgent);
|
||||
|
||||
const subdomain =
|
||||
Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb"
|
||||
? `${Settings.store.discordBranch}.`
|
||||
: "";
|
||||
let uriFiredDarwin = false;
|
||||
app.on("open-url", (_, url) => {
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
const startMinimized = process.argv.includes("--start-minimized");
|
||||
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
|
||||
// https://github.com/electron/electron/issues/43367
|
||||
// TODO: remove once fixed
|
||||
|
|
Reference in a new issue