Skip to content

Commit

Permalink
apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed Apr 9, 2023
1 parent df53ea5 commit ddebb65
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tabWidth: 4
semi: true
printWidth: 100
printWidth: 120
trailingComma: none
bracketSpacing: true
arrowParens: avoid
Expand Down
8 changes: 7 additions & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -8,4 +14,4 @@ declare global {
export var IS_DEV: boolean;
}

export { };
export {};
7 changes: 7 additions & 0 deletions src/main/about.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/constants.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
24 changes: 14 additions & 10 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
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";
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();
}
Expand All @@ -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();
});
});
Expand All @@ -65,6 +70,5 @@ async function createWindows() {
}

app.on("window-all-closed", () => {
if (process.platform !== "darwin")
app.quit();
if (process.platform !== "darwin") app.quit();
});
17 changes: 14 additions & 3 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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)
);
});
18 changes: 12 additions & 6 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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: {
Expand All @@ -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;
Expand All @@ -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`);

Expand Down
23 changes: 13 additions & 10 deletions src/main/settings.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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) {
Expand All @@ -37,7 +43,4 @@ export function setSettings(settings: TSettings) {
Settings = makeSettingsProxy(settings);
}

export {
PlainSettings,
PlainVencordSettings,
};
export { PlainSettings, PlainVencordSettings };
6 changes: 6 additions & 0 deletions src/main/splash.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
24 changes: 14 additions & 10 deletions src/main/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
/*
* 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
})
)
);
}

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);
});
Expand Down
10 changes: 9 additions & 1 deletion src/main/utils/makeLinksOpenExternally.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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" };
}
Expand All @@ -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:":
Expand Down
22 changes: 10 additions & 12 deletions src/main/utils/vencordLoader.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -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)))
);
}

Expand Down
12 changes: 9 additions & 3 deletions src/preload/VencordDesktopNative.ts
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand All @@ -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),
Expand All @@ -27,5 +34,4 @@ export const VencordDesktopNative = {
win: {
focus: () => invoke<void>(IpcEvents.FOCUS)
}
}

};
7 changes: 7 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Loading

0 comments on commit ddebb65

Please sign in to comment.