apply lint

This commit is contained in:
Vendicated 2023-04-09 22:49:50 +02:00 committed by V
parent df53ea549a
commit ddebb6563a
29 changed files with 274 additions and 103 deletions

View file

@ -1,6 +1,6 @@
tabWidth: 4 tabWidth: 4
semi: true semi: true
printWidth: 100 printWidth: 120
trailingComma: none trailingComma: none
bracketSpacing: true bracketSpacing: true
arrowParens: avoid arrowParens: avoid

8
src/globals.d.ts vendored
View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
declare global { declare global {
export var VencordDesktopNative: typeof import("preload/VencordDesktopNative").VencordDesktopNative; export var VencordDesktopNative: typeof import("preload/VencordDesktopNative").VencordDesktopNative;
export var VencordDesktop: typeof import("renderer/index"); export var VencordDesktop: typeof import("renderer/index");
@ -8,4 +14,4 @@ declare global {
export var IS_DEV: boolean; export var IS_DEV: boolean;
} }
export { }; export {};

View file

@ -1,6 +1,13 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { BrowserWindow } from "electron"; import { BrowserWindow } from "electron";
import { join } from "path"; import { join } from "path";
import { ICON_PATH, STATIC_DIR } from "shared/paths"; import { ICON_PATH, STATIC_DIR } from "shared/paths";
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
export function createAboutWindow() { export function createAboutWindow() {

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { app } from "electron"; import { app } from "electron";
import { join } from "path"; import { join } from "path";

View file

@ -1,5 +1,14 @@
import { app, BrowserWindow } from 'electron'; /*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import "./ipc";
import { app, BrowserWindow } from "electron";
import { join } from "path"; import { join } from "path";
import { ICON_PATH } from "../shared/paths"; import { ICON_PATH } from "../shared/paths";
import { once } from "../shared/utils/once"; import { once } from "../shared/utils/once";
import { DATA_DIR, VENCORD_FILES_DIR } from "./constants"; import { DATA_DIR, VENCORD_FILES_DIR } from "./constants";
@ -7,8 +16,6 @@ import { createMainWindow } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { createSplashWindow } from "./splash"; import { createSplashWindow } from "./splash";
import { ensureVencordFiles } from "./utils/vencordLoader"; import { ensureVencordFiles } from "./utils/vencordLoader";
import "./ipc";
if (IS_DEV) { if (IS_DEV) {
require("source-map-support").install(); require("source-map-support").install();
} }
@ -33,14 +40,12 @@ if (!app.requestSingleInstanceLock()) {
}); });
app.whenReady().then(async () => { app.whenReady().then(async () => {
if (process.platform === "win32") if (process.platform === "win32") app.setAppUserModelId("dev.vencord.desktop");
app.setAppUserModelId("dev.vencord.desktop"); else if (process.platform === "darwin") app.dock.setIcon(ICON_PATH);
else if (process.platform === "darwin")
app.dock.setIcon(ICON_PATH);
createWindows(); createWindows();
app.on('activate', () => { app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindows(); if (BrowserWindow.getAllWindows().length === 0) createWindows();
}); });
}); });
@ -65,6 +70,5 @@ async function createWindows() {
} }
app.on("window-all-closed", () => { app.on("window-all-closed", () => {
if (process.platform !== "darwin") if (process.platform !== "darwin") app.quit();
app.quit();
}); });

View file

@ -1,8 +1,15 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { app, dialog, ipcMain, shell } from "electron"; import { app, dialog, ipcMain, shell } from "electron";
import { existsSync, readFileSync, watch } from "fs"; import { existsSync, readFileSync, watch } from "fs";
import { open, readFile } from "fs/promises"; import { open, readFile } from "fs/promises";
import { join } from "path"; import { join } from "path";
import { debounce } from "shared/utils/debounce"; import { debounce } from "shared/utils/debounce";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants";
import { mainWin } from "./mainWindow"; import { mainWin } from "./mainWindow";
@ -69,7 +76,11 @@ function readCss() {
open(VENCORD_QUICKCSS_FILE, "a+").then(fd => { open(VENCORD_QUICKCSS_FILE, "a+").then(fd => {
fd.close(); fd.close();
watch(VENCORD_QUICKCSS_FILE, { persistent: false }, debounce(async () => { watch(
mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss()); VENCORD_QUICKCSS_FILE,
}, 50)); { persistent: false },
debounce(async () => {
mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
}, 50)
);
}); });

View file

@ -1,5 +1,12 @@
import { BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray, app } from "electron"; /*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { app, BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray } from "electron";
import { join } from "path"; import { join } from "path";
import { ICON_PATH } from "../shared/paths"; import { ICON_PATH } from "../shared/paths";
import { createAboutWindow } from "./about"; import { createAboutWindow } from "./about";
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants"; import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants";
@ -206,7 +213,7 @@ function initWindowBoundsListeners(win: BrowserWindow) {
} }
export function createMainWindow() { export function createMainWindow() {
const win = mainWin = new BrowserWindow({ const win = (mainWin = new BrowserWindow({
show: false, show: false,
autoHideMenuBar: true, autoHideMenuBar: true,
webPreferences: { webPreferences: {
@ -219,7 +226,7 @@ export function createMainWindow() {
icon: ICON_PATH, icon: ICON_PATH,
frame: VencordSettings.frameless !== true, frame: VencordSettings.frameless !== true,
...getWindowBoundsOptions() ...getWindowBoundsOptions()
}); }));
win.on("close", e => { win.on("close", e => {
if (isQuitting || Settings.minimizeToTray === false) return; if (isQuitting || Settings.minimizeToTray === false) return;
@ -235,9 +242,8 @@ export function createMainWindow() {
initMenuBar(win); initMenuBar(win);
makeLinksOpenExternally(win); makeLinksOpenExternally(win);
const subdomain = Settings.discordBranch === "canary" || Settings.discordBranch === "ptb" const subdomain =
? `${Settings.discordBranch}.` Settings.discordBranch === "canary" || Settings.discordBranch === "ptb" ? `${Settings.discordBranch}.` : "";
: "";
win.loadURL(`https://${subdomain}discord.com/app`); win.loadURL(`https://${subdomain}discord.com/app`);

View file

@ -1,7 +1,14 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { readFileSync, writeFileSync } from "fs"; import { readFileSync, writeFileSync } from "fs";
import { join } from "path"; import { join } from "path";
import type { Settings as TSettings } from "shared/settings"; import type { Settings as TSettings } from "shared/settings";
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy"; import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
import { DATA_DIR, VENCORD_SETTINGS_FILE } from "./constants"; import { DATA_DIR, VENCORD_SETTINGS_FILE } from "./constants";
const SETTINGS_FILE = join(DATA_DIR, "settings.json"); const SETTINGS_FILE = join(DATA_DIR, "settings.json");
@ -15,20 +22,19 @@ function loadSettings<T extends object = any>(file: string, name: string) {
} catch (err) { } catch (err) {
console.error(`Failed to parse ${name} settings.json:`, err); console.error(`Failed to parse ${name} settings.json:`, err);
} }
} catch { } } catch {}
const makeSettingsProxy = (settings: T) => makeChangeListenerProxy( const makeSettingsProxy = (settings: T) =>
settings, makeChangeListenerProxy(settings, target => writeFileSync(file, JSON.stringify(target, null, 4)));
target => writeFileSync(file, JSON.stringify(target, null, 4))
);
return [settings, makeSettingsProxy] as const; return [settings, makeSettingsProxy] as const;
} }
// eslint-disable-next-line prefer-const
let [PlainSettings, makeSettingsProxy] = loadSettings<TSettings>(SETTINGS_FILE, "VencordDesktop"); let [PlainSettings, makeSettingsProxy] = loadSettings<TSettings>(SETTINGS_FILE, "VencordDesktop");
export let Settings = makeSettingsProxy(PlainSettings); export let Settings = makeSettingsProxy(PlainSettings);
let [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings<any>(VENCORD_SETTINGS_FILE, "Vencord"); const [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings<any>(VENCORD_SETTINGS_FILE, "Vencord");
export const VencordSettings = makeVencordSettingsProxy(PlainVencordSettings); export const VencordSettings = makeVencordSettingsProxy(PlainVencordSettings);
export function setSettings(settings: TSettings) { export function setSettings(settings: TSettings) {
@ -37,7 +43,4 @@ export function setSettings(settings: TSettings) {
Settings = makeSettingsProxy(settings); Settings = makeSettingsProxy(settings);
} }
export { export { PlainSettings, PlainVencordSettings };
PlainSettings,
PlainVencordSettings,
};

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { BrowserWindow } from "electron"; import { BrowserWindow } from "electron";
import { join } from "path"; import { join } from "path";
import { STATIC_DIR } from "shared/paths"; import { STATIC_DIR } from "shared/paths";

View file

@ -1,14 +1,22 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { createWriteStream } from "fs"; import { createWriteStream } from "fs";
import type { IncomingMessage } from "http"; import type { IncomingMessage } from "http";
import { RequestOptions, get } from "https"; import { get, RequestOptions } from "https";
import { finished } from "stream/promises"; import { finished } from "stream/promises";
export async function downloadFile(url: string, file: string, options: RequestOptions = {}) { export async function downloadFile(url: string, file: string, options: RequestOptions = {}) {
const res = await simpleReq(url, options); const res = await simpleReq(url, options);
await finished( await finished(
res.pipe(createWriteStream(file, { res.pipe(
autoClose: true createWriteStream(file, {
})) autoClose: true
})
)
); );
} }
@ -16,12 +24,8 @@ export function simpleReq(url: string, options: RequestOptions = {}) {
return new Promise<IncomingMessage>((resolve, reject) => { return new Promise<IncomingMessage>((resolve, reject) => {
get(url, options, res => { get(url, options, res => {
const { statusCode, statusMessage, headers } = res; const { statusCode, statusMessage, headers } = res;
if (statusCode! >= 400) if (statusCode! >= 400) return void reject(`${statusCode}: ${statusMessage} - ${url}`);
return void reject(`${statusCode}: ${statusMessage} - ${url}`); if (statusCode! >= 300) return simpleReq(headers.location!, options).then(resolve).catch(reject);
if (statusCode! >= 300)
return simpleReq(headers.location!, options)
.then(resolve)
.catch(reject);
resolve(res); resolve(res);
}); });

View file

@ -1,4 +1,11 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { BrowserWindow, shell } from "electron"; import { BrowserWindow, shell } from "electron";
import { Settings } from "../settings"; import { Settings } from "../settings";
export function makeLinksOpenExternally(win: BrowserWindow) { export function makeLinksOpenExternally(win: BrowserWindow) {
@ -10,7 +17,7 @@ export function makeLinksOpenExternally(win: BrowserWindow) {
} }
try { try {
var protocol = new URL(url).protocol; var { protocol } = new URL(url);
} catch { } catch {
return { action: "deny" }; return { action: "deny" };
} }
@ -21,6 +28,7 @@ export function makeLinksOpenExternally(win: BrowserWindow) {
if (Settings.openLinksWithElectron) { if (Settings.openLinksWithElectron) {
return { action: "allow" }; return { action: "allow" };
} }
// eslint-disable-next-line no-fallthrough
case "mailto:": case "mailto:":
case "steam:": case "steam:":
case "spotify:": case "spotify:":

View file

@ -1,16 +1,18 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { existsSync, mkdirSync } from "fs"; import { existsSync, mkdirSync } from "fs";
import { join } from "path"; import { join } from "path";
import { USER_AGENT, VENCORD_FILES_DIR } from "../constants"; import { USER_AGENT, VENCORD_FILES_DIR } from "../constants";
import { downloadFile, simpleGet } from "./http"; import { downloadFile, simpleGet } from "./http";
const API_BASE = "https://api.github.com/repos/Vendicated/Vencord"; const API_BASE = "https://api.github.com/repos/Vendicated/Vencord";
const FILES_TO_DOWNLOAD = [ const FILES_TO_DOWNLOAD = ["vencordDesktopMain.js", "preload.js", "vencordDesktopRenderer.js", "renderer.css"];
"vencordDesktopMain.js",
"preload.js",
"vencordDesktopRenderer.js",
"renderer.css"
];
export async function githubGet(endpoint: string) { export async function githubGet(endpoint: string) {
return simpleGet(API_BASE + endpoint, { return simpleGet(API_BASE + endpoint, {
@ -32,12 +34,8 @@ export async function downloadVencordFiles() {
await Promise.all( await Promise.all(
assets assets
.filter(({ name }) => .filter(({ name }) => FILES_TO_DOWNLOAD.some(f => name.startsWith(f)))
FILES_TO_DOWNLOAD.some(f => name.startsWith(f)) .map(({ name, browser_download_url }) => downloadFile(browser_download_url, join(VENCORD_FILES_DIR, name)))
)
.map(({ name, browser_download_url }) =>
downloadFile(browser_download_url, join(VENCORD_FILES_DIR, name))
)
); );
} }

View file

@ -1,6 +1,13 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import type { Settings } from "shared/settings"; import type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest"; import type { LiteralUnion } from "type-fest";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
function invoke<T = any>(event: IpcEvents, ...args: any[]) { function invoke<T = any>(event: IpcEvents, ...args: any[]) {
@ -18,7 +25,7 @@ export const VencordDesktopNative = {
}, },
fileManager: { fileManager: {
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path), showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
selectVencordDir: () => invoke<LiteralUnion<"cancelled" | "invalid", string>>(IpcEvents.SELECT_VENCORD_DIR), selectVencordDir: () => invoke<LiteralUnion<"cancelled" | "invalid", string>>(IpcEvents.SELECT_VENCORD_DIR)
}, },
settings: { settings: {
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS), get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
@ -27,5 +34,4 @@ export const VencordDesktopNative = {
win: { win: {
focus: () => invoke<void>(IpcEvents.FOCUS) focus: () => invoke<void>(IpcEvents.FOCUS)
} }
} };

View file

@ -1,5 +1,12 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { contextBridge, ipcRenderer, webFrame } from "electron"; import { contextBridge, ipcRenderer, webFrame } from "electron";
import { readFileSync, watch } from "fs"; import { readFileSync, watch } from "fs";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
import { VencordDesktopNative } from "./VencordDesktopNative"; import { VencordDesktopNative } from "./VencordDesktopNative";

View file

@ -1,18 +1,43 @@
import { getValueAndOnChange, useSettings } from "renderer/settings"; /*
import { Common, Util } from "../vencord"; * SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import "./settings.css"; import "./settings.css";
import { useSettings } from "renderer/settings";
import { Common, Util } from "../vencord";
const { Margins } = Util; const { Margins } = Util;
export default function SettingsUi() { export default function SettingsUi() {
const Settings = useSettings(); const Settings = useSettings();
const { Forms: { FormSection, FormText, FormDivider, FormSwitch, FormTitle }, Text, Select, Button } = Common; const {
Forms: { FormSection, FormText, FormDivider, FormSwitch, FormTitle },
Text,
Select,
Button
} = Common;
const switches: [keyof typeof Settings, string, string, boolean?][] = [ const switches: [keyof typeof Settings, string, string, boolean?][] = [
["minimizeToTray", "Minimize to tray", "Hitting X will make Vencord Desktop minimize to the tray instead of closing", true], [
["disableMinSize", "Disable minimum window size", "Allows you to make the window as small as your heart desires"], "minimizeToTray",
["openLinksWithElectron", "Open Links in app (experimental)", "Opens links in a new Vencord Desktop window instead of your web browser"], "Minimize to tray",
"Hitting X will make Vencord Desktop minimize to the tray instead of closing",
true
],
[
"disableMinSize",
"Disable minimum window size",
"Allows you to make the window as small as your heart desires"
],
[
"openLinksWithElectron",
"Open Links in app (experimental)",
"Opens links in a new Vencord Desktop window instead of your web browser"
]
]; ];
return ( return (
@ -21,18 +46,16 @@ export default function SettingsUi() {
Vencord Desktop Settings Vencord Desktop Settings
</Text> </Text>
<FormTitle className={Margins.top16}> <FormTitle className={Margins.top16}>Discord Branch</FormTitle>
Discord Branch
</FormTitle>
<Select <Select
placeholder="Stable" placeholder="Stable"
options={[ options={[
{ label: "Stable", value: "stable", default: true }, { label: "Stable", value: "stable", default: true },
{ label: "Canary", value: "canary" }, { label: "Canary", value: "canary" },
{ label: "PTB", value: "ptb" }, { label: "PTB", value: "ptb" }
]} ]}
closeOnSelect={true} closeOnSelect={true}
select={v => Settings.discordBranch = v} select={v => (Settings.discordBranch = v)}
isSelected={v => v === Settings.discordBranch} isSelected={v => v === Settings.discordBranch}
serialize={s => s} serialize={s => s}
/> />
@ -42,7 +65,7 @@ export default function SettingsUi() {
{switches.map(([key, text, note, def]) => ( {switches.map(([key, text, note, def]) => (
<FormSwitch <FormSwitch
value={Settings[key] ?? def ?? false} value={Settings[key] ?? def ?? false}
onChange={v => Settings[key] = v} onChange={v => (Settings[key] = v)}
note={note} note={note}
key={key} key={key}
> >
@ -52,22 +75,20 @@ export default function SettingsUi() {
<FormTitle>Vencord Location</FormTitle> <FormTitle>Vencord Location</FormTitle>
<FormText> <FormText>
Vencord files are loaded from Vencord files are loaded from{" "}
{" "} {Settings.vencordDir ? (
{Settings.vencordDir <a
? ( href="about:blank"
<a onClick={e => {
href="about:blank" e.preventDefault();
onClick={e => { VencordDesktopNative.fileManager.showItemInFolder(Settings.vencordDir!);
e.preventDefault(); }}
VencordDesktopNative.fileManager.showItemInFolder(Settings.vencordDir!); >
}} {Settings.vencordDir}
> </a>
{Settings.vencordDir} ) : (
</a> "the default location"
) )}
: "the default location"
}
</FormText> </FormText>
<div className="vcd-location-btns"> <div className="vcd-location-btns">
<Button <Button
@ -88,11 +109,11 @@ export default function SettingsUi() {
<Button <Button
size={Button.Sizes.SMALL} size={Button.Sizes.SMALL}
color={Button.Colors.RED} color={Button.Colors.RED}
onClick={() => Settings.vencordDir = void 0} onClick={() => (Settings.vencordDir = void 0)}
> >
Reset Reset
</Button> </Button>
</div> </div>
</FormSection > </FormSection>
); );
} }

View file

@ -1 +1,7 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export { default as Settings } from "./Settings"; export { default as Settings } from "./Settings";

View file

@ -1,4 +1,11 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import "./hideGarbage.css"; import "./hideGarbage.css";
import { isFirstRun, localStorage } from "./utils"; import { isFirstRun, localStorage } from "./utils";
// Make clicking Notifications focus the window // Make clicking Notifications focus the window

View file

@ -1,7 +1,12 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import "./fixes"; import "./fixes";
console.log("read if cute :3"); console.log("read if cute :3");
export * as Components from "./components"; export * as Components from "./components";
export { PlainSettings, Settings } from "./settings"; export { PlainSettings, Settings } from "./settings";

View file

@ -1,5 +1,12 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import type { Settings as TSettings } from "shared/settings"; import type { Settings as TSettings } from "shared/settings";
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy"; import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
import { Common } from "./vencord"; import { Common } from "./vencord";
const signals = new Set<() => void>(); const signals = new Set<() => void>();
@ -23,6 +30,6 @@ export function useSettings() {
export function getValueAndOnChange(key: keyof TSettings) { export function getValueAndOnChange(key: keyof TSettings) {
return { return {
value: Settings[key] as any, value: Settings[key] as any,
onChange: (value: any) => Settings[key] = value onChange: (value: any) => (Settings[key] = value)
}; };
} }

View file

@ -1,4 +1,10 @@
export const localStorage = window.vcdLS = window.localStorage; /*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export const localStorage = (window.vcdLS = window.localStorage);
export const isFirstRun = (() => { export const isFirstRun = (() => {
const key = "VCD_FIRST_RUN"; const key = "VCD_FIRST_RUN";

View file

@ -1,13 +1,13 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
// FIXME: this is terrible // FIXME: this is terrible
const { Webpack, Plugins, Util } = Vencord; const { Webpack, Plugins, Util } = Vencord;
const { Common } = Webpack; const { Common } = Webpack;
const { plugins } = Plugins; const { plugins } = Plugins;
export { export { Common, Plugins, plugins, Util, Webpack };
Webpack,
Common,
Util,
Plugins,
plugins
};

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export const enum IpcEvents { export const enum IpcEvents {
GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE", GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE",
GET_VENCORD_RENDERER_SCRIPT = "VCD_GET_VC_RENDERER_SCRIPT", GET_VENCORD_RENDERER_SCRIPT = "VCD_GET_VC_RENDERER_SCRIPT",
@ -15,4 +21,3 @@ export const enum IpcEvents {
SELECT_VENCORD_DIR = "VCD_SELECT_VENCORD_DIR" SELECT_VENCORD_DIR = "VCD_SELECT_VENCORD_DIR"
} }

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { join } from "path"; import { join } from "path";
export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static"); export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static");

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import type { Rectangle } from "electron"; import type { Rectangle } from "electron";
export interface Settings { export interface Settings {

View file

@ -1,7 +1,15 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export function debounce<T extends Function>(func: T, delay = 300): T { export function debounce<T extends Function>(func: T, delay = 300): T {
let timeout: NodeJS.Timeout; let timeout: NodeJS.Timeout;
return function (...args: any[]) { return function (...args: any[]) {
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(() => { func(...args); }, delay); timeout = setTimeout(() => {
func(...args);
}, delay);
} as any; } as any;
} }

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export function makeChangeListenerProxy<T extends object>(object: T, onChange: (object: T) => void, _root = object): T { export function makeChangeListenerProxy<T extends object>(object: T, onChange: (object: T) => void, _root = object): T {
return new Proxy(object, { return new Proxy(object, {
get(target, key) { get(target, key) {
@ -15,6 +21,6 @@ export function makeChangeListenerProxy<T extends object>(object: T, onChange: (
onChange(_root); onChange(_root);
return true; return true;
}, }
}); });
} }

View file

@ -1,11 +1,21 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
type Func = (...args: any[]) => any; type Func = (...args: any[]) => any;
export function monkeyPatch<O extends object>(object: O, key: keyof O, replacement: (original: Func, ...args: any[]) => any): void { export function monkeyPatch<O extends object>(
object: O,
key: keyof O,
replacement: (original: Func, ...args: any[]) => any
): void {
const original = object[key] as Func; const original = object[key] as Func;
const replacer = object[key] = function (this: unknown, ...args: any[]) { const replacer = (object[key] = function (this: unknown, ...args: any[]) {
return replacement.call(this, original, ...args); return replacement.call(this, original, ...args);
} as any; } as any);
Object.defineProperties(replacer, Object.getOwnPropertyDescriptors(original)); Object.defineProperties(replacer, Object.getOwnPropertyDescriptors(original));
replacer.toString = () => original.toString(); replacer.toString = () => original.toString();

View file

@ -1,3 +1,9 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export function once<T extends Function>(fn: T): T { export function once<T extends Function>(fn: T): T {
let called = false; let called = false;
return function (this: any, ...args: any[]) { return function (this: any, ...args: any[]) {