2023-04-10 05:49:50 +09:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
2023-07-14 02:03:13 +09:00
|
|
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
2023-04-10 05:49:50 +09:00
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
*/
|
|
|
|
|
2023-07-14 09:14:48 +09:00
|
|
|
import {
|
|
|
|
app,
|
|
|
|
BrowserWindow,
|
|
|
|
BrowserWindowConstructorOptions,
|
|
|
|
dialog,
|
|
|
|
Menu,
|
|
|
|
MenuItemConstructorOptions,
|
2023-10-14 12:04:44 +09:00
|
|
|
nativeTheme,
|
2024-05-11 04:04:16 +09:00
|
|
|
screen,
|
2024-05-24 00:30:40 +09:00
|
|
|
session,
|
2023-07-14 09:14:48 +09:00
|
|
|
Tray
|
|
|
|
} from "electron";
|
|
|
|
import { rm } from "fs/promises";
|
2023-03-30 08:02:30 +09:00
|
|
|
import { join } from "path";
|
2023-06-25 10:44:19 +09:00
|
|
|
import { IpcEvents } from "shared/IpcEvents";
|
2023-07-12 04:35:15 +09:00
|
|
|
import { isTruthy } from "shared/utils/guards";
|
2023-06-21 21:39:41 +09:00
|
|
|
import { once } from "shared/utils/once";
|
2023-06-25 23:48:26 +09:00
|
|
|
import type { SettingsStore } from "shared/utils/SettingsStore";
|
2023-04-10 05:49:50 +09:00
|
|
|
|
2023-04-04 08:35:37 +09:00
|
|
|
import { ICON_PATH } from "../shared/paths";
|
2023-04-06 00:55:49 +09:00
|
|
|
import { createAboutWindow } from "./about";
|
2023-06-21 21:39:41 +09:00
|
|
|
import { initArRPC } from "./arrpc";
|
2023-10-27 04:39:21 +09:00
|
|
|
import {
|
2024-03-12 09:33:50 +09:00
|
|
|
BrowserUserAgent,
|
2023-10-27 04:39:21 +09:00
|
|
|
DATA_DIR,
|
|
|
|
DEFAULT_HEIGHT,
|
|
|
|
DEFAULT_WIDTH,
|
2023-11-01 06:14:30 +09:00
|
|
|
MessageBoxChoice,
|
2023-10-27 04:39:21 +09:00
|
|
|
MIN_HEIGHT,
|
|
|
|
MIN_WIDTH,
|
|
|
|
VENCORD_FILES_DIR
|
|
|
|
} from "./constants";
|
2024-01-07 10:26:18 +09:00
|
|
|
import { Settings, State, VencordSettings } from "./settings";
|
2023-06-21 21:39:41 +09:00
|
|
|
import { createSplashWindow } from "./splash";
|
2023-04-06 00:55:49 +09:00
|
|
|
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
2023-11-01 06:14:30 +09:00
|
|
|
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
2023-06-21 21:39:41 +09:00
|
|
|
import { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader";
|
2023-03-30 08:02:30 +09:00
|
|
|
|
2023-04-04 08:47:33 +09:00
|
|
|
let isQuitting = false;
|
2023-04-11 02:12:58 +09:00
|
|
|
let tray: Tray;
|
2023-04-04 07:41:52 +09:00
|
|
|
|
2023-11-01 06:14:30 +09:00
|
|
|
applyDeckKeyboardFix();
|
|
|
|
|
2023-04-04 08:47:33 +09:00
|
|
|
app.on("before-quit", () => {
|
|
|
|
isQuitting = true;
|
|
|
|
});
|
|
|
|
|
2023-04-05 12:19:48 +09:00
|
|
|
export let mainWin: BrowserWindow;
|
|
|
|
|
2023-06-25 23:48:26 +09:00
|
|
|
function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
|
|
|
|
const listeners = new Map<(data: any) => void, PropertyKey>();
|
|
|
|
|
|
|
|
const addListener: typeof o.addChangeListener = (path, cb) => {
|
|
|
|
listeners.set(cb, path);
|
|
|
|
o.addChangeListener(path, cb);
|
|
|
|
};
|
2023-06-26 07:05:08 +09:00
|
|
|
const removeAllListeners = () => {
|
2023-06-25 23:48:26 +09:00
|
|
|
for (const [listener, path] of listeners) {
|
|
|
|
o.removeChangeListener(path as any, listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
listeners.clear();
|
|
|
|
};
|
|
|
|
|
2023-06-26 07:05:08 +09:00
|
|
|
return [addListener, removeAllListeners] as const;
|
2023-06-25 23:48:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const [addSettingsListener, removeSettingsListeners] = makeSettingsListenerHelpers(Settings);
|
|
|
|
const [addVencordSettingsListener, removeVencordSettingsListeners] = makeSettingsListenerHelpers(VencordSettings);
|
|
|
|
|
2023-04-04 08:47:33 +09:00
|
|
|
function initTray(win: BrowserWindow) {
|
2024-04-09 11:23:34 +09:00
|
|
|
const onTrayClick = () => {
|
|
|
|
if (Settings.store.clickTrayToShowHide && win.isVisible()) win.hide();
|
|
|
|
else win.show();
|
|
|
|
};
|
2023-04-04 08:35:37 +09:00
|
|
|
const trayMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: "Open",
|
|
|
|
click() {
|
|
|
|
win.show();
|
2024-01-16 09:22:10 +09:00
|
|
|
}
|
2023-04-04 08:35:37 +09:00
|
|
|
},
|
2023-04-06 07:08:28 +09:00
|
|
|
{
|
|
|
|
label: "About",
|
|
|
|
click: createAboutWindow
|
|
|
|
},
|
|
|
|
{
|
2024-07-05 01:51:18 +09:00
|
|
|
label: "Repair Vencord",
|
2023-04-06 07:08:28 +09:00
|
|
|
async click() {
|
|
|
|
await downloadVencordFiles();
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
},
|
2023-07-14 09:14:48 +09:00
|
|
|
{
|
|
|
|
label: "Reset Vesktop",
|
|
|
|
async click() {
|
|
|
|
await clearData(win);
|
|
|
|
}
|
|
|
|
},
|
2023-04-06 10:52:06 +09:00
|
|
|
{
|
|
|
|
type: "separator"
|
|
|
|
},
|
2023-04-06 07:08:28 +09:00
|
|
|
{
|
2024-07-05 01:51:18 +09:00
|
|
|
label: "Restart",
|
2023-04-06 07:08:28 +09:00
|
|
|
click() {
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
},
|
2023-04-04 08:35:37 +09:00
|
|
|
{
|
2024-07-05 01:51:18 +09:00
|
|
|
label: "Quit",
|
2023-04-04 08:35:37 +09:00
|
|
|
click() {
|
|
|
|
isQuitting = true;
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2023-04-11 02:12:58 +09:00
|
|
|
tray = new Tray(ICON_PATH);
|
2023-07-14 02:03:13 +09:00
|
|
|
tray.setToolTip("Vesktop");
|
2023-04-04 08:35:37 +09:00
|
|
|
tray.setContextMenu(trayMenu);
|
2024-04-09 11:23:34 +09:00
|
|
|
tray.on("click", onTrayClick);
|
2023-04-04 08:47:33 +09:00
|
|
|
}
|
|
|
|
|
2023-07-14 09:14:48 +09:00
|
|
|
async function clearData(win: BrowserWindow) {
|
|
|
|
const { response } = await dialog.showMessageBox(win, {
|
|
|
|
message: "Are you sure you want to reset Vesktop?",
|
|
|
|
detail: "This will log you out, clear caches and reset all your settings!\n\nVesktop will automatically restart after this operation.",
|
|
|
|
buttons: ["Yes", "No"],
|
|
|
|
cancelId: MessageBoxChoice.Cancel,
|
|
|
|
defaultId: MessageBoxChoice.Default,
|
|
|
|
type: "warning"
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response === MessageBoxChoice.Cancel) return;
|
|
|
|
|
|
|
|
win.close();
|
|
|
|
|
|
|
|
await win.webContents.session.clearStorageData();
|
|
|
|
await win.webContents.session.clearCache();
|
|
|
|
await win.webContents.session.clearCodeCaches({});
|
|
|
|
await rm(DATA_DIR, { force: true, recursive: true });
|
|
|
|
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
|
2023-10-01 05:43:27 +09:00
|
|
|
type MenuItemList = Array<MenuItemConstructorOptions | false>;
|
|
|
|
|
2023-04-06 00:25:29 +09:00
|
|
|
function initMenuBar(win: BrowserWindow) {
|
2023-04-09 12:25:45 +09:00
|
|
|
const isWindows = process.platform === "win32";
|
2023-07-12 04:35:15 +09:00
|
|
|
const isDarwin = process.platform === "darwin";
|
2023-04-10 08:04:41 +09:00
|
|
|
const wantCtrlQ = !isWindows || VencordSettings.store.winCtrlQ;
|
2023-04-09 12:25:45 +09:00
|
|
|
|
2023-07-12 04:35:15 +09:00
|
|
|
const subMenu = [
|
|
|
|
{
|
2023-07-14 02:03:13 +09:00
|
|
|
label: "About Vesktop",
|
2023-07-12 04:35:15 +09:00
|
|
|
click: createAboutWindow
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Force Update Vencord",
|
|
|
|
async click() {
|
|
|
|
await downloadVencordFiles();
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
},
|
2023-07-14 02:03:13 +09:00
|
|
|
toolTip: "Vesktop will automatically restart after this operation"
|
2023-07-12 04:35:15 +09:00
|
|
|
},
|
2023-07-14 09:14:48 +09:00
|
|
|
{
|
|
|
|
label: "Reset Vesktop",
|
|
|
|
async click() {
|
|
|
|
await clearData(win);
|
|
|
|
},
|
|
|
|
toolTip: "Vesktop will automatically restart after this operation"
|
|
|
|
},
|
2023-07-12 04:35:15 +09:00
|
|
|
{
|
|
|
|
label: "Relaunch",
|
|
|
|
accelerator: "CmdOrCtrl+Shift+R",
|
|
|
|
click() {
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
},
|
2023-10-01 05:43:27 +09:00
|
|
|
...(!isDarwin
|
|
|
|
? []
|
|
|
|
: ([
|
|
|
|
{
|
|
|
|
type: "separator"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Settings",
|
|
|
|
accelerator: "CmdOrCtrl+,",
|
|
|
|
async click() {
|
|
|
|
mainWin.webContents.executeJavaScript(
|
|
|
|
"Vencord.Webpack.Common.SettingsRouter.open('My Account')"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "hide"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "hideOthers"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: "unhide"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator"
|
|
|
|
}
|
|
|
|
] satisfies MenuItemList)),
|
2023-07-12 04:35:15 +09:00
|
|
|
{
|
|
|
|
label: "Quit",
|
|
|
|
accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0,
|
|
|
|
visible: !isWindows,
|
|
|
|
role: "quit",
|
|
|
|
click() {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
},
|
2023-07-14 02:07:19 +09:00
|
|
|
isWindows && {
|
2023-07-12 04:35:15 +09:00
|
|
|
label: "Quit",
|
2023-07-14 02:07:19 +09:00
|
|
|
accelerator: "Alt+F4",
|
2023-07-12 04:35:15 +09:00
|
|
|
role: "quit",
|
|
|
|
click() {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256
|
|
|
|
{
|
|
|
|
label: "Zoom in (hidden, hack for Qwertz and others)",
|
|
|
|
accelerator: "CmdOrCtrl+=",
|
|
|
|
role: "zoomIn",
|
|
|
|
visible: false
|
|
|
|
}
|
2023-10-01 05:43:27 +09:00
|
|
|
] satisfies MenuItemList;
|
2023-07-12 04:35:15 +09:00
|
|
|
|
2023-04-06 00:25:29 +09:00
|
|
|
const menu = Menu.buildFromTemplate([
|
|
|
|
{
|
2023-07-14 02:03:13 +09:00
|
|
|
label: "Vesktop",
|
2023-04-15 19:37:52 +09:00
|
|
|
role: "appMenu",
|
2023-07-12 04:35:15 +09:00
|
|
|
submenu: subMenu.filter(isTruthy)
|
2023-04-06 00:25:29 +09:00
|
|
|
},
|
2023-04-15 19:37:52 +09:00
|
|
|
{ role: "fileMenu" },
|
|
|
|
{ role: "editMenu" },
|
|
|
|
{ role: "viewMenu" },
|
2023-04-27 09:23:17 +09:00
|
|
|
{ role: "windowMenu" }
|
2023-04-06 00:25:29 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(menu);
|
|
|
|
}
|
|
|
|
|
2023-04-09 12:04:49 +09:00
|
|
|
function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
|
2023-11-01 06:14:30 +09:00
|
|
|
// We want the default window behaivour to apply in game mode since it expects everything to be fullscreen and maximized.
|
|
|
|
if (isDeckGameMode) return {};
|
|
|
|
|
2024-01-07 10:26:18 +09:00
|
|
|
const { x, y, width, height } = State.store.windowBounds ?? {};
|
2023-04-09 12:04:49 +09:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
width: width ?? DEFAULT_WIDTH,
|
|
|
|
height: height ?? DEFAULT_HEIGHT
|
|
|
|
} as BrowserWindowConstructorOptions;
|
|
|
|
|
2024-05-11 04:04:16 +09:00
|
|
|
const storedDisplay = screen.getAllDisplays().find(display => display.id === State.store.displayid);
|
|
|
|
|
|
|
|
if (x != null && y != null && storedDisplay) {
|
2023-04-04 11:17:38 +09:00
|
|
|
options.x = x;
|
|
|
|
options.y = y;
|
|
|
|
}
|
|
|
|
|
2023-04-10 08:04:41 +09:00
|
|
|
if (!Settings.store.disableMinSize) {
|
2023-04-09 12:04:49 +09:00
|
|
|
options.minWidth = MIN_WIDTH;
|
|
|
|
options.minHeight = MIN_HEIGHT;
|
|
|
|
}
|
2023-04-04 11:17:38 +09:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2023-10-25 07:24:37 +09:00
|
|
|
function getDarwinOptions(): BrowserWindowConstructorOptions {
|
|
|
|
const options = {
|
2023-10-31 02:35:24 +09:00
|
|
|
titleBarStyle: "hidden",
|
|
|
|
trafficLightPosition: { x: 10, y: 10 }
|
2023-10-25 07:24:37 +09:00
|
|
|
} as BrowserWindowConstructorOptions;
|
|
|
|
|
|
|
|
const { splashTheming, splashBackground } = Settings.store;
|
|
|
|
const { macosTranslucency } = VencordSettings.store;
|
|
|
|
|
|
|
|
if (macosTranslucency) {
|
|
|
|
options.vibrancy = "sidebar";
|
|
|
|
options.backgroundColor = "#ffffff00";
|
|
|
|
} else {
|
|
|
|
if (splashTheming) {
|
|
|
|
options.backgroundColor = splashBackground;
|
|
|
|
} else {
|
|
|
|
options.backgroundColor = nativeTheme.shouldUseDarkColors ? "#313338" : "#ffffff";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2023-04-04 11:17:38 +09:00
|
|
|
function initWindowBoundsListeners(win: BrowserWindow) {
|
2023-04-09 12:04:49 +09:00
|
|
|
const saveState = () => {
|
2024-01-07 10:26:18 +09:00
|
|
|
State.store.maximized = win.isMaximized();
|
|
|
|
State.store.minimized = win.isMinimized();
|
2023-04-09 12:04:49 +09:00
|
|
|
};
|
2023-04-04 11:17:38 +09:00
|
|
|
|
2023-04-09 12:04:49 +09:00
|
|
|
win.on("maximize", saveState);
|
|
|
|
win.on("minimize", saveState);
|
|
|
|
win.on("unmaximize", saveState);
|
2023-04-04 11:17:38 +09:00
|
|
|
|
|
|
|
const saveBounds = () => {
|
2024-01-07 10:26:18 +09:00
|
|
|
State.store.windowBounds = win.getBounds();
|
2024-05-11 04:04:16 +09:00
|
|
|
State.store.displayid = screen.getDisplayMatching(State.store.windowBounds).id;
|
2023-04-04 11:17:38 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
win.on("resize", saveBounds);
|
|
|
|
win.on("move", saveBounds);
|
|
|
|
}
|
|
|
|
|
2023-04-10 08:43:47 +09:00
|
|
|
function initSettingsListeners(win: BrowserWindow) {
|
2023-06-25 23:48:26 +09:00
|
|
|
addSettingsListener("tray", enable => {
|
2023-04-11 02:18:00 +09:00
|
|
|
if (enable) initTray(win);
|
|
|
|
else tray?.destroy();
|
2023-04-11 02:12:58 +09:00
|
|
|
});
|
2023-06-25 23:48:26 +09:00
|
|
|
addSettingsListener("disableMinSize", disable => {
|
2023-04-10 08:55:48 +09:00
|
|
|
if (disable) {
|
|
|
|
// 0 no work
|
|
|
|
win.setMinimumSize(1, 1);
|
|
|
|
} else {
|
|
|
|
win.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
|
|
|
|
|
|
|
|
const { width, height } = win.getBounds();
|
|
|
|
win.setBounds({
|
|
|
|
width: Math.max(width, MIN_WIDTH),
|
|
|
|
height: Math.max(height, MIN_HEIGHT)
|
|
|
|
});
|
|
|
|
}
|
2023-04-10 08:43:47 +09:00
|
|
|
});
|
2023-04-11 02:21:45 +09:00
|
|
|
|
2023-06-25 23:48:26 +09:00
|
|
|
addVencordSettingsListener("macosTranslucency", enabled => {
|
2023-04-11 02:21:45 +09:00
|
|
|
if (enabled) {
|
|
|
|
win.setVibrancy("sidebar");
|
|
|
|
win.setBackgroundColor("#ffffff00");
|
|
|
|
} else {
|
|
|
|
win.setVibrancy(null);
|
|
|
|
win.setBackgroundColor("#ffffff");
|
|
|
|
}
|
|
|
|
});
|
2023-07-29 04:54:17 +09:00
|
|
|
|
|
|
|
addSettingsListener("enableMenu", enabled => {
|
|
|
|
win.setAutoHideMenuBar(enabled ?? false);
|
|
|
|
});
|
2024-05-24 00:30:40 +09:00
|
|
|
|
|
|
|
addSettingsListener("spellCheckLanguages", languages => initSpellCheckLanguages(win, languages));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function initSpellCheckLanguages(win: BrowserWindow, languages?: string[]) {
|
|
|
|
languages ??= await win.webContents.executeJavaScript("[...new Set(navigator.languages)]").catch(() => []);
|
|
|
|
if (!languages) return;
|
|
|
|
|
|
|
|
const ses = session.defaultSession;
|
|
|
|
|
|
|
|
const available = ses.availableSpellCheckerLanguages;
|
|
|
|
const applicable = languages.filter(l => available.includes(l)).slice(0, 5);
|
|
|
|
if (applicable.length) ses.setSpellCheckerLanguages(applicable);
|
2023-04-10 08:43:47 +09:00
|
|
|
}
|
|
|
|
|
2023-06-25 10:44:19 +09:00
|
|
|
function initSpellCheck(win: BrowserWindow) {
|
|
|
|
win.webContents.on("context-menu", (_, data) => {
|
|
|
|
win.webContents.send(IpcEvents.SPELLCHECK_RESULT, data.misspelledWord, data.dictionarySuggestions);
|
|
|
|
});
|
2024-05-24 00:30:40 +09:00
|
|
|
|
|
|
|
initSpellCheckLanguages(win, Settings.store.spellCheckLanguages);
|
2023-06-25 10:44:19 +09:00
|
|
|
}
|
|
|
|
|
2023-06-21 21:39:41 +09:00
|
|
|
function createMainWindow() {
|
2023-06-25 23:48:26 +09:00
|
|
|
// Clear up previous settings listeners
|
|
|
|
removeSettingsListeners();
|
|
|
|
removeVencordSettingsListeners();
|
|
|
|
|
2024-01-16 09:08:06 +09:00
|
|
|
const { staticTitle, transparencyOption, enableMenu, customTitleBar } = Settings.store;
|
2023-10-14 12:04:44 +09:00
|
|
|
|
2024-01-19 09:05:45 +09:00
|
|
|
const { frameless, transparent } = VencordSettings.store;
|
2023-08-07 07:23:27 +09:00
|
|
|
|
2024-01-16 09:08:06 +09:00
|
|
|
const noFrame = frameless === true || customTitleBar === true;
|
2023-08-07 07:23:27 +09:00
|
|
|
|
2023-04-10 05:49:50 +09:00
|
|
|
const win = (mainWin = new BrowserWindow({
|
2023-04-04 08:47:33 +09:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: false,
|
|
|
|
sandbox: false,
|
|
|
|
contextIsolation: true,
|
|
|
|
devTools: true,
|
2023-06-25 10:44:19 +09:00
|
|
|
preload: join(__dirname, "preload.js"),
|
2024-05-29 01:11:55 +09:00
|
|
|
spellcheck: true,
|
|
|
|
// disable renderer backgrounding to prevent the app from unloading when in the background
|
|
|
|
backgroundThrottling: false
|
2023-04-04 08:47:33 +09:00
|
|
|
},
|
2023-04-04 11:17:38 +09:00
|
|
|
icon: ICON_PATH,
|
2023-08-07 07:23:27 +09:00
|
|
|
frame: !noFrame,
|
2024-01-19 09:05:45 +09:00
|
|
|
...(transparent && {
|
|
|
|
transparent: true,
|
|
|
|
backgroundColor: "#00000000"
|
|
|
|
}),
|
2023-10-25 07:24:37 +09:00
|
|
|
...(transparencyOption &&
|
|
|
|
transparencyOption !== "none" && {
|
|
|
|
backgroundColor: "#00000000",
|
2024-01-07 09:59:29 +09:00
|
|
|
backgroundMaterial: transparencyOption
|
|
|
|
}),
|
|
|
|
// Fix transparencyOption for custom discord titlebar
|
2024-01-16 09:08:06 +09:00
|
|
|
...(customTitleBar &&
|
2024-01-07 09:59:29 +09:00
|
|
|
transparencyOption &&
|
|
|
|
transparencyOption !== "none" && {
|
2023-10-25 07:24:37 +09:00
|
|
|
transparent: true
|
|
|
|
}),
|
|
|
|
...(staticTitle && { title: "Vesktop" }),
|
|
|
|
...(process.platform === "darwin" && getDarwinOptions()),
|
2023-07-29 04:54:17 +09:00
|
|
|
...getWindowBoundsOptions(),
|
|
|
|
autoHideMenuBar: enableMenu
|
2023-04-10 05:49:50 +09:00
|
|
|
}));
|
2023-07-04 05:25:11 +09:00
|
|
|
win.setMenuBarVisibility(false);
|
2024-06-02 00:25:42 +09:00
|
|
|
if (process.platform === "darwin" && customTitleBar) win.setWindowButtonVisibility(false);
|
2023-04-04 07:41:52 +09:00
|
|
|
|
|
|
|
win.on("close", e => {
|
2023-11-01 06:14:30 +09:00
|
|
|
const useTray = !isDeckGameMode && Settings.store.minimizeToTray !== false && Settings.store.tray !== false;
|
2023-07-12 03:57:10 +09:00
|
|
|
if (isQuitting || (process.platform !== "darwin" && !useTray)) return;
|
2023-04-04 07:41:52 +09:00
|
|
|
|
|
|
|
e.preventDefault();
|
2023-07-12 03:57:10 +09:00
|
|
|
|
|
|
|
if (process.platform === "darwin") app.hide();
|
|
|
|
else win.hide();
|
2023-04-04 07:41:52 +09:00
|
|
|
|
|
|
|
return false;
|
2023-03-30 08:02:30 +09:00
|
|
|
});
|
|
|
|
|
2023-04-20 11:26:56 +09:00
|
|
|
if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
|
|
|
|
|
2023-04-04 11:17:38 +09:00
|
|
|
initWindowBoundsListeners(win);
|
2023-11-01 06:14:30 +09:00
|
|
|
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win);
|
2023-04-06 00:25:29 +09:00
|
|
|
initMenuBar(win);
|
2023-04-06 00:55:49 +09:00
|
|
|
makeLinksOpenExternally(win);
|
2023-04-10 08:43:47 +09:00
|
|
|
initSettingsListeners(win);
|
2023-06-25 10:44:19 +09:00
|
|
|
initSpellCheck(win);
|
2023-04-04 07:41:52 +09:00
|
|
|
|
2024-03-12 09:33:50 +09:00
|
|
|
win.webContents.setUserAgent(BrowserUserAgent);
|
2023-04-16 03:13:18 +09:00
|
|
|
|
2023-04-10 05:49:50 +09:00
|
|
|
const subdomain =
|
2023-04-10 08:04:41 +09:00
|
|
|
Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb"
|
|
|
|
? `${Settings.store.discordBranch}.`
|
|
|
|
: "";
|
2023-04-04 11:40:03 +09:00
|
|
|
|
|
|
|
win.loadURL(`https://${subdomain}discord.com/app`);
|
2023-03-30 08:02:30 +09:00
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
2023-06-21 21:39:41 +09:00
|
|
|
|
|
|
|
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
|
|
|
|
|
|
|
export async function createWindows() {
|
2024-01-07 11:11:00 +09:00
|
|
|
const startMinimized = process.argv.includes("--start-minimized");
|
|
|
|
const splash = createSplashWindow(startMinimized);
|
2023-11-01 06:14:30 +09:00
|
|
|
// SteamOS letterboxes and scales it terribly, so just full screen it
|
|
|
|
if (isDeckGameMode) splash.setFullScreen(true);
|
2023-06-21 21:39:41 +09:00
|
|
|
await ensureVencordFiles();
|
|
|
|
runVencordMain();
|
|
|
|
|
|
|
|
mainWin = createMainWindow();
|
|
|
|
|
2023-11-01 06:14:30 +09:00
|
|
|
mainWin.webContents.on("did-finish-load", () => {
|
2023-06-21 21:39:41 +09:00
|
|
|
splash.destroy();
|
|
|
|
|
2024-01-07 11:11:00 +09:00
|
|
|
if (!startMinimized) {
|
|
|
|
mainWin!.show();
|
|
|
|
if (State.store.maximized && !isDeckGameMode) mainWin!.maximize();
|
2023-12-28 12:25:54 +09:00
|
|
|
}
|
2023-11-01 06:14:30 +09:00
|
|
|
|
|
|
|
if (isDeckGameMode) {
|
|
|
|
// always use entire display
|
|
|
|
mainWin!.setFullScreen(true);
|
|
|
|
|
|
|
|
askToApplySteamLayout(mainWin);
|
|
|
|
}
|
2024-01-07 11:11:00 +09:00
|
|
|
|
|
|
|
mainWin.once("show", () => {
|
|
|
|
if (State.store.maximized && !mainWin!.isMaximized() && !isDeckGameMode) {
|
|
|
|
mainWin!.maximize();
|
|
|
|
}
|
|
|
|
});
|
2023-06-21 21:39:41 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
initArRPC();
|
|
|
|
}
|