Debounce CssWatcher, fix empty tooltips in settings

This commit is contained in:
Vendicated 2022-09-02 16:15:47 +02:00
parent 02aeca6b73
commit 68057d49e8
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3
4 changed files with 14 additions and 6 deletions

View file

@ -43,7 +43,7 @@ export default ErrorBoundary.wrap(function Settings(props) {
</Flex.Child>
<Flex.Child>
<Button
onClick={() => VencordNative.ipc.invoke(IpcEvents.OPEN_PATH, settingsDir + "/quickCss.css")}
onClick={() => VencordNative.ipc.invoke(IpcEvents.OPEN_PATH, settingsDir, "quickCss.css")}
size={ButtonProps.ButtonSizes.SMALL}
disabled={settingsDir === "Loading..."}
>
@ -98,7 +98,7 @@ export default ErrorBoundary.wrap(function Settings(props) {
"This plugin is required. Thus you cannot disable it."
: dependency ?
`${humanFriendlyJoin(enabledDependants)} ${enabledDependants.length === 1 ? "depends" : "depend"} on this plugin. Thus you cannot disable it.`
: ""
: null
}
>
{p.name}

View file

@ -2,6 +2,7 @@ import { app, BrowserWindow, ipcMain, shell } from "electron";
import { mkdirSync, readFileSync, watch } from "fs";
import { open, readFile, writeFile } from "fs/promises";
import { join } from 'path';
import { debounce } from "./utils/debounce";
import IpcEvents from './utils/IpcEvents';
const DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
@ -25,7 +26,7 @@ function readSettings() {
ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR);
ipcMain.handle(IpcEvents.GET_QUICK_CSS, () => readCss());
ipcMain.handle(IpcEvents.OPEN_PATH, (_, path) => shell.openPath(path));
ipcMain.handle(IpcEvents.OPEN_PATH, (_, ...pathElements) => shell.openPath(join(...pathElements)));
ipcMain.handle(IpcEvents.OPEN_EXTERNAL, (_, url) => shell.openExternal(url));
// .on because we need Settings synchronously (ipcRenderer.sendSync)
@ -40,8 +41,8 @@ ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => {
export function initIpc(mainWindow: BrowserWindow) {
open(QUICKCSS_PATH, "a+").then(fd => {
fd.close();
watch(QUICKCSS_PATH, async () => {
watch(QUICKCSS_PATH, debounce(async () => {
mainWindow.webContents.postMessage(IpcEvents.QUICK_CSS_UPDATE, await readCss());
});
}, 50));
});
}

View file

@ -3,7 +3,7 @@ import definePlugin from "../utils/types";
export default definePlugin({
name: "NoTrack",
description: "Disable Discord's tracking and crash reporting",
author: "Vendicated",
author: "Cynosphere",
required: true,
patches: [
{

7
src/utils/debounce.ts Normal file
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;
}