diff --git a/src/globals.d.ts b/src/globals.d.ts index 633fc66..8e2c24b 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -2,6 +2,7 @@ declare global { export var VencordDesktop: typeof import("./preload/VencordDesktop").VencordDesktop; // TODO export var Vencord: any; + export var vcdLS: typeof localStorage; } export { }; diff --git a/src/main/constants.ts b/src/main/constants.ts index 7c39526..7691b35 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -3,5 +3,8 @@ import { join } from "path"; export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR ?? join(app.getPath("userData"), "VencordDesktop"); export const VENCORD_FILES_DIR = join(DATA_DIR, "vencordDist"); +export const VENCORD_SETTINGS_DIR = join(DATA_DIR, "settings"); +export const VENCORD_QUICKCSS_FILE = join(VENCORD_SETTINGS_DIR, "quickCss.css"); +export const VENCORD_SETTINGS_FILE = join(VENCORD_SETTINGS_DIR, "settings.json"); export const USER_AGENT = `VencordDesktop/${app.getVersion()} (https://github.com/Vencord/Electron)`; diff --git a/src/main/ipc.ts b/src/main/ipc.ts index b22301b..1ee90b7 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -1,9 +1,10 @@ import { app, ipcMain, shell } from "electron"; -import { readFileSync } from "fs"; -import { readFile } from "fs/promises"; +import { readFileSync, watch } from "fs"; +import { open, readFile } from "fs/promises"; import { join } from "path"; +import { debounce } from "shared/utils/debounce"; import { FOCUS, GET_RENDERER_SCRIPT, GET_RENDERER_STYLES, GET_SETTINGS, GET_VENCORD_PRELOAD_FILE, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents"; -import { VENCORD_FILES_DIR } from "./constants"; +import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants"; import { mainWin } from "./mainWindow"; import { PlainSettings, setSettings } from "./settings"; @@ -37,3 +38,14 @@ ipcMain.handle(SHOW_ITEM_IN_FOLDER, (_, path) => { ipcMain.handle(FOCUS, () => { mainWin?.focus(); }); + +function readCss() { + return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => ""); +} + +open(VENCORD_QUICKCSS_FILE, "a+").then(fd => { + fd.close(); + watch(VENCORD_QUICKCSS_FILE, { persistent: false }, debounce(async () => { + mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss()); + }, 50)); +}); diff --git a/src/renderer/fixes.ts b/src/renderer/fixes.ts index 1b48907..582a6d5 100644 --- a/src/renderer/fixes.ts +++ b/src/renderer/fixes.ts @@ -1,5 +1,5 @@ import "./hideGarbage.css"; -import { isFirstRun } from "./utils"; +import { isFirstRun, localStorage } from "./utils"; // Make clicking Notifications focus the window const originalSetOnClick = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick")!.set!; @@ -15,6 +15,9 @@ Object.defineProperty(Notification.prototype, "onclick", { // Enable Desktop Notifications by default if (isFirstRun) { + // Hide "Download Discord Desktop now!!!!" banner + localStorage.setItem("hideNag", "true"); + Vencord.Webpack.waitFor("setDesktopType", m => { m.setDesktopType("all"); }); diff --git a/src/renderer/utils.ts b/src/renderer/utils.ts index da393fa..961a7fd 100644 --- a/src/renderer/utils.ts +++ b/src/renderer/utils.ts @@ -1,4 +1,4 @@ -export const localStorage = window.localStorage; +export const localStorage = window.vcdLS = window.localStorage; export const isFirstRun = (() => { const key = "VCD_FIRST_RUN"; diff --git a/src/shared/utils/debounce.ts b/src/shared/utils/debounce.ts new file mode 100644 index 0000000..f001b7b --- /dev/null +++ b/src/shared/utils/debounce.ts @@ -0,0 +1,7 @@ +export function debounce(func: T, delay = 300): T { + let timeout: NodeJS.Timeout; + return function (...args: any[]) { + clearTimeout(timeout); + timeout = setTimeout(() => { func(...args); }, delay); + } as any; +}