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

1.7.1 submit

上级 cbb27772
......@@ -25,4 +25,4 @@ yarn-error.log*
*.sln
*.sw*
test.js
/public/background.html
/public/background.js
......@@ -6,6 +6,10 @@
![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png)
## 在线使用
<https://baiy.github.io/Ctool/>
## chrome 安装
- 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装
......
{
"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",
......
{
"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"
},
......
......@@ -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
......
<!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;
// 打开独立窗口
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
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
......@@ -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
......
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) => {
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
......@@ -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')
......@@ -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);
});
}
}
......
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
......@@ -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);
})
......
......@@ -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: "./",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册