Skip to content

Commit

Permalink
Bug fixes; Code optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Jun 25, 2024
1 parent 345f838 commit 41381e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
22 changes: 7 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ipcMain.handle("LiteLoader.transitio.queryIsDebug", async (event) => {

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

const debouncedSet = debounce(LiteLoader.api.config.set, 1000); // Adjust debounce time as needed
let stylesConfig = new Proxy({}, {
const debouncedSet = debounce(LiteLoader.api.config.set, 1000);
const stylesConfig = new Proxy({}, {
cache: null,
get(target, prop) {
if (!this.cache) {
log("Calling config.get");
this.cache = LiteLoader.api.config.get("transitio", { "styles": {} }).styles;
this.cache = LiteLoader.api.config.get("transitio", { styles: {} }).styles;
}
return this.cache[prop];
},
set(target, prop, value) {
this.cache[prop] = value;
log("Calling debounced config.set after set");
try {
debouncedSet("transitio", { "styles": this.cache });
debouncedSet("transitio", { styles: this.cache });
} catch (e) {
log("debouncedSet error", e);
}
Expand All @@ -142,7 +142,7 @@ let stylesConfig = new Proxy({}, {
delete this.cache[prop];
console.log("Calling debounced config.set after delete");
try {
debouncedSet("transitio", { "styles": this.cache });
debouncedSet("transitio", { styles: this.cache });
} catch (e) {
log("debouncedSet error", e);
}
Expand Down Expand Up @@ -183,14 +183,8 @@ function extractUserStyleMetadata(css) {
}
});
} else { // Fall back to the old method
let comment = getDesc(css) || "";
let disabled = false;
if (comment.endsWith("[Disabled]")) {
comment = comment.slice(0, -10).trim();
disabled = true;
}
const comment = getDesc(css) || "";
result["description"] = comment;
result["disabled"] = disabled;
}

return result;
Expand Down Expand Up @@ -278,9 +272,7 @@ function onStyleChange(eventType, filename) {
function onConfigChange(event, absPath, enable) {
log("onConfigChange", absPath, enable);
stylesConfig[absPath] = enable;
log("onConfigChange2", devMode);
if (!devMode) {
log("onConfigChange3", absPath, enable);
updateStyle(absPath);
}
}
Expand Down
11 changes: 5 additions & 6 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,20 @@

/* 悬浮显示的按钮 */
.transitio .transitio-more {
color: var(--icon_secondary);
opacity: 0;
transition: color 0.2s ease-in-out, opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
font-family: system-ui, PingFang SC, PingFangSC-Regular, Microsoft YaHei, Hiragino Sans GB, Heiti SC, WenQuanYi Micro Hei, sans-serif, Apple Braille;
}

.transitio setting-item:not([data-deleted]):hover .transitio-more {
opacity: 0.6;

&:hover {
color: var(--theme-color);
transform: scale(1.2);
opacity: 1;
}
}

.transitio setting-item:not([data-deleted]):hover .transitio-more {
opacity: 1;
}

/* Logo */
.transitio .logo {
position: fixed;
Expand Down

0 comments on commit 41381e1

Please sign in to comment.