diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bdfcb2..d2c6c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,10 @@ -### 🔄 Other Changes - * util 由 `submodule` 更改为 `package` +### 🛠️ Bug Fixes + * 修复 `$argument` 和 `$persistentStore` 载入顺序颠倒的问题 + * 正确顺序为先读取 `$argument` 再读取 `$persistentStore (BoxJs)` + * 即,有相同键名时,`$persistentStore (BoxJs)` 的值会覆盖 `$argument` 的值 + +### 🔣 Dependencies + * 升级了 `@nsnanocat/util` + * `util` 由 `submodule` 更改为 `package` + * `$platform` 改为 `$app` + * 使用了全新的 `Console` polyfill diff --git a/src/Microsoft.Translate.dev.js b/src/Microsoft.Translate.dev.js index 2326d00..1d9f724 100644 --- a/src/Microsoft.Translate.dev.js +++ b/src/Microsoft.Translate.dev.js @@ -1,4 +1,4 @@ -import { $platform, Lodash as _, URL, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import database from "./function/database.mjs"; import setENV from "./function/setENV.mjs"; const $request = { @@ -15,26 +15,17 @@ const $request = { * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database); - log(`⚠ Settings.Switch: ${Settings?.Switch}`, ""); - switch (Settings.Switch) { - case true: - default: { - const $response = await fetch($request); - _.set(Settings, "Vendor", "Microsoft"); - _.set(Settings, "Microsoft.Version", "Azure"); - _.set(Settings, "Microsoft.Mode", "Token"); - _.set(Settings, "Microsoft.Token", $response?.body); - log(`⚠ Settings: ${JSON.stringify(Settings)}`, ""); - // 写入缓存 - Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token); - break; - } - case false: - break; - } + const $response = await fetch($request); + _.set(Settings, "Vendor", "Microsoft"); + _.set(Settings, "Microsoft.Version", "Azure"); + _.set(Settings, "Microsoft.Mode", "Token"); + _.set(Settings, "Microsoft.Token", $response?.body); + lConsole.info(`Settings: ${JSON.stringify(Settings)}`); + // 写入缓存 + Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token); })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done()); diff --git a/src/Microsoft.Translate.js b/src/Microsoft.Translate.js index 2326d00..72d8bfe 100644 --- a/src/Microsoft.Translate.js +++ b/src/Microsoft.Translate.js @@ -1,4 +1,4 @@ -import { $platform, Lodash as _, URL, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util"; +import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util"; import database from "./function/database.mjs"; import setENV from "./function/setENV.mjs"; const $request = { @@ -15,26 +15,17 @@ const $request = { * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database); - log(`⚠ Settings.Switch: ${Settings?.Switch}`, ""); - switch (Settings.Switch) { - case true: - default: { - const $response = await fetch($request); - _.set(Settings, "Vendor", "Microsoft"); - _.set(Settings, "Microsoft.Version", "Azure"); - _.set(Settings, "Microsoft.Mode", "Token"); - _.set(Settings, "Microsoft.Token", $response?.body); - log(`⚠ Settings: ${JSON.stringify(Settings)}`, ""); - // 写入缓存 - Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode); - Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token); - break; - } - case false: - break; - } + const $response = await fetch($request); + _.set(Settings, "Vendor", "Microsoft"); + _.set(Settings, "Microsoft.Version", "Azure"); + _.set(Settings, "Microsoft.Mode", "Token"); + _.set(Settings, "Microsoft.Token", $response?.body); + Console.info(`Settings: ${JSON.stringify(Settings)}`); + // 写入缓存 + Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode); + Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token); })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done()); diff --git a/src/function/database.mjs b/src/function/database.mjs index 8c01761..c5fbdf6 100644 --- a/src/function/database.mjs +++ b/src/function/database.mjs @@ -1,7 +1,6 @@ export default { "Default": { "Settings": { - "Switch": true, "Type": "Translate", "Types": [ "Official", diff --git a/src/function/setENV.mjs b/src/function/setENV.mjs index 13ad1a2..ea507a3 100644 --- a/src/function/setENV.mjs +++ b/src/function/setENV.mjs @@ -1,4 +1,4 @@ -import { Lodash as _, getStorage, log } from "@nsnanocat/util"; +import { Console, getStorage, Lodash as _ } from "@nsnanocat/util"; /** * Set Environment Variables @@ -9,17 +9,20 @@ import { Lodash as _, getStorage, log } from "@nsnanocat/util"; * @return {Object} { Settings, Caches, Configs } */ export default function setENV(name, platforms, database) { - log("☑️ Set Environment Variables", ""); + Console.log("☑️ Set Environment Variables"); const { Settings, Caches, Configs } = getStorage(name, platforms, database); /***************** Settings *****************/ if (!Array.isArray(Settings?.Types)) Settings.Types = (Settings.Types) ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔 - log(`✅ Set Environment Variables, Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`, ""); + Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`); /***************** Caches *****************/ + //Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`); if (typeof Caches?.Playlists !== "object" || Array.isArray(Caches?.Playlists)) Caches.Playlists = {}; // 创建Playlists缓存 Caches.Playlists.Master = new Map(JSON.parse(Caches?.Playlists?.Master || "[]")); // Strings转Array转Map Caches.Playlists.Subtitle = new Map(JSON.parse(Caches?.Playlists?.Subtitle || "[]")); // Strings转Array转Map if (typeof Caches?.Subtitles !== "object") Caches.Subtitles = new Map(JSON.parse(Caches?.Subtitles || "[]")); // Strings转Array转Map - //log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, ""); + if (typeof Caches?.Metadatas !== "object" || Array.isArray(Caches?.Metadatas)) Caches.Metadatas = {}; // 创建Playlists缓存 + if (typeof Caches?.Metadatas?.Tracks !== "object") Caches.Metadatas.Tracks = new Map(JSON.parse(Caches?.Metadatas?.Tracks || "[]")); // Strings转Array转Map /***************** Configs *****************/ + Console.log("✅ Set Environment Variables"); return { Settings, Caches, Configs }; }; diff --git a/src/types.d.ts b/src/types.d.ts index eebbf87..2d070bc 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,10 +1,2 @@ export interface Settings { - /** - * 总功能开关 - * - * 是否启用此APP修改 - * - * @defaultValue true - */ - Switch?: boolean; } diff --git a/template/boxjs.settings.json b/template/boxjs.settings.json index 8faed64..0637a08 100644 --- a/template/boxjs.settings.json +++ b/template/boxjs.settings.json @@ -1 +1 @@ -[{"id":"@DualSubs.AddOn.Settings.Switch","name":"总功能开关","type":"boolean","val":true,"desc":"是否启用此APP修改"}] \ No newline at end of file +[] \ No newline at end of file diff --git a/template/egern.handlebars b/template/egern.handlebars deleted file mode 100644 index 78fc8da..0000000 --- a/template/egern.handlebars +++ /dev/null @@ -1,26 +0,0 @@ -name: "{{@package 'displayName'}} (Microsoft Translate)" -description: |- - {{#each (split (@package 'description') "\n")}} - {{{this}}} - {{/each}} - 切换为微软翻译并自动刷新Token -open_url: "{{@package 'openUrl'}}" -author: |- - {{#each (@package 'contributors')}} - {{this}} - {{/each}} -homepage: "{{@package 'homepage'}}" -icon: "{{@package 'icon'}}" -category: "{{@package 'organizationName'}}" -date: "{{now "yyyy-MM-dd HH:mm:ss"}}" -version: "{{@package 'version'}}" -compat_arguments: - cronexp: '*/10 * * * *' -compat_arguments_desc: 'cronexp: * * * * * *\n │ │ │ │ │ └── 星期几 (0 - 6, 星期天 = 0)\n │ │ │ │ └──── 月份 (1 - 12)\n │ │ │ └────── 天数 (1 - 31)\n │ │ └──────── 小时 (0 - 23)\n │ └────────── 分钟 (0 - 59)\n └──────────── [可选] 秒 (0 - 59)' - -scriptings: -- schedule: - name: 🍿️ DualSubs.AddOn.Microsoft.Translate - cron: '{{{cronexp}}}' - script_url: https://github.com/DualSubs/AddOn/releases/download/v{{@package 'version'}}/Microsoft.Translate.bundle.js - timeout: 60