Skip to content

Commit

Permalink
fix: #110
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Sep 10, 2023
1 parent 51d04da commit 8cb335a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions addon/prefs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/* eslint-disable no-undef */
pref("__prefsPrefix__.enable", true);
pref("__prefsPrefix__.input", "This is input");
pref("__prefsPrefix__.rulesInit", false);
18 changes: 11 additions & 7 deletions src/utils/rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from "../../package.json";
import { updateHint } from "./hint";
import { getPref, setPref } from "./prefs";

const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;

Expand Down Expand Up @@ -85,12 +86,15 @@ function initRules() {
addon.data.rules.data = new ztoolkit.LargePref(
`${config.prefsPrefix}.rules`,
`${config.prefsPrefix}.rules.`,
"parser",
"parser"
).asMapLike() as TagRuleMap;
for (const key of defaultRules.keys()) {
if (!Array.from(addon.data.rules.data.keys()).includes(key)) {
addon.data.rules.data.set(key, defaultRules.get(key)!);
if (!getPref("rulesInit")) {
for (const key of defaultRules.keys()) {
if (!Array.from(addon.data.rules.data.keys()).includes(key)) {
addon.data.rules.data.set(key, defaultRules.get(key)!);
}
}
setPref("rulesInit", true);
}
}

Expand Down Expand Up @@ -122,7 +126,7 @@ async function applyRule(rule: TagRule, data: TagRuleData) {
item.removeTag(tag);
}
message = `Remove tag ${tags.join(",")} from item ${item.getField(
"title",
"title"
)}`;
break;
}
Expand All @@ -135,7 +139,7 @@ async function applyRule(rule: TagRule, data: TagRuleData) {
}
}
message = `Toggle tag ${tags.join(",")} to item ${item.getField(
"title",
"title"
)}`;
break;
}
Expand All @@ -144,7 +148,7 @@ async function applyRule(rule: TagRule, data: TagRuleData) {
try {
const func = new AsyncFunction("item, data, require", script);
message = await func(item, data, (module: string) =>
ztoolkit.getGlobal(module),
ztoolkit.getGlobal(module)
);
} catch (e) {
ztoolkit.log("Script Error", e);
Expand Down

0 comments on commit 8cb335a

Please sign in to comment.