From f3a2ad4a629bbb410b1f46e42c7fa483545c1282 Mon Sep 17 00:00:00 2001 From: fofolee Date: Sat, 7 May 2022 00:53:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=88=86=E4=B8=BA=E9=80=9A=E7=94=A8=E5=92=8C=E6=9C=AC=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 57 +++++++++------------- src/components/CommandCard.vue | 6 +-- src/components/CommandEditor.vue | 9 ++-- src/components/ConfigurationMenu.vue | 2 +- src/components/popup/ShareDialog.vue | 9 ++-- src/components/popup/UserInfo.vue | 4 +- src/components/quickFeatures/ApiServer.vue | 6 +-- src/js/options/defaultProfile.js | 34 +++++++------ src/js/utools.js | 4 +- src/pages/ConfigurationPage.vue | 16 ++---- src/pages/ShareCenterPage.vue | 7 +-- src/pages/quickFeaturesPage.vue | 5 +- 12 files changed, 66 insertions(+), 93 deletions(-) diff --git a/src/App.vue b/src/App.vue index 0236583..ee57b65 100644 --- a/src/App.vue +++ b/src/App.vue @@ -21,7 +21,8 @@ export default defineComponent({ return { setCssVar: setCssVar, programs: programmings, - profile: defaultProfile, + profile: defaultProfile.common, + nativeProfile: defaultProfile.native, utools: UTOOLS, cronJobs: {}, enterData: {}, @@ -60,12 +61,14 @@ export default defineComponent({ // 处理旧版本数据 this.v2DataHandler(); // 读取用户配置 - let userProfile = this.utools.getDB( - this.utools.DBPRE.CFG + "preferences" + let commonProfile = this.utools.getDB("cfg_profile"); + let nativeProfile = this.utools.getDB( + "cfg_" + utools.getNativeId() + "_profile" ); - this.profile = _.merge( - _.cloneDeep(defaultProfile), - _.cloneDeep(userProfile) + this.profile = Object.assign(_.cloneDeep(this.profile), commonProfile); + this.nativeProfile = Object.assign( + _.cloneDeep(this.nativeProfile), + nativeProfile ); // 默认主题色 this.setCssVar("primary", this.profile.primaryColor); @@ -76,17 +79,12 @@ export default defineComponent({ if (window.multiProcessDetection()) return console.log("multiProcess Detected"); // 计划任务 - _.forIn(this.profile.crontabs, (cronExp, featureCode) => { + _.forIn(this.nativeProfile.crontabs, (cronExp, featureCode) => { this.runCronTask(featureCode, cronExp); }); // 快捷命令服务 - if (this.profile.quickFeatures.apiServer.serverStatus) { - window - .quickcommandHttpServer() - .run( - this.profile.quickFeatures.apiServer.cmd, - this.profile.apiServerPort - ); + if (this.nativeProfile.apiServerStatus) { + window.quickcommandHttpServer().run(this.profile.apiServerPort); console.log("Server Start..."); } }, @@ -98,9 +96,10 @@ export default defineComponent({ this.$router.push(enter.code); }, outPlugin() { + this.utools.putDB(_.cloneDeep(this.profile), "cfg_profile"); this.utools.putDB( - _.cloneDeep(this.profile), - this.utools.DBPRE.CFG + "preferences" + _.cloneDeep(this.nativeProfile), + "cfg_" + utools.getNativeId() + "_profile" ); this.$refs.view.$refs?.commandEditor?.saveCodeHistory(); this.$router.push("/"); @@ -111,7 +110,7 @@ export default defineComponent({ }); }, runCommandSilently(featureCode) { - let command = this.utools.getDB(this.utools.DBPRE.QC + featureCode); + let command = this.utools.getDB("qc_" + featureCode); if (command.program === "quickcommand") { window.runCodeInSandbox(command.cmd, () => {}); } else { @@ -125,9 +124,7 @@ export default defineComponent({ } }, usageStatistics(featureCode, runTime) { - let statisticsData = this.utools.getDB( - this.utools.DBPRE.CFG + "statisticsData" - ); + let statisticsData = this.utools.getDB("cfg_statisticsData"); let thisYear = runTime.year; if (!statisticsData[thisYear]) statisticsData[thisYear] = []; statisticsData[thisYear].push({ @@ -139,10 +136,7 @@ export default defineComponent({ minute: runTime.minute, }, }); - this.utools.putDB( - statisticsData, - this.utools.DBPRE.CFG + "statisticsData" - ); + this.utools.putDB(statisticsData, "cfg_statisticsData"); }, parseDate: (dateString) => { return { @@ -155,14 +149,10 @@ export default defineComponent({ }; }, v2DataHandler() { - let v2DataHandled = this.utools.getStorage( - this.utools.DBPRE.STATUS + "v2DataHandled" - ); + let v2DataHandled = this.utools.getStorage("st_v2DataHandled"); if (v2DataHandled) return; // 处理统计数据 - let statisticsData = this.utools.getDB( - this.utools.DBPRE.CFG + "statisticsData" - ); + let statisticsData = this.utools.getDB("cfg_statisticsData"); _.forIn(statisticsData, (data, year) => { statisticsData[year] = data.map((x) => { let code = @@ -173,13 +163,10 @@ export default defineComponent({ }; }); }); - this.utools.putDB( - statisticsData, - this.utools.DBPRE.CFG + "statisticsData" - ); + this.utools.putDB(statisticsData, "cfg_statisticsData"); // 处理历史代码 // ... - this.utools.setStorage(this.utools.DBPRE.STATUS + "v2DataHandled", true); + this.utools.setStorage("st_v2DataHandled", true); }, }, }); diff --git a/src/components/CommandCard.vue b/src/components/CommandCard.vue index a10d26d..a5a632c 100644 --- a/src/components/CommandCard.vue +++ b/src/components/CommandCard.vue @@ -320,7 +320,7 @@ export default { return this.commandInfo.features.code; }, cronExp() { - return this.$root.profile.crontabs[this.featureCode]; + return this.$root.nativeProfile.crontabs[this.featureCode]; }, }, props: { @@ -363,11 +363,11 @@ export default { this.$emit("commandChanged", event); }, addCrontab(cronExp) { - this.$root.profile.crontabs[this.featureCode] = cronExp; + this.$root.nativeProfile.crontabs[this.featureCode] = cronExp; this.$root.runCronTask(this.featureCode, cronExp); }, delCrontab() { - delete this.$root.profile.crontabs[this.featureCode]; + delete this.$root.nativeProfile.crontabs[this.featureCode]; this.$root.cronJobs[this.featureCode].stop(); }, // 启用/禁用命令 diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index d89aeed..380608f 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -301,7 +301,7 @@ export default { init() { let quickCommandInfo = this.action.type === "run" - ? this.$root.utools.getDB(this.$root.utools.DBPRE.CFG + "codeHistory") + ? this.$root.utools.getDB("cfg_codeHistory") : this.action.data; quickCommandInfo?.program && Object.assign(this.quickcommandInfo, _.cloneDeep(quickCommandInfo)); @@ -360,7 +360,7 @@ export default { let newQuickcommandInfo = _.cloneDeep(this.quickcommandInfo); this.$root.utools.putDB( newQuickcommandInfo, - this.$root.utools.DBPRE.QC + this.quickcommandInfo.features.code + "qc_" + this.quickcommandInfo.features.code ); this.$emit("editorEvent", { type: "save", @@ -380,10 +380,7 @@ export default { if (this.action.type !== "run") return; let command = _.cloneDeep(this.quickcommandInfo); command.cursorPosition = this.$refs.editor.getCursorPosition(); - this.$root.utools.putDB( - command, - this.$root.utools.DBPRE.CFG + "codeHistory" - ); + this.$root.utools.putDB(command, "cfg_codeHistory"); }, monacoKeyStroke(event) { switch (event) { diff --git a/src/components/ConfigurationMenu.vue b/src/components/ConfigurationMenu.vue index 2037b34..87777d6 100644 --- a/src/components/ConfigurationMenu.vue +++ b/src/components/ConfigurationMenu.vue @@ -457,7 +457,7 @@ export default { this.$root.utools.whole.setFeature(_.cloneDeep(this.features[type])); if (type === "apiServer" && !this.$root.profile.apiServerEnable) { window.quickcommandHttpServer().stop(); - this.$root.profile.quickFeatures.apiServer.serverStatus = false; + this.$root.nativeProfile.apiServerStatus = false; } }, }, diff --git a/src/components/popup/ShareDialog.vue b/src/components/popup/ShareDialog.vue index 0feb752..7aa88cd 100644 --- a/src/components/popup/ShareDialog.vue +++ b/src/components/popup/ShareDialog.vue @@ -155,7 +155,7 @@ export default { } }, showHelp() { - window.showUb.help('#rWU2i') + window.showUb.help("#rWU2i"); }, joinRepo() { quickcommand @@ -167,13 +167,10 @@ export default { }); }, loadYuQueInfo() { - return this.$root.utools.getDB(this.$root.utools.DBPRE.CFG + "extraInfo"); + return this.$root.utools.getDB("cfg_extraInfo"); }, saveYuQueInfo() { - this.$root.utools.putDB( - _.cloneDeep(this.yuQueInfo), - this.$root.utools.DBPRE.CFG + "extraInfo" - ); + this.$root.utools.putDB(_.cloneDeep(this.yuQueInfo), "cfg_extraInfo"); }, }, }; diff --git a/src/components/popup/UserInfo.vue b/src/components/popup/UserInfo.vue index 31a3436..3c619d9 100644 --- a/src/components/popup/UserInfo.vue +++ b/src/components/popup/UserInfo.vue @@ -170,9 +170,7 @@ export default { methods: { getUserInfo() { Object.assign(this.userInfo, this.$root.utools.whole.getUser()); - let statisticsData = this.$root.utools.getDB( - this.$root.utools.DBPRE.CFG + "statisticsData" - ); + let statisticsData = this.$root.utools.getDB("cfg_statisticsData"); this.userInfo.exp = Object.values(statisticsData) .map((x) => x.length) .reduce((x, y) => x + y); diff --git a/src/components/quickFeatures/ApiServer.vue b/src/components/quickFeatures/ApiServer.vue index b1bb5d2..494a08f 100644 --- a/src/components/quickFeatures/ApiServer.vue +++ b/src/components/quickFeatures/ApiServer.vue @@ -51,7 +51,7 @@ flat color="negative" icon="stop" - v-if="$root.profile.quickFeatures.apiServer.serverStatus" + v-if="$root.nativeProfile.apiServerStatus" @click="stopServer" label="停止服务" /> @@ -97,14 +97,14 @@ export default { "FBI WARNING" ) .then(() => { - this.$root.profile.quickFeatures.apiServer.serverStatus = true; + this.$root.nativeProfile.apiServerStatus = true; window.quickcommandHttpServer().run(this.$root.profile.apiServerPort); quickcommand.showMessageBox("启动服务成功!"); }); }, stopServer() { window.quickcommandHttpServer().stop(); - this.$root.profile.quickFeatures.apiServer.serverStatus = false; + this.$root.nativeProfile.apiServerStatus = false; quickcommand.showMessageBox("关闭服务成功!"); }, saveCode() { diff --git a/src/js/options/defaultProfile.js b/src/js/options/defaultProfile.js index 08af8ab..d2f51d6 100644 --- a/src/js/options/defaultProfile.js +++ b/src/js/options/defaultProfile.js @@ -1,16 +1,22 @@ export default { - commandCardStyle: "normal", - primaryColor: "#009688", - defaultPrimaryColor: "#009688", - backgroundImg: null, - autofocusSearch: false, - denseTagBar: false, - quickFileEnable: false, - quickFileTag: "文件", - quickUrlEnable: false, - quickUrlTag: "网址", - pluNickNameEnable: false, - pluNickNameTag: "别名", - apiServerEnable: false, - apiServerPort: 33442, + common: { + commandCardStyle: "normal", + primaryColor: "#009688", + defaultPrimaryColor: "#009688", + backgroundImg: null, + autofocusSearch: false, + denseTagBar: false, + quickFileEnable: false, + quickFileTag: "文件", + quickUrlEnable: false, + quickUrlTag: "网址", + pluNickNameEnable: false, + pluNickNameTag: "别名", + apiServerEnable: false, + apiServerPort: 33442, + }, + native: { + crontabs: {}, + apiServerStatus: false + } } \ No newline at end of file diff --git a/src/js/utools.js b/src/js/utools.js index 0db6ed8..7df6e84 100644 --- a/src/js/utools.js +++ b/src/js/utools.js @@ -10,7 +10,7 @@ let whole = window.utools const DBPRE = { QC: 'qc_', // 快捷命令 CFG: 'cfg_', // 配置 - PAN: 'pan_', // 面板视图 + PAN: 'panel_', // 面板视图 STATUS: 'st_', // 状态变量 USR: 'usr_' // 用户数据 } @@ -85,5 +85,5 @@ export default { setStorage, getStorage, userData, - DBPRE, + getDocs, } \ No newline at end of file diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue index d8174db..791dc2e 100644 --- a/src/pages/ConfigurationPage.vue +++ b/src/pages/ConfigurationPage.vue @@ -339,10 +339,7 @@ export default { }, importDefaultCommands() { for (var code of Object.keys(defaultCommands)) { - this.$root.utools.putDB( - defaultCommands[code], - this.$root.utools.DBPRE.QC + code - ); + this.$root.utools.putDB(defaultCommands[code], "qc_" + code); } Object.assign(this.allQuickCommands, defaultCommands); }, @@ -365,7 +362,7 @@ export default { getAllQuickCommands() { let allQcs = {}; this.$root.utools - .getDocs(this.$root.utools.DBPRE.QC) + .getDocs("qc_") .forEach((x) => (allQcs[x.data.features.code] = x.data)); return allQcs; }, @@ -413,7 +410,7 @@ export default { removeCommand(code) { utools.copyText(JSON.stringify(this.allQuickCommands[code], null, 4)); delete this.allQuickCommands[code]; - this.$root.utools.delDB(this.$root.utools.DBPRE.QC + code); + this.$root.utools.delDB("qc_" + code); this.disableCommand(code); if (!this.allQuickCommandTags.includes(this.currentTag)) this.currentTag = "默认"; @@ -463,10 +460,7 @@ export default { dataToPushed = parsedData.qc; } for (var code of Object.keys(dataToPushed)) { - this.$root.utools.putDB( - dataToPushed[code], - this.$root.utools.DBPRE.QC + code - ); + this.$root.utools.putDB(dataToPushed[code], "qc_" + code); } Object.assign(this.allQuickCommands, dataToPushed); quickcommand.showMessageBox("导入成功!"); @@ -524,7 +518,7 @@ export default { return quickcommand.showMessageBox("取消操作", "info"); this.exportAllCommands(false); this.$root.utools - .getDocs(this.$root.utools.DBPRE.QC) + .getDocs("qc_") .map((x) => x._id) .forEach((y) => this.$root.utools.delDB(y)); this.importDefaultCommands(); diff --git a/src/pages/ShareCenterPage.vue b/src/pages/ShareCenterPage.vue index 407f997..965fa2e 100644 --- a/src/pages/ShareCenterPage.vue +++ b/src/pages/ShareCenterPage.vue @@ -192,10 +192,7 @@ export default { this.installedCodes.push(code); let pushData = _.cloneDeep(command); pushData.fromShare = true; - this.$root.utools.putDB( - _.cloneDeep(pushData), - this.$root.utools.DBPRE.QC + code - ); + this.$root.utools.putDB(_.cloneDeep(pushData), "qc_" + code); // 通过模拟访问页面来统计下载量 utools.ubrowser .goto(`https://www.yuque.com/${this.releaseRepo}/${code}`) @@ -242,7 +239,7 @@ export default { checkCommands() { let installed = []; let needUpdate = []; - this.$root.utools.getDocs(this.$root.utools.DBPRE.QC).forEach((item) => { + this.$root.utools.getDocs("qc_").forEach((item) => { if (!item.data.fromShare) return; let code = item._id.slice(3); let remote = this.remoteCommands.filter((cmd) => cmd.slug === code)[0]; diff --git a/src/pages/quickFeaturesPage.vue b/src/pages/quickFeaturesPage.vue index e7f5ae3..52004a0 100644 --- a/src/pages/quickFeaturesPage.vue +++ b/src/pages/quickFeaturesPage.vue @@ -24,10 +24,7 @@ export default { methods: { importCommand(command) { command = _.cloneDeep(command); - this.$root.utools.putDB( - command, - this.$root.utools.DBPRE.QC + command.features.code - ); + this.$root.utools.putDB(command, "qc_" + command.features.code); this.$root.utools.whole.setFeature(command.features); }, getUid() {