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
semi: true
printWidth: 100
printWidth: 120
trailingComma: none
bracketSpacing: true
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 {
export var VencordDesktopNative: typeof import("preload/VencordDesktopNative").VencordDesktopNative;
export var VencordDesktop: typeof import("renderer/index");
@ -8,4 +14,4 @@ declare global {
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 { join } from "path";
import { ICON_PATH, STATIC_DIR } from "shared/paths";
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
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 { 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 { ICON_PATH } from "../shared/paths";
import { once } from "../shared/utils/once";
import { DATA_DIR, VENCORD_FILES_DIR } from "./constants";
@ -7,8 +16,6 @@ import { createMainWindow } from "./mainWindow";
import { Settings } from "./settings";
import { createSplashWindow } from "./splash";
import { ensureVencordFiles } from "./utils/vencordLoader";
import "./ipc";
if (IS_DEV) {
require("source-map-support").install();
}
@ -33,14 +40,12 @@ if (!app.requestSingleInstanceLock()) {
});
app.whenReady().then(async () => {
if (process.platform === "win32")
app.setAppUserModelId("dev.vencord.desktop");
else if (process.platform === "darwin")
app.dock.setIcon(ICON_PATH);
if (process.platform === "win32") app.setAppUserModelId("dev.vencord.desktop");
else if (process.platform === "darwin") app.dock.setIcon(ICON_PATH);
createWindows();
app.on('activate', () => {
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindows();
});
});
@ -65,6 +70,5 @@ async function createWindows() {
}
app.on("window-all-closed", () => {
if (process.platform !== "darwin")
app.quit();
if (process.platform !== "darwin") 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 { existsSync, readFileSync, watch } from "fs";
import { open, readFile } from "fs/promises";
import { join } from "path";
import { debounce } from "shared/utils/debounce";
import { IpcEvents } from "../shared/IpcEvents";
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants";
import { mainWin } from "./mainWindow";
@ -69,7 +76,11 @@ function readCss() {
open(VENCORD_QUICKCSS_FILE, "a+").then(fd => {
fd.close();
watch(VENCORD_QUICKCSS_FILE, { persistent: false }, debounce(async () => {
mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
}, 50));
watch(
VENCORD_QUICKCSS_FILE,
{ 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 { ICON_PATH } from "../shared/paths";
import { createAboutWindow } from "./about";
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants";
@ -206,7 +213,7 @@ function initWindowBoundsListeners(win: BrowserWindow) {
}
export function createMainWindow() {
const win = mainWin = new BrowserWindow({
const win = (mainWin = new BrowserWindow({
show: false,
autoHideMenuBar: true,
webPreferences: {
@ -219,7 +226,7 @@ export function createMainWindow() {
icon: ICON_PATH,
frame: VencordSettings.frameless !== true,
...getWindowBoundsOptions()
});
}));
win.on("close", e => {
if (isQuitting || Settings.minimizeToTray === false) return;
@ -235,9 +242,8 @@ export function createMainWindow() {
initMenuBar(win);
makeLinksOpenExternally(win);
const subdomain = Settings.discordBranch === "canary" || Settings.discordBranch === "ptb"
? `${Settings.discordBranch}.`
: "";
const subdomain =
Settings.discordBranch === "canary" || Settings.discordBranch === "ptb" ? `${Settings.discordBranch}.` : "";
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 { join } from "path";
import type { Settings as TSettings } from "shared/settings";
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
import { DATA_DIR, VENCORD_SETTINGS_FILE } from "./constants";
const SETTINGS_FILE = join(DATA_DIR, "settings.json");
@ -15,20 +22,19 @@ function loadSettings<T extends object = any>(file: string, name: string) {
} catch (err) {
console.error(`Failed to parse ${name} settings.json:`, err);
}
} catch { }
} catch {}
const makeSettingsProxy = (settings: T) => makeChangeListenerProxy(
settings,
target => writeFileSync(file, JSON.stringify(target, null, 4))
);
const makeSettingsProxy = (settings: T) =>
makeChangeListenerProxy(settings, target => writeFileSync(file, JSON.stringify(target, null, 4)));
return [settings, makeSettingsProxy] as const;
}
// eslint-disable-next-line prefer-const
let [PlainSettings, makeSettingsProxy] = loadSettings<TSettings>(SETTINGS_FILE, "VencordDesktop");
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 function setSettings(settings: TSettings) {
@ -37,7 +43,4 @@ export function setSettings(settings: TSettings) {
Settings = makeSettingsProxy(settings);
}
export {
PlainSettings,
PlainVencordSettings,
};
export { 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 { join } from "path";
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 type { IncomingMessage } from "http";
import { RequestOptions, get } from "https";
import { get, RequestOptions } from "https";
import { finished } from "stream/promises";
export async function downloadFile(url: string, file: string, options: RequestOptions = {}) {
const res = await simpleReq(url, options);
await finished(
res.pipe(createWriteStream(file, {
autoClose: true
}))
res.pipe(
createWriteStream(file, {
autoClose: true
})
)
);
}
@ -16,12 +24,8 @@ export function simpleReq(url: string, options: RequestOptions = {}) {
return new Promise<IncomingMessage>((resolve, reject) => {
get(url, options, res => {
const { statusCode, statusMessage, headers } = res;
if (statusCode! >= 400)
return void reject(`${statusCode}: ${statusMessage} - ${url}`);
if (statusCode! >= 300)
return simpleReq(headers.location!, options)
.then(resolve)
.catch(reject);
if (statusCode! >= 400) return void reject(`${statusCode}: ${statusMessage} - ${url}`);
if (statusCode! >= 300) return simpleReq(headers.location!, options).then(resolve).catch(reject);
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 { Settings } from "../settings";
export function makeLinksOpenExternally(win: BrowserWindow) {
@ -10,7 +17,7 @@ export function makeLinksOpenExternally(win: BrowserWindow) {
}
try {
var protocol = new URL(url).protocol;
var { protocol } = new URL(url);
} catch {
return { action: "deny" };
}
@ -21,6 +28,7 @@ export function makeLinksOpenExternally(win: BrowserWindow) {
if (Settings.openLinksWithElectron) {
return { action: "allow" };
}
// eslint-disable-next-line no-fallthrough
case "mailto:":
case "steam:":
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 { join } from "path";
import { USER_AGENT, VENCORD_FILES_DIR } from "../constants";
import { downloadFile, simpleGet } from "./http";
const API_BASE = "https://api.github.com/repos/Vendicated/Vencord";
const FILES_TO_DOWNLOAD = [
"vencordDesktopMain.js",
"preload.js",
"vencordDesktopRenderer.js",
"renderer.css"
];
const FILES_TO_DOWNLOAD = ["vencordDesktopMain.js", "preload.js", "vencordDesktopRenderer.js", "renderer.css"];
export async function githubGet(endpoint: string) {
return simpleGet(API_BASE + endpoint, {
@ -32,12 +34,8 @@ export async function downloadVencordFiles() {
await Promise.all(
assets
.filter(({ name }) =>
FILES_TO_DOWNLOAD.some(f => name.startsWith(f))
)
.map(({ name, browser_download_url }) =>
downloadFile(browser_download_url, join(VENCORD_FILES_DIR, name))
)
.filter(({ name }) => FILES_TO_DOWNLOAD.some(f => name.startsWith(f)))
.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 type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest";
import { IpcEvents } from "../shared/IpcEvents";
function invoke<T = any>(event: IpcEvents, ...args: any[]) {
@ -18,7 +25,7 @@ export const VencordDesktopNative = {
},
fileManager: {
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: {
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
@ -27,5 +34,4 @@ export const VencordDesktopNative = {
win: {
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 { readFileSync, watch } from "fs";
import { IpcEvents } from "../shared/IpcEvents";
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 { useSettings } from "renderer/settings";
import { Common, Util } from "../vencord";
const { Margins } = Util;
export default function SettingsUi() {
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?][] = [
["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"],
["openLinksWithElectron", "Open Links in app (experimental)", "Opens links in a new Vencord Desktop window instead of your web browser"],
[
"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"
],
[
"openLinksWithElectron",
"Open Links in app (experimental)",
"Opens links in a new Vencord Desktop window instead of your web browser"
]
];
return (
@ -21,18 +46,16 @@ export default function SettingsUi() {
Vencord Desktop Settings
</Text>
<FormTitle className={Margins.top16}>
Discord Branch
</FormTitle>
<FormTitle className={Margins.top16}>Discord Branch</FormTitle>
<Select
placeholder="Stable"
options={[
{ label: "Stable", value: "stable", default: true },
{ label: "Canary", value: "canary" },
{ label: "PTB", value: "ptb" },
{ label: "PTB", value: "ptb" }
]}
closeOnSelect={true}
select={v => Settings.discordBranch = v}
select={v => (Settings.discordBranch = v)}
isSelected={v => v === Settings.discordBranch}
serialize={s => s}
/>
@ -42,7 +65,7 @@ export default function SettingsUi() {
{switches.map(([key, text, note, def]) => (
<FormSwitch
value={Settings[key] ?? def ?? false}
onChange={v => Settings[key] = v}
onChange={v => (Settings[key] = v)}
note={note}
key={key}
>
@ -52,22 +75,20 @@ export default function SettingsUi() {
<FormTitle>Vencord Location</FormTitle>
<FormText>
Vencord files are loaded from
{" "}
{Settings.vencordDir
? (
<a
href="about:blank"
onClick={e => {
e.preventDefault();
VencordDesktopNative.fileManager.showItemInFolder(Settings.vencordDir!);
}}
>
{Settings.vencordDir}
</a>
)
: "the default location"
}
Vencord files are loaded from{" "}
{Settings.vencordDir ? (
<a
href="about:blank"
onClick={e => {
e.preventDefault();
VencordDesktopNative.fileManager.showItemInFolder(Settings.vencordDir!);
}}
>
{Settings.vencordDir}
</a>
) : (
"the default location"
)}
</FormText>
<div className="vcd-location-btns">
<Button
@ -88,11 +109,11 @@ export default function SettingsUi() {
<Button
size={Button.Sizes.SMALL}
color={Button.Colors.RED}
onClick={() => Settings.vencordDir = void 0}
onClick={() => (Settings.vencordDir = void 0)}
>
Reset
</Button>
</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";

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 { isFirstRun, localStorage } from "./utils";
// 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";
console.log("read if cute :3");
export * as Components from "./components";
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 { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
import { Common } from "./vencord";
const signals = new Set<() => void>();
@ -23,6 +30,6 @@ export function useSettings() {
export function getValueAndOnChange(key: keyof TSettings) {
return {
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 = (() => {
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
const { Webpack, Plugins, Util } = Vencord;
const { Common } = Webpack;
const { plugins } = Plugins;
export {
Webpack,
Common,
Util,
Plugins,
plugins
};
export { Common, Plugins, plugins, Util, Webpack };

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 {
GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE",
GET_VENCORD_RENDERER_SCRIPT = "VCD_GET_VC_RENDERER_SCRIPT",
@ -15,4 +21,3 @@ export const enum IpcEvents {
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";
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";
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 {
let timeout: NodeJS.Timeout;
return function (...args: any[]) {
clearTimeout(timeout);
timeout = setTimeout(() => { func(...args); }, delay);
timeout = setTimeout(() => {
func(...args);
}, delay);
} 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 {
return new Proxy(object, {
get(target, key) {
@ -15,6 +21,6 @@ export function makeChangeListenerProxy<T extends object>(object: T, onChange: (
onChange(_root);
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;
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 replacer = object[key] = function (this: unknown, ...args: any[]) {
const replacer = (object[key] = function (this: unknown, ...args: any[]) {
return replacement.call(this, original, ...args);
} as any;
} as any);
Object.defineProperties(replacer, Object.getOwnPropertyDescriptors(original));
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 {
let called = false;
return function (this: any, ...args: any[]) {