merge unconflict
This commit is contained in:
@@ -1,52 +1,44 @@
|
||||
/*
|
||||
|
||||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||
|
||||
* Copyright (c) 2025 Vendicated and Vesktop contributors
|
||||
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
*/
|
||||
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
BrowserWindowConstructorOptions,
|
||||
dialog,
|
||||
Menu,
|
||||
MenuItemConstructorOptions,
|
||||
nativeTheme,
|
||||
screen,
|
||||
session,
|
||||
Tray
|
||||
session
|
||||
} from "electron";
|
||||
import { EventEmitter } from "events";
|
||||
import { rm } from "fs/promises";
|
||||
import { join } from "path";
|
||||
import { IpcCommands, IpcEvents } from "shared/IpcEvents";
|
||||
import { isTruthy } from "shared/utils/guards";
|
||||
import { once } from "shared/utils/once";
|
||||
import type { SettingsStore } from "shared/utils/SettingsStore";
|
||||
|
||||
import { ICON_PATH } from "../shared/paths";
|
||||
import { createAboutWindow } from "./about";
|
||||
import { initArRPC } from "./arrpc";
|
||||
import {
|
||||
BrowserUserAgent,
|
||||
DATA_DIR,
|
||||
DEFAULT_HEIGHT,
|
||||
DEFAULT_WIDTH,
|
||||
MessageBoxChoice,
|
||||
MIN_HEIGHT,
|
||||
MIN_WIDTH,
|
||||
VENCORD_FILES_DIR
|
||||
} from "./constants";
|
||||
import { BrowserUserAgent, DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH, VENCORD_FILES_DIR } from "./constants";
|
||||
import { AppEvents } from "./events";
|
||||
import { darwinURL } from "./index";
|
||||
import { sendRendererCommand } from "./ipcCommands";
|
||||
import { Settings, State, VencordSettings } from "./settings";
|
||||
import { createSplashWindow, updateSplashMessage } from "./splash";
|
||||
import { destroyTray, initTray } from "./tray";
|
||||
import { clearData } from "./utils/clearData";
|
||||
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
||||
import { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader";
|
||||
|
||||
let isQuitting = false;
|
||||
let tray: Tray;
|
||||
|
||||
applyDeckKeyboardFix();
|
||||
|
||||
@@ -77,84 +69,6 @@ function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
|
||||
const [addSettingsListener, removeSettingsListeners] = makeSettingsListenerHelpers(Settings);
|
||||
const [addVencordSettingsListener, removeVencordSettingsListeners] = makeSettingsListenerHelpers(VencordSettings);
|
||||
|
||||
function initTray(win: BrowserWindow) {
|
||||
const onTrayClick = () => {
|
||||
if (Settings.store.clickTrayToShowHide && win.isVisible()) win.hide();
|
||||
else win.show();
|
||||
};
|
||||
const trayMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: "Open",
|
||||
click() {
|
||||
win.show();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "About",
|
||||
click: createAboutWindow
|
||||
},
|
||||
{
|
||||
label: "Repair Not-Nexulien",
|
||||
async click() {
|
||||
await downloadVencordFiles();
|
||||
app.relaunch();
|
||||
app.quit();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Reset Not-Nextop",
|
||||
async click() {
|
||||
await clearData(win);
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "separator"
|
||||
},
|
||||
{
|
||||
label: "Restart",
|
||||
click() {
|
||||
app.relaunch();
|
||||
app.quit();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Quit",
|
||||
click() {
|
||||
isQuitting = true;
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
tray = new Tray(ICON_PATH);
|
||||
tray.setToolTip("Not-Nextop");
|
||||
tray.setContextMenu(trayMenu);
|
||||
tray.on("click", onTrayClick);
|
||||
}
|
||||
|
||||
async function clearData(win: BrowserWindow) {
|
||||
const { response } = await dialog.showMessageBox(win, {
|
||||
message: "Are you sure you want to reset Not-Nextop?",
|
||||
detail: "This will log you out, clear caches and reset all your settings!\n\nNot-Nextop 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();
|
||||
}
|
||||
|
||||
type MenuItemList = Array<MenuItemConstructorOptions | false>;
|
||||
|
||||
function initMenuBar(win: BrowserWindow) {
|
||||
@@ -333,8 +247,8 @@ function initWindowBoundsListeners(win: BrowserWindow) {
|
||||
|
||||
function initSettingsListeners(win: BrowserWindow) {
|
||||
addSettingsListener("tray", enable => {
|
||||
if (enable) initTray(win);
|
||||
else tray?.destroy();
|
||||
if (enable) initTray(win, q => (isQuitting = q));
|
||||
else destroyTray();
|
||||
});
|
||||
|
||||
addSettingsListener("disableMinSize", disable => {
|
||||
@@ -439,7 +353,6 @@ function createMainWindow() {
|
||||
// disable renderer backgrounding to prevent the app from unloading when in the background
|
||||
backgroundThrottling: false
|
||||
},
|
||||
icon: ICON_PATH,
|
||||
frame: !noFrame,
|
||||
...(transparent && {
|
||||
transparent: true,
|
||||
@@ -477,7 +390,9 @@ function createMainWindow() {
|
||||
});
|
||||
|
||||
initWindowBoundsListeners(win);
|
||||
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win);
|
||||
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin")
|
||||
initTray(win, q => (isQuitting = q));
|
||||
|
||||
initMenuBar(win);
|
||||
makeLinksOpenExternally(win);
|
||||
initSettingsListeners(win);
|
||||
@@ -497,8 +412,6 @@ function createMainWindow() {
|
||||
|
||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
||||
|
||||
const loadEvents = new EventEmitter();
|
||||
|
||||
export function loadUrl(uri: string | undefined) {
|
||||
const branch = Settings.store.discordBranch;
|
||||
const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
|
||||
@@ -506,7 +419,7 @@ export function loadUrl(uri: string | undefined) {
|
||||
// we do not rely on 'did-finish-load' because it fires even if loadURL fails which triggers early detruction of the splash
|
||||
mainWin
|
||||
.loadURL(`https://${subdomain}discord.com/${uri ? new URL(uri).pathname.slice(1) || "app" : "app"}`)
|
||||
.then(() => loadEvents.emit("app-loaded"))
|
||||
.then(() => AppEvents.emit("appLoaded"))
|
||||
.catch(error => retryUrl(error.url, error.code));
|
||||
}
|
||||
|
||||
@@ -533,7 +446,7 @@ export async function createWindows() {
|
||||
|
||||
mainWin = createMainWindow();
|
||||
|
||||
loadEvents.on("app-loaded", () => {
|
||||
AppEvents.on("appLoaded", () => {
|
||||
splash?.destroy();
|
||||
|
||||
if (!startMinimized) {
|
||||
|
||||
Reference in New Issue
Block a user