Make QuickCSS work

This commit is contained in:
Vendicated 2023-04-05 20:01:31 +02:00
parent 1980606e03
commit 19c43289f6
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
6 changed files with 31 additions and 5 deletions

1
src/globals.d.ts vendored
View file

@ -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 { };

View file

@ -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)`;

View file

@ -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));
});

View file

@ -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");
});

View file

@ -1,4 +1,4 @@
export const localStorage = window.localStorage;
export const localStorage = window.vcdLS = window.localStorage;
export const isFirstRun = (() => {
const key = "VCD_FIRST_RUN";

View file

@ -0,0 +1,7 @@
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);
} as any;
}