Revert to export let; ignore autosorted import order

This commit is contained in:
Albert Zhang 2023-12-27 21:11:54 -05:00
parent 2e155c3217
commit 69e555b240
No known key found for this signature in database
GPG key ID: D74C859E94CA6DDC
5 changed files with 25 additions and 35 deletions

View file

@ -7,8 +7,7 @@
import { app, NativeImage, nativeImage } from "electron"; import { app, NativeImage, nativeImage } from "electron";
import { join } from "path"; import { join } from "path";
import { BADGE_DIR, TRAY_ICON_DIR, TRAY_ICON_PATH } from "shared/paths"; import { BADGE_DIR, TRAY_ICON_DIR, TRAY_ICON_PATH } from "shared/paths";
import { tray, mainWin } from "./mainWindow";
import { globals } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
const imgCache = new Map<string, NativeImage>(); const imgCache = new Map<string, NativeImage>();
@ -37,7 +36,7 @@ export function setBadgeCount(count: number) {
const [index, description] = getBadgeIndexAndDescription(count); const [index, description] = getBadgeIndexAndDescription(count);
if (Settings.store.trayBadge) { if (Settings.store.trayBadge) {
globals.tray?.setImage(loadTrayIcon(index ?? 0)); tray?.setImage(loadTrayIcon(index ?? 0));
} }
if (!Settings.store.appBadge) return; if (!Settings.store.appBadge) return;
@ -59,7 +58,7 @@ export function setBadgeCount(count: number) {
lastIndex = index; lastIndex = index;
globals.mainWin?.setOverlayIcon(index === null ? null : loadBadge(index), description); mainWin.setOverlayIcon(index === null ? null : loadBadge(index), description);
break; break;
} }
} }

View file

@ -7,7 +7,7 @@
import Server from "arrpc"; import Server from "arrpc";
import { IpcEvents } from "shared/IpcEvents"; import { IpcEvents } from "shared/IpcEvents";
import { globals } from "./mainWindow"; import { mainWin } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
let server: any; let server: any;
@ -19,13 +19,12 @@ export async function initArRPC() {
try { try {
server = await new Server(); server = await new Server();
const { mainWin } = globals; server.on("activity", (data: any) => mainWin.webContents.send(IpcEvents.ARRPC_ACTIVITY, JSON.stringify(data)));
server.on("activity", (data: any) => mainWin!.webContents.send(IpcEvents.ARRPC_ACTIVITY, JSON.stringify(data)));
server.on("invite", (invite: string, callback: (valid: boolean) => void) => { server.on("invite", (invite: string, callback: (valid: boolean) => void) => {
invite = String(invite); invite = String(invite);
if (!inviteCodeRegex.test(invite)) return callback(false); if (!inviteCodeRegex.test(invite)) return callback(false);
mainWin!.webContents mainWin.webContents
// Safety: Result of JSON.stringify should always be safe to equal // Safety: Result of JSON.stringify should always be safe to equal
// Also, just to be super super safe, invite is regex validated above // Also, just to be super super safe, invite is regex validated above
.executeJavaScript(`Vesktop.openInviteModal(${JSON.stringify(invite)})`) .executeJavaScript(`Vesktop.openInviteModal(${JSON.stringify(invite)})`)

View file

@ -11,7 +11,7 @@ import { checkUpdates } from "updater/main";
import { DATA_DIR } from "./constants"; import { DATA_DIR } from "./constants";
import { createFirstLaunchTour } from "./firstLaunch"; import { createFirstLaunchTour } from "./firstLaunch";
import { createWindows, globals } from "./mainWindow"; import { createWindows, mainWin } from "./mainWindow";
import { registerMediaPermissionsHandler } from "./mediaPermissions"; import { registerMediaPermissionsHandler } from "./mediaPermissions";
import { registerScreenShareHandler } from "./screenShare"; import { registerScreenShareHandler } from "./screenShare";
import { Settings } from "./settings"; import { Settings } from "./settings";
@ -43,7 +43,6 @@ function init() {
); );
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => { app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
const { mainWin } = globals;
if (data.IS_DEV) app.quit(); if (data.IS_DEV) app.quit();
else if (mainWin) { else if (mainWin) {
if (mainWin.isMinimized()) mainWin.restore(); if (mainWin.isMinimized()) mainWin.restore();

View file

@ -6,6 +6,7 @@
if (process.platform === "linux") import("./virtmic"); if (process.platform === "linux") import("./virtmic");
// eslint-disable-next-line simple-import-sort/imports
import { execFile } from "child_process"; import { execFile } from "child_process";
import { app, BrowserWindow, dialog, RelaunchOptions, session, shell } from "electron"; import { app, BrowserWindow, dialog, RelaunchOptions, session, shell } from "electron";
import { mkdirSync, readFileSync, watch } from "fs"; import { mkdirSync, readFileSync, watch } from "fs";
@ -17,8 +18,9 @@ import { debounce } from "shared/utils/debounce";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
import { autoStart } from "./autoStart"; import { autoStart } from "./autoStart";
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
import { globals } from "./mainWindow"; import { mainWin } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { setBadgeCount } from "./appBadge";
import { handle, handleSync } from "./utils/ipcWrappers"; import { handle, handleSync } from "./utils/ipcWrappers";
import { isDeckGameMode, showGamePage } from "./utils/steamOS"; import { isDeckGameMode, showGamePage } from "./utils/steamOS";
import { isValidVencordInstall } from "./utils/vencordLoader"; import { isValidVencordInstall } from "./utils/vencordLoader";
@ -67,8 +69,6 @@ handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => {
}); });
handle(IpcEvents.FOCUS, () => { handle(IpcEvents.FOCUS, () => {
const mainWin = globals.mainWin!;
if (process.platform === "win32") mainWin.minimize(); // Windows is weird if (process.platform === "win32") mainWin.minimize(); // Windows is weird
mainWin.restore(); mainWin.restore();
@ -80,11 +80,10 @@ handle(IpcEvents.CLOSE, e => {
}); });
handle(IpcEvents.MINIMIZE, e => { handle(IpcEvents.MINIMIZE, e => {
globals.mainWin!.minimize(); mainWin.minimize();
}); });
handle(IpcEvents.MAXIMIZE, e => { handle(IpcEvents.MAXIMIZE, e => {
const mainWin = globals.mainWin!;
if (mainWin.isMaximized()) { if (mainWin.isMaximized()) {
mainWin.unmaximize(); mainWin.unmaximize();
} else { } else {
@ -109,7 +108,7 @@ handle(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, (e, word: string) => {
}); });
handle(IpcEvents.SELECT_VENCORD_DIR, async () => { handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
const res = await dialog.showOpenDialog(globals.mainWin!, { const res = await dialog.showOpenDialog(mainWin!, {
properties: ["openDirectory"] properties: ["openDirectory"]
}); });
if (!res.filePaths.length) return "cancelled"; if (!res.filePaths.length) return "cancelled";
@ -120,9 +119,7 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
return dir; return dir;
}); });
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => { handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => setBadgeCount(count));
(require("./appBadge") as typeof import("./appBadge")).setBadgeCount(count);
});
function readCss() { function readCss() {
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => ""); return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
@ -134,7 +131,7 @@ open(VENCORD_QUICKCSS_FILE, "a+").then(fd => {
VENCORD_QUICKCSS_FILE, VENCORD_QUICKCSS_FILE,
{ persistent: false }, { persistent: false },
debounce(async () => { debounce(async () => {
globals.mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss()); mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
}, 50) }, 50)
); );
}); });
@ -144,6 +141,6 @@ watch(
VENCORD_THEMES_DIR, VENCORD_THEMES_DIR,
{ persistent: false }, { persistent: false },
debounce(() => { debounce(() => {
globals.mainWin?.webContents.postMessage("VencordThemeUpdate", void 0); mainWin?.webContents.postMessage("VencordThemeUpdate", void 0);
}) })
); );

View file

@ -48,12 +48,8 @@ app.on("before-quit", () => {
isQuitting = true; isQuitting = true;
}); });
// Export a container object of objects that are used by other modules export let mainWin: BrowserWindow;
// but won't be initialized at import time. export let tray: Tray | null = null;
export const globals = {
tray: <null | Tray>null,
mainWin: <null | BrowserWindow>null
};
function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) { function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
const listeners = new Map<(data: any) => void, PropertyKey>(); const listeners = new Map<(data: any) => void, PropertyKey>();
@ -122,7 +118,7 @@ function initTray(win: BrowserWindow) {
} }
]); ]);
const tray = (globals.tray = new Tray(TRAY_ICON_PATH)); tray = new Tray(TRAY_ICON_PATH);
tray.setToolTip("Vesktop"); tray.setToolTip("Vesktop");
tray.setContextMenu(trayMenu); tray.setContextMenu(trayMenu);
tray.on("click", () => win.show()); tray.on("click", () => win.show());
@ -205,7 +201,7 @@ function initMenuBar(win: BrowserWindow) {
label: "Settings", label: "Settings",
accelerator: "CmdOrCtrl+,", accelerator: "CmdOrCtrl+,",
async click() { async click() {
globals.mainWin!.webContents.executeJavaScript( mainWin.webContents.executeJavaScript(
"Vencord.Webpack.Common.SettingsRouter.open('My Account')" "Vencord.Webpack.Common.SettingsRouter.open('My Account')"
); );
} }
@ -337,9 +333,9 @@ function initSettingsListeners(win: BrowserWindow) {
addSettingsListener("tray", enable => { addSettingsListener("tray", enable => {
if (enable) { if (enable) {
initTray(win); initTray(win);
} else if (globals.tray) { } else if (tray) {
globals.tray.destroy(); tray.destroy();
globals.tray = null; tray = null;
} }
}); });
addSettingsListener("disableMinSize", disable => { addSettingsListener("disableMinSize", disable => {
@ -378,7 +374,7 @@ function initSpellCheck(win: BrowserWindow) {
}); });
} }
function createMainWindow(): BrowserWindow { function createMainWindow() {
// Clear up previous settings listeners // Clear up previous settings listeners
removeSettingsListeners(); removeSettingsListeners();
removeVencordSettingsListeners(); removeVencordSettingsListeners();
@ -389,7 +385,7 @@ function createMainWindow(): BrowserWindow {
const noFrame = frameless === true || (process.platform === "win32" && discordWindowsTitleBar === true); const noFrame = frameless === true || (process.platform === "win32" && discordWindowsTitleBar === true);
const win = (globals.mainWin = new BrowserWindow({ const win = (mainWin = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: false, nodeIntegration: false,
@ -457,7 +453,7 @@ export async function createWindows() {
await ensureVencordFiles(); await ensureVencordFiles();
runVencordMain(); runVencordMain();
const mainWin = (globals.mainWin = createMainWindow()); mainWin = createMainWindow();
mainWin.webContents.on("did-finish-load", () => { mainWin.webContents.on("did-finish-load", () => {
splash.destroy(); splash.destroy();