Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Jun 25, 2024
1 parent da6fa32 commit a11852d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ipcMain.on("LiteLoader.scriptio.removeScript", (event, absPath) => {
name: " [已删除] ",
description: "[此脚本已被删除]",
"run-at": [],
reactive: true
}
};
webContents.getAllWebContents().forEach((webContent) => {
Expand Down Expand Up @@ -100,7 +101,7 @@ ipcMain.handle("LiteLoader.scriptio.fetchText", async (event, ...args) => {

// 防抖
function debounce(fn, time) {
const timer = null;
let timer = null;
return function (...args) {
timer && clearTimeout(timer);
timer = setTimeout(() => {
Expand Down Expand Up @@ -145,23 +146,21 @@ function listJS(dir) {
return files;
}

const debouncedSet = debounce((slug, data) => {
LiteLoader.api.config.set(slug, data);
}, 1000);
const debouncedSet = debounce(LiteLoader.api.config.set, 1000);
const scriptsConfig = new Proxy({}, {
cache: null,
get(target, prop) {
if (!this.cache) {
log("Calling config.get");
this.cache = LiteLoader.api.config.get("scriptio", { "scripts": {} }).scripts;
this.cache = LiteLoader.api.config.get("scriptio", { scripts: {} }).scripts;
}
return this.cache[prop];
},
set(target, prop, value) {
this.cache[prop] = value;
log("Calling debounced config.set after set");
try {
debouncedSet("scriptio", { "scripts": this.cache });
debouncedSet("scriptio", { scripts: this.cache });
} catch (e) {
log("debouncedSet error", e);
}
Expand All @@ -172,7 +171,7 @@ const scriptsConfig = new Proxy({}, {
delete this.cache[prop];
console.log("Calling debounced config.set after delete");
try {
debouncedSet("scriptio", { "scripts": this.cache });
debouncedSet("scriptio", { scripts: this.cache });
} catch (e) {
log("debouncedSet error", e);
}
Expand Down

0 comments on commit a11852d

Please sign in to comment.