From bea4bdd212eb76e79534ec4c969635bc0c52d157 Mon Sep 17 00:00:00 2001 From: baiy Date: Mon, 16 Aug 2021 13:19:01 +0800 Subject: [PATCH] 1.7.1 submit --- .gitignore | 2 +- README.md | 4 ++ package-lock.json | 13 +++--- package.json | 4 +- src/adapter/chrome/manifest.json | 11 +++-- src/adapter/chromium/background.html | 14 ------ src/adapter/chromium/background.js | 3 +- src/adapter/chromium/helper.js | 3 ++ src/adapter/edge/manifest.json | 11 +++-- src/background.js | 55 ---------------------- src/helper.js | 4 +- src/tool.js | 37 +++++++++++---- src/tool/adapter.js | 11 ++--- src/tool/cache.js | 69 ++++++++++++++++++++-------- src/tool/config.js | 3 +- vue.config.js | 6 --- 16 files changed, 120 insertions(+), 130 deletions(-) delete mode 100644 src/adapter/chromium/background.html delete mode 100644 src/background.js diff --git a/.gitignore b/.gitignore index 6ce2895..d0048ea 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,4 @@ yarn-error.log* *.sln *.sw* test.js -/public/background.html +/public/background.js diff --git a/README.md b/README.md index fadd84e..3009d61 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ ![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png) +## 在线使用 + + + ## chrome 安装 - 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装 diff --git a/package-lock.json b/package-lock.json index b3e4d4f..6686193 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "c-tool", - "version": "1.6.8", + "version": "1.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -7286,11 +7286,6 @@ "yallist": "^3.0.2" } }, - "lscache": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/lscache/-/lscache-1.3.0.tgz", - "integrity": "sha512-0JwzMSSu3fd3m8QQVbqIxzXywkNLQvgdNehuEtZ66v7f89ybpkZX+WN45SkvChP4AqUPSpDPJKHsAqStOhHgUA==" - }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -11820,6 +11815,12 @@ "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", "dev": true }, + "utools-api-types": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/utools-api-types/-/utools-api-types-2.0.6.tgz", + "integrity": "sha512-XahJpUEdlraIBJ9VEt26w4JqUQqcXjk+uZvUfyn5MCZj3i2eypMTdC8aRif8obhEPTqgXK5E6ZqJhUl28l+Wfg==", + "dev": true + }, "uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", diff --git a/package.json b/package.json index 1ba95fc..3ac2bbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "c-tool", - "version": "1.6.9", + "version": "1.7.1", "private": true, "scripts": { "serve": "vue-cli-service serve --port 8081", @@ -26,7 +26,6 @@ "jsonlint": "^1.6.3", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", - "lscache": "^1.3.0", "mime-types": "^2.1.32", "moment": "^2.29.1", "php-array-reader": "^1.3.0", @@ -56,6 +55,7 @@ "eslint-plugin-vue": "^5.2.3", "less": "^2.7.3", "less-loader": "^5.0.0", + "utools-api-types": "^2.0.6", "vue-cli-plugin-iview": "^1.0.6", "vue-template-compiler": "^2.6.14" }, diff --git a/src/adapter/chrome/manifest.json b/src/adapter/chrome/manifest.json index 83379c0..ce53476 100644 --- a/src/adapter/chrome/manifest.json +++ b/src/adapter/chrome/manifest.json @@ -5,14 +5,14 @@ "author": "wo@baiy.org", "offline_enabled": true, "homepage_url": "https://github.com/baiy/Ctool", - "manifest_version": 2, - "browser_action": { + "manifest_version": 3, + "action": { "default_icon": "img/icon_chrome.png", "default_title": "常用开发工具", "default_popup": "index.html" }, "background": { - "page": "background.html" + "service_worker": "background.js" }, "icons": { "16": "img/icon_chrome.png", @@ -21,11 +21,14 @@ }, "permissions": [ "clipboardWrite", - "clipboardRead", + "clipboardRead" + ], + "host_permissions": [ "*://ifconfig.co/*", "*://*.baiy.org/*" ], "commands": { + "_execute_browser_action": {}, "panel": { "description": "打开独立工具窗口", "global": true diff --git a/src/adapter/chromium/background.html b/src/adapter/chromium/background.html deleted file mode 100644 index 1ca7ec5..0000000 --- a/src/adapter/chromium/background.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - Ctool 程序开发常用工具 - - -
-
-
- - \ No newline at end of file diff --git a/src/adapter/chromium/background.js b/src/adapter/chromium/background.js index a5581e2..3da1725 100644 --- a/src/adapter/chromium/background.js +++ b/src/adapter/chromium/background.js @@ -1,6 +1,7 @@ let windowId = null; // 打开独立窗口 const panel = { + cacheName: "background:panel:window_id", create() { chrome.windows.create({ url: chrome.runtime.getURL("tool.html"), @@ -49,4 +50,4 @@ chrome.commands.onCommand.addListener((command) => { // 窗口关闭事件 chrome.windows.onRemoved.addListener((id) => { panel.onRemoved(id); -}) +}) \ No newline at end of file diff --git a/src/adapter/chromium/helper.js b/src/adapter/chromium/helper.js index 77776fe..81de9ee 100644 --- a/src/adapter/chromium/helper.js +++ b/src/adapter/chromium/helper.js @@ -1,5 +1,8 @@ export const openUrl = (url) => { // return chrome.tabs.create(); // return chrome.windows.create(); + if (url.indexOf('chrome://') === 0){ + return chrome.tabs.create({url:url}); + } return window.open(url); } \ No newline at end of file diff --git a/src/adapter/edge/manifest.json b/src/adapter/edge/manifest.json index 96cc9c3..6a84db3 100644 --- a/src/adapter/edge/manifest.json +++ b/src/adapter/edge/manifest.json @@ -5,14 +5,14 @@ "author": "wo@baiy.org", "offline_enabled": true, "homepage_url": "https://github.com/baiy/Ctool", - "manifest_version": 2, - "browser_action": { + "manifest_version": 3, + "action": { "default_icon": "img/icon_chrome.png", "default_title": "常用开发工具", "default_popup": "index.html" }, "background": { - "page": "background.html" + "service_worker": "background.js" }, "icons": { "16": "img/icon_chrome.png", @@ -21,11 +21,14 @@ }, "permissions": [ "clipboardWrite", - "clipboardRead", + "clipboardRead" + ], + "host_permissions": [ "*://ifconfig.co/*", "*://*.baiy.org/*" ], "commands": { + "_execute_browser_action": {}, "panel": { "description": "打开独立工具窗口", "global": true diff --git a/src/background.js b/src/background.js deleted file mode 100644 index d18d31f..0000000 --- a/src/background.js +++ /dev/null @@ -1,55 +0,0 @@ -import cache from './tool/cache' -// 打开独立窗口 -const panel = { - cacheName: "background:panel:window_id", - create() { - chrome.windows.create({ - url: chrome.runtime.getURL("tool.html"), - type: "popup", - width: 810, - left: 200, - top: 200, - height: 610, - }, (w) => { - cache.set(this.cacheName, w.id) - }) - }, - open() { - let windowId = cache.get(this.cacheName) - if (windowId === null) { - this.create() - } else { - chrome.windows.get(windowId, (w) => { - if (!w) { - this.create() - } else { - chrome.windows.update(windowId, {focused: true}) - } - }) - } - - }, - onRemoved(id) { - if (id === cache.get(this.cacheName)) { - cache.remove(this.cacheName) - } - } -} - -// 注册快捷键 -chrome.commands.onCommand.addListener((command) => { - switch (command) { - case "panel": - panel.open() - - break; - default: - return; - } -}) - -// 窗口关闭事件 -chrome.windows.onRemoved.addListener((id) => { - panel.onRemoved(id); -}) - diff --git a/src/helper.js b/src/helper.js index 0d7f6e3..7b6fcb7 100644 --- a/src/helper.js +++ b/src/helper.js @@ -24,4 +24,6 @@ export const openUrl = (url) => { return utoolsOpenUrl(url) } return window.open(url); -}; \ No newline at end of file +}; + +export const version = env('version').trim() \ No newline at end of file diff --git a/src/tool.js b/src/tool.js index bce5867..bcda09f 100644 --- a/src/tool.js +++ b/src/tool.js @@ -4,9 +4,28 @@ import './statics/theme.less' import router from './tool.router' import optionBlock from './components/optionBlock' import {plugin as modelPlugin} from './tool/model' +import cache from './tool/cache' import App from './tool.vue' import {isUtools} from './helper' +const run = () => { + Vue.config.productionTip = false + + Vue.use(ViewUI) + Vue.use(modelPlugin) + Vue.component('option-block', optionBlock); + + new Vue({ + router, + render: h => h(App), + }).$mount('#app') + + // 清理缓存数据 + setTimeout(() => { + cache.clear() + }, 500) +} + (function () { if (document.body.clientWidth > 900 || isUtools) { console.log('调整窗口大小') @@ -15,15 +34,15 @@ import {isUtools} from './helper' page.style.height = 'auto' page.style.minHeight = '550px' } + if (isUtools) { + window.utools.onPluginReady(() => { + // 重设高度 + window.utools.setExpendHeight(582) + run() + }) + } else { + run() + } })() -Vue.config.productionTip = false - -Vue.use(ViewUI) -Vue.use(modelPlugin) -Vue.component('option-block', optionBlock); -new Vue({ - router, - render: h => h(App), -}).$mount('#app') diff --git a/src/tool/adapter.js b/src/tool/adapter.js index cdb9351..a4f61a7 100644 --- a/src/tool/adapter.js +++ b/src/tool/adapter.js @@ -51,16 +51,16 @@ const edgeConfigWrite = () => { const chromiumConfigWrite = () => { // 移除环境配置文件 removeFile(path.join(__dirname, '../../public/manifest.json')); - let backgroundPath = path.join(__dirname, '../../public/background.html'); + let backgroundPath = path.join(__dirname, '../../public/background.js'); removeFile(backgroundPath); if (IS_CHROMIUM) { - fs.copyFileSync(path.join(__dirname, "../adapter/chromium/background.html"), backgroundPath); + fs.copyFileSync(path.join(__dirname, "../adapter/chromium/background.js"), backgroundPath); } } const utoolsConfigWrite = () => { // 移除环境配置文件 - let fileArr = ['plugin.json', 'README.md'] + let fileArr = ['plugin.json'] fileArr.forEach((file) => { let filePath = path.join(__dirname, '../../public/' + file); removeFile(filePath); @@ -118,7 +118,6 @@ const utoolsConfigWrite = () => { utoolsToolFeature[toolFeatureCode].cmds.push(cmd) } } - } let features = [ @@ -135,10 +134,6 @@ const utoolsConfigWrite = () => { .replace(/"##features##"/g, JSON.stringify(features)); fs.writeFileSync(pluginPath, result); }); - let readmePath = path.join(__dirname, '../../public/README.md'); - fs.copyFile(path.join(__dirname, "../../README.md"), readmePath, function (err) { - if (err) return console.log(err); - }); } } diff --git a/src/tool/cache.js b/src/tool/cache.js index fd97732..db0364d 100644 --- a/src/tool/cache.js +++ b/src/tool/cache.js @@ -1,28 +1,61 @@ -import lsCache from 'lscache' -import p from '../../package' +import db from './db' +import {version} from '../helper' + +const cacheVersion = version.split('.').join(''); // 缓存key添加版本号 const cacheNameConvert = function (name) { - return 'v_' + (p.version.split('.').join('')) + '_' + name + return 'v_' + cacheVersion + '_' + name } -export default { - // expiry 过期时间 秒 - set (name, value, expiry = 0) { - return lsCache.set(cacheNameConvert(name), value, expiry / 60) +const cache = { + set(name, value, expiry = 0) { + return db.set(cacheNameConvert(name), value, expiry) + }, + get(name, defaultValue = null) { + let data = db.get(cacheNameConvert(name)) + return data === null ? defaultValue : data }, - get (name, defaultValue = null) { - let data = lsCache.get(cacheNameConvert(name)) - return data ? data : defaultValue + remove(name) { + db.remove(cacheNameConvert(name)) + return db.remove(cacheNameConvert(name)) }, - remove (name) { - lsCache.remove(cacheNameConvert(name)) + setNoVersion(name, value, expiry = 0) { + return db.set('nv_' + name, value, expiry) }, - setNoVersion (name, value, expiry = 0) { - return lsCache.set('nv_' + name, value, expiry / 60) + getNoVersion(name, defaultValue = null) { + let data = db.get('nv_' + name) + return data === null ? defaultValue : data }, - getNoVersion (name, defaultValue = null) { - let data = lsCache.get('nv_' + name) - return data ? data : defaultValue + removeNoVersion(name) { + return db.remove('nv_' + name) }, -} \ No newline at end of file + // 清理数据 + clear() { + setTimeout(() => { + // 清理过期数据 + db.clear(); + // 清理过期版本数据 + clearExpireVersion(); + }, 100); + } +}; + +const clearExpireVersion = () => { + const cache_version_name = "cache_version"; + if (cacheVersion === cache.getNoVersion(cache_version_name)) { + return; + } + cache.setNoVersion(cache_version_name, cacheVersion) + for (let key of db.getAllKey()) { + let c = /^v_(\d+)_/.exec(key) + if (c === null) { + continue; + } + if (cacheVersion !== c[1].trim()) { + db.remove(key) + } + } +} + +export default cache \ No newline at end of file diff --git a/src/tool/config.js b/src/tool/config.js index 2cbef33..8d5c7f7 100644 --- a/src/tool/config.js +++ b/src/tool/config.js @@ -82,9 +82,10 @@ export default { getToolTitle, getUserCommon, getToolByCategory(cat) { + let common = getUserCommon(); return tool.filter((t) => { if (cat === 'common') { - return getUserCommon().includes(t.name) + return common.includes(t.name) } return t.cat.includes(cat); }) diff --git a/vue.config.js b/vue.config.js index ca3bc99..ea618f2 100644 --- a/vue.config.js +++ b/vue.config.js @@ -5,12 +5,6 @@ pages.tool = { entry: 'src/tool.js', template: 'public/tool.html', }; -if (adapter.isChromium) { - pages.background = { - entry: 'src/background.js', - template: 'public/background.html', - }; -} const config = { productionSourceMap: false, publicPath: "./", -- GitLab