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

View file

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

View file

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

View file

@ -6,6 +6,7 @@
if (process.platform === "linux") import("./virtmic");
// eslint-disable-next-line simple-import-sort/imports
import { execFile } from "child_process";
import { app, BrowserWindow, dialog, RelaunchOptions, session, shell } from "electron";
import { mkdirSync, readFileSync, watch } from "fs";
@ -17,8 +18,9 @@ import { debounce } from "shared/utils/debounce";
import { IpcEvents } from "../shared/IpcEvents";
import { autoStart } from "./autoStart";
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 { setBadgeCount } from "./appBadge";
import { handle, handleSync } from "./utils/ipcWrappers";
import { isDeckGameMode, showGamePage } from "./utils/steamOS";
import { isValidVencordInstall } from "./utils/vencordLoader";
@ -67,8 +69,6 @@ handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => {
});
handle(IpcEvents.FOCUS, () => {
const mainWin = globals.mainWin!;
if (process.platform === "win32") mainWin.minimize(); // Windows is weird
mainWin.restore();
@ -80,11 +80,10 @@ handle(IpcEvents.CLOSE, e => {
});
handle(IpcEvents.MINIMIZE, e => {
globals.mainWin!.minimize();
mainWin.minimize();
});
handle(IpcEvents.MAXIMIZE, e => {
const mainWin = globals.mainWin!;
if (mainWin.isMaximized()) {
mainWin.unmaximize();
} else {
@ -109,7 +108,7 @@ handle(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, (e, word: string) => {
});
handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
const res = await dialog.showOpenDialog(globals.mainWin!, {
const res = await dialog.showOpenDialog(mainWin!, {
properties: ["openDirectory"]
});
if (!res.filePaths.length) return "cancelled";
@ -120,9 +119,7 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
return dir;
});
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => {
(require("./appBadge") as typeof import("./appBadge")).setBadgeCount(count);
});
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => setBadgeCount(count));
function readCss() {
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
@ -134,7 +131,7 @@ open(VENCORD_QUICKCSS_FILE, "a+").then(fd => {
VENCORD_QUICKCSS_FILE,
{ persistent: false },
debounce(async () => {
globals.mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
}, 50)
);
});
@ -144,6 +141,6 @@ watch(
VENCORD_THEMES_DIR,
{ persistent: false },
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;
});
// Export a container object of objects that are used by other modules
// but won't be initialized at import time.
export const globals = {
tray: <null | Tray>null,
mainWin: <null | BrowserWindow>null
};
export let mainWin: BrowserWindow;
export let tray: Tray | null = null;
function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
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.setContextMenu(trayMenu);
tray.on("click", () => win.show());
@ -205,7 +201,7 @@ function initMenuBar(win: BrowserWindow) {
label: "Settings",
accelerator: "CmdOrCtrl+,",
async click() {
globals.mainWin!.webContents.executeJavaScript(
mainWin.webContents.executeJavaScript(
"Vencord.Webpack.Common.SettingsRouter.open('My Account')"
);
}
@ -337,9 +333,9 @@ function initSettingsListeners(win: BrowserWindow) {
addSettingsListener("tray", enable => {
if (enable) {
initTray(win);
} else if (globals.tray) {
globals.tray.destroy();
globals.tray = null;
} else if (tray) {
tray.destroy();
tray = null;
}
});
addSettingsListener("disableMinSize", disable => {
@ -378,7 +374,7 @@ function initSpellCheck(win: BrowserWindow) {
});
}
function createMainWindow(): BrowserWindow {
function createMainWindow() {
// Clear up previous settings listeners
removeSettingsListeners();
removeVencordSettingsListeners();
@ -389,7 +385,7 @@ function createMainWindow(): BrowserWindow {
const noFrame = frameless === true || (process.platform === "win32" && discordWindowsTitleBar === true);
const win = (globals.mainWin = new BrowserWindow({
const win = (mainWin = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: false,
@ -457,7 +453,7 @@ export async function createWindows() {
await ensureVencordFiles();
runVencordMain();
const mainWin = (globals.mainWin = createMainWindow());
mainWin = createMainWindow();
mainWin.webContents.on("did-finish-load", () => {
splash.destroy();