提交 bea4bdd2 编写于 作者: B baiy 提交者: ninecents

1.7.1 submit

上级 cbb27772
...@@ -25,4 +25,4 @@ yarn-error.log* ...@@ -25,4 +25,4 @@ yarn-error.log*
*.sln *.sln
*.sw* *.sw*
test.js test.js
/public/background.html /public/background.js
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png) ![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png)
## 在线使用
<https://baiy.github.io/Ctool/>
## chrome 安装 ## chrome 安装
- 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装 - 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装
......
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.6.8", "version": "1.7.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
...@@ -7286,11 +7286,6 @@ ...@@ -7286,11 +7286,6 @@
"yallist": "^3.0.2" "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": { "make-dir": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
...@@ -11820,6 +11815,12 @@ ...@@ -11820,6 +11815,12 @@
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=",
"dev": true "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": { "uuid": {
"version": "8.3.2", "version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
......
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.6.9", "version": "1.7.1",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --port 8081", "serve": "vue-cli-service serve --port 8081",
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
"jsonlint": "^1.6.3", "jsonlint": "^1.6.3",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"lscache": "^1.3.0",
"mime-types": "^2.1.32", "mime-types": "^2.1.32",
"moment": "^2.29.1", "moment": "^2.29.1",
"php-array-reader": "^1.3.0", "php-array-reader": "^1.3.0",
...@@ -56,6 +55,7 @@ ...@@ -56,6 +55,7 @@
"eslint-plugin-vue": "^5.2.3", "eslint-plugin-vue": "^5.2.3",
"less": "^2.7.3", "less": "^2.7.3",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"utools-api-types": "^2.0.6",
"vue-cli-plugin-iview": "^1.0.6", "vue-cli-plugin-iview": "^1.0.6",
"vue-template-compiler": "^2.6.14" "vue-template-compiler": "^2.6.14"
}, },
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
"author": "wo@baiy.org", "author": "wo@baiy.org",
"offline_enabled": true, "offline_enabled": true,
"homepage_url": "https://github.com/baiy/Ctool", "homepage_url": "https://github.com/baiy/Ctool",
"manifest_version": 2, "manifest_version": 3,
"browser_action": { "action": {
"default_icon": "img/icon_chrome.png", "default_icon": "img/icon_chrome.png",
"default_title": "常用开发工具", "default_title": "常用开发工具",
"default_popup": "index.html" "default_popup": "index.html"
}, },
"background": { "background": {
"page": "background.html" "service_worker": "background.js"
}, },
"icons": { "icons": {
"16": "img/icon_chrome.png", "16": "img/icon_chrome.png",
...@@ -21,11 +21,14 @@ ...@@ -21,11 +21,14 @@
}, },
"permissions": [ "permissions": [
"clipboardWrite", "clipboardWrite",
"clipboardRead", "clipboardRead"
],
"host_permissions": [
"*://ifconfig.co/*", "*://ifconfig.co/*",
"*://*.baiy.org/*" "*://*.baiy.org/*"
], ],
"commands": { "commands": {
"_execute_browser_action": {},
"panel": { "panel": {
"description": "打开独立工具窗口", "description": "打开独立工具窗口",
"global": true "global": true
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Ctool 程序开发常用工具</title>
</head>
<body>
<div>
<div id="app"></div>
</div>
</body>
</html>
\ No newline at end of file
let windowId = null; let windowId = null;
// 打开独立窗口 // 打开独立窗口
const panel = { const panel = {
cacheName: "background:panel:window_id",
create() { create() {
chrome.windows.create({ chrome.windows.create({
url: chrome.runtime.getURL("tool.html"), url: chrome.runtime.getURL("tool.html"),
...@@ -49,4 +50,4 @@ chrome.commands.onCommand.addListener((command) => { ...@@ -49,4 +50,4 @@ chrome.commands.onCommand.addListener((command) => {
// 窗口关闭事件 // 窗口关闭事件
chrome.windows.onRemoved.addListener((id) => { chrome.windows.onRemoved.addListener((id) => {
panel.onRemoved(id); panel.onRemoved(id);
}) })
\ No newline at end of file
export const openUrl = (url) => { export const openUrl = (url) => {
// return chrome.tabs.create(); // return chrome.tabs.create();
// return chrome.windows.create(); // return chrome.windows.create();
if (url.indexOf('chrome://') === 0){
return chrome.tabs.create({url:url});
}
return window.open(url); return window.open(url);
} }
\ No newline at end of file
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
"author": "wo@baiy.org", "author": "wo@baiy.org",
"offline_enabled": true, "offline_enabled": true,
"homepage_url": "https://github.com/baiy/Ctool", "homepage_url": "https://github.com/baiy/Ctool",
"manifest_version": 2, "manifest_version": 3,
"browser_action": { "action": {
"default_icon": "img/icon_chrome.png", "default_icon": "img/icon_chrome.png",
"default_title": "常用开发工具", "default_title": "常用开发工具",
"default_popup": "index.html" "default_popup": "index.html"
}, },
"background": { "background": {
"page": "background.html" "service_worker": "background.js"
}, },
"icons": { "icons": {
"16": "img/icon_chrome.png", "16": "img/icon_chrome.png",
...@@ -21,11 +21,14 @@ ...@@ -21,11 +21,14 @@
}, },
"permissions": [ "permissions": [
"clipboardWrite", "clipboardWrite",
"clipboardRead", "clipboardRead"
],
"host_permissions": [
"*://ifconfig.co/*", "*://ifconfig.co/*",
"*://*.baiy.org/*" "*://*.baiy.org/*"
], ],
"commands": { "commands": {
"_execute_browser_action": {},
"panel": { "panel": {
"description": "打开独立工具窗口", "description": "打开独立工具窗口",
"global": true "global": true
......
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);
})
...@@ -24,4 +24,6 @@ export const openUrl = (url) => { ...@@ -24,4 +24,6 @@ export const openUrl = (url) => {
return utoolsOpenUrl(url) return utoolsOpenUrl(url)
} }
return window.open(url); return window.open(url);
}; };
\ No newline at end of file
export const version = env('version').trim()
\ No newline at end of file
...@@ -4,9 +4,28 @@ import './statics/theme.less' ...@@ -4,9 +4,28 @@ import './statics/theme.less'
import router from './tool.router' import router from './tool.router'
import optionBlock from './components/optionBlock' import optionBlock from './components/optionBlock'
import {plugin as modelPlugin} from './tool/model' import {plugin as modelPlugin} from './tool/model'
import cache from './tool/cache'
import App from './tool.vue' import App from './tool.vue'
import {isUtools} from './helper' 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 () { (function () {
if (document.body.clientWidth > 900 || isUtools) { if (document.body.clientWidth > 900 || isUtools) {
console.log('调整窗口大小') console.log('调整窗口大小')
...@@ -15,15 +34,15 @@ import {isUtools} from './helper' ...@@ -15,15 +34,15 @@ import {isUtools} from './helper'
page.style.height = 'auto' page.style.height = 'auto'
page.style.minHeight = '550px' 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')
...@@ -51,16 +51,16 @@ const edgeConfigWrite = () => { ...@@ -51,16 +51,16 @@ const edgeConfigWrite = () => {
const chromiumConfigWrite = () => { const chromiumConfigWrite = () => {
// 移除环境配置文件 // 移除环境配置文件
removeFile(path.join(__dirname, '../../public/manifest.json')); 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); removeFile(backgroundPath);
if (IS_CHROMIUM) { 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 = () => { const utoolsConfigWrite = () => {
// 移除环境配置文件 // 移除环境配置文件
let fileArr = ['plugin.json', 'README.md'] let fileArr = ['plugin.json']
fileArr.forEach((file) => { fileArr.forEach((file) => {
let filePath = path.join(__dirname, '../../public/' + file); let filePath = path.join(__dirname, '../../public/' + file);
removeFile(filePath); removeFile(filePath);
...@@ -118,7 +118,6 @@ const utoolsConfigWrite = () => { ...@@ -118,7 +118,6 @@ const utoolsConfigWrite = () => {
utoolsToolFeature[toolFeatureCode].cmds.push(cmd) utoolsToolFeature[toolFeatureCode].cmds.push(cmd)
} }
} }
} }
let features = [ let features = [
...@@ -135,10 +134,6 @@ const utoolsConfigWrite = () => { ...@@ -135,10 +134,6 @@ const utoolsConfigWrite = () => {
.replace(/"##features##"/g, JSON.stringify(features)); .replace(/"##features##"/g, JSON.stringify(features));
fs.writeFileSync(pluginPath, result); 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);
});
} }
} }
......
import lsCache from 'lscache' import db from './db'
import p from '../../package' import {version} from '../helper'
const cacheVersion = version.split('.').join('');
// 缓存key添加版本号 // 缓存key添加版本号
const cacheNameConvert = function (name) { const cacheNameConvert = function (name) {
return 'v_' + (p.version.split('.').join('')) + '_' + name return 'v_' + cacheVersion + '_' + name
} }
export default { const cache = {
// expiry 过期时间 秒 set(name, value, expiry = 0) {
set (name, value, expiry = 0) { return db.set(cacheNameConvert(name), value, expiry)
return lsCache.set(cacheNameConvert(name), value, expiry / 60) },
get(name, defaultValue = null) {
let data = db.get(cacheNameConvert(name))
return data === null ? defaultValue : data
}, },
get (name, defaultValue = null) { remove(name) {
let data = lsCache.get(cacheNameConvert(name)) db.remove(cacheNameConvert(name))
return data ? data : defaultValue return db.remove(cacheNameConvert(name))
}, },
remove (name) { setNoVersion(name, value, expiry = 0) {
lsCache.remove(cacheNameConvert(name)) return db.set('nv_' + name, value, expiry)
}, },
setNoVersion (name, value, expiry = 0) { getNoVersion(name, defaultValue = null) {
return lsCache.set('nv_' + name, value, expiry / 60) let data = db.get('nv_' + name)
return data === null ? defaultValue : data
}, },
getNoVersion (name, defaultValue = null) { removeNoVersion(name) {
let data = lsCache.get('nv_' + name) return db.remove('nv_' + name)
return data ? data : defaultValue
}, },
} // 清理数据
\ 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
...@@ -82,9 +82,10 @@ export default { ...@@ -82,9 +82,10 @@ export default {
getToolTitle, getToolTitle,
getUserCommon, getUserCommon,
getToolByCategory(cat) { getToolByCategory(cat) {
let common = getUserCommon();
return tool.filter((t) => { return tool.filter((t) => {
if (cat === 'common') { if (cat === 'common') {
return getUserCommon().includes(t.name) return common.includes(t.name)
} }
return t.cat.includes(cat); return t.cat.includes(cat);
}) })
......
...@@ -5,12 +5,6 @@ pages.tool = { ...@@ -5,12 +5,6 @@ pages.tool = {
entry: 'src/tool.js', entry: 'src/tool.js',
template: 'public/tool.html', template: 'public/tool.html',
}; };
if (adapter.isChromium) {
pages.background = {
entry: 'src/background.js',
template: 'public/background.html',
};
}
const config = { const config = {
productionSourceMap: false, productionSourceMap: false,
publicPath: "./", publicPath: "./",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册