diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 276d855..27dcbb8 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -1,6 +1,6 @@ tabWidth: 4 semi: true -printWidth: 100 +printWidth: 120 trailingComma: none bracketSpacing: true arrowParens: avoid diff --git a/src/globals.d.ts b/src/globals.d.ts index 7bf4e4e..606f4f5 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -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 {}; diff --git a/src/main/about.ts b/src/main/about.ts index 099eab4..4daf965 100644 --- a/src/main/about.ts +++ b/src/main/about.ts @@ -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() { diff --git a/src/main/constants.ts b/src/main/constants.ts index 7099f09..96c9970 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -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"; diff --git a/src/main/index.ts b/src/main/index.ts index cef8166..cf51e33 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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(); }); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 3f2c35b..3bdaf98 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -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) + ); }); diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index e1d3e2a..e214a0c 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -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`); diff --git a/src/main/settings.ts b/src/main/settings.ts index 0bd6ade..507046a 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -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(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(SETTINGS_FILE, "VencordDesktop"); export let Settings = makeSettingsProxy(PlainSettings); -let [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings(VENCORD_SETTINGS_FILE, "Vencord"); +const [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings(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 }; diff --git a/src/main/splash.ts b/src/main/splash.ts index d426b52..6c21c6c 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -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"; diff --git a/src/main/utils/http.ts b/src/main/utils/http.ts index fcbbb74..fc50410 100644 --- a/src/main/utils/http.ts +++ b/src/main/utils/http.ts @@ -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((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); }); diff --git a/src/main/utils/makeLinksOpenExternally.ts b/src/main/utils/makeLinksOpenExternally.ts index bfd83b2..59e8593 100644 --- a/src/main/utils/makeLinksOpenExternally.ts +++ b/src/main/utils/makeLinksOpenExternally.ts @@ -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:": diff --git a/src/main/utils/vencordLoader.ts b/src/main/utils/vencordLoader.ts index 8964604..5f17add 100644 --- a/src/main/utils/vencordLoader.ts +++ b/src/main/utils/vencordLoader.ts @@ -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))) ); } diff --git a/src/preload/VencordDesktopNative.ts b/src/preload/VencordDesktopNative.ts index 88f1a22..a62e5ac 100644 --- a/src/preload/VencordDesktopNative.ts +++ b/src/preload/VencordDesktopNative.ts @@ -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(event: IpcEvents, ...args: any[]) { @@ -18,7 +25,7 @@ export const VencordDesktopNative = { }, fileManager: { showItemInFolder: (path: string) => invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path), - selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR), + selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR) }, settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), @@ -27,5 +34,4 @@ export const VencordDesktopNative = { win: { focus: () => invoke(IpcEvents.FOCUS) } -} - +}; diff --git a/src/preload/index.ts b/src/preload/index.ts index 8f93b21..039357a 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -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"; diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index c545a97..dd957ba 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -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 - - Discord Branch - + Discord Branch