提交 7589d84a 编写于 作者: B baiy 提交者: ninecents

1.7.1 submit

上级 e2e90d05
...@@ -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
import cache from './tool/cache' let windowId = null;
// 打开独立窗口 // 打开独立窗口
const panel = { const panel = {
cacheName: "background:panel:window_id", cacheName: "background:panel:window_id",
...@@ -11,11 +11,10 @@ const panel = { ...@@ -11,11 +11,10 @@ const panel = {
top: 200, top: 200,
height: 610, height: 610,
}, (w) => { }, (w) => {
cache.set(this.cacheName, w.id) windowId = w.id
}) })
}, },
open() { open() {
let windowId = cache.get(this.cacheName)
if (windowId === null) { if (windowId === null) {
this.create() this.create()
} else { } else {
...@@ -30,8 +29,8 @@ const panel = { ...@@ -30,8 +29,8 @@ const panel = {
}, },
onRemoved(id) { onRemoved(id) {
if (id === cache.get(this.cacheName)) { if (id === windowId) {
cache.remove(this.cacheName) windowId = null;
} }
} }
} }
...@@ -51,5 +50,4 @@ chrome.commands.onCommand.addListener((command) => { ...@@ -51,5 +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
import lsCache from './lscache'
export default {
get(key, def = null) {
let data = lsCache.get(key)
return data ? data : def
},
set(key, value, expiry = 0) {
return lsCache.set(key, value, expiry / 60)
},
remove(key) {
return lsCache.remove(key)
},
// 清理过期
clear() {
return lsCache.flushExpired()
},
getAllKey() {
return lsCache.getAllKey();
}
}
\ No newline at end of file
/**
* lscache library
* Copyright (c) 2011, Pamela Fox
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://github.com/pamelafox/lscache
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint undef:true, browser:true, node:true */
// Prefix for all lscache keys
var CACHE_PREFIX = 'lscache-';
// Suffix for the key name on the expiration items in localStorage
var CACHE_SUFFIX = '-cacheexpiration';
// expiration date radix (set to Base-36 for most space savings)
var EXPIRY_RADIX = 10;
// time resolution in milliseconds
var expiryMilliseconds = 60 * 1000;
// ECMAScript max Date (epoch + 1e8 days)
var maxDate = calculateMaxDate(expiryMilliseconds);
var cachedStorage;
var cachedJSON;
var cacheBucket = '';
var warnings = false;
// Determines if localStorage is supported in the browser;
// result is cached for better performance instead of being run each time.
// Feature detection is based on how Modernizr does it;
// it's not straightforward due to FF4 issues.
// It's not run at parse-time as it takes 200ms in Android.
function supportsStorage() {
var key = '__lscachetest__';
var value = key;
if (cachedStorage !== undefined) {
return cachedStorage;
}
// some browsers will throw an error if you try to access local storage (e.g. brave browser)
// hence check is inside a try/catch
try {
if (!localStorage) {
return false;
}
} catch (ex) {
return false;
}
try {
setItem(key, value);
removeItem(key);
cachedStorage = true;
} catch (e) {
// If we hit the limit, and we don't have an empty localStorage then it means we have support
if (isOutOfSpace(e) && localStorage.length) {
cachedStorage = true; // just maxed it out and even the set test failed.
} else {
cachedStorage = false;
}
}
return cachedStorage;
}
// Check to set if the error is us dealing with being out of space
function isOutOfSpace(e) {
return e && (
e.name === 'QUOTA_EXCEEDED_ERR' ||
e.name === 'NS_ERROR_DOM_QUOTA_REACHED' ||
e.name === 'QuotaExceededError'
);
}
// Determines if native JSON (de-)serialization is supported in the browser.
function supportsJSON() {
/*jshint eqnull:true */
if (cachedJSON === undefined) {
cachedJSON = (window.JSON != null);
}
return cachedJSON;
}
/**
* Returns a string where all RegExp special characters are escaped with a \.
* @param {String} text
* @return {string}
*/
function escapeRegExpSpecialCharacters(text) {
return text.replace(/[[\]{}()*+?.\\^$|]/g, '\\$&');
}
/**
* Returns the full string for the localStorage expiration item.
* @param {String} key
* @return {string}
*/
function expirationKey(key) {
return key + CACHE_SUFFIX;
}
/**
* Returns the number of minutes since the epoch.
* @return {number}
*/
function currentTime() {
return Math.floor((new Date().getTime()) / expiryMilliseconds);
}
/**
* Wrapper functions for localStorage methods
*/
function getItem(key) {
return localStorage.getItem(CACHE_PREFIX + cacheBucket + key);
}
function setItem(key, value) {
// Fix for iPad issue - sometimes throws QUOTA_EXCEEDED_ERR on setItem.
localStorage.removeItem(CACHE_PREFIX + cacheBucket + key);
localStorage.setItem(CACHE_PREFIX + cacheBucket + key, value);
}
function removeItem(key) {
localStorage.removeItem(CACHE_PREFIX + cacheBucket + key);
}
function eachKey(fn) {
var prefixRegExp = new RegExp('^' + CACHE_PREFIX + escapeRegExpSpecialCharacters(cacheBucket) + '(.*)');
// Loop in reverse as removing items will change indices of tail
for (var i = localStorage.length - 1; i >= 0; --i) {
var key = localStorage.key(i);
key = key && key.match(prefixRegExp);
key = key && key[1];
if (key && key.indexOf(CACHE_SUFFIX) < 0) {
fn(key, expirationKey(key));
}
}
}
function flushItem(key) {
var exprKey = expirationKey(key);
removeItem(key);
removeItem(exprKey);
}
function flushExpiredItem(key) {
var exprKey = expirationKey(key);
var expr = getItem(exprKey);
if (expr) {
var expirationTime = parseInt(expr, EXPIRY_RADIX);
// Check if we should actually kick item out of storage
if (currentTime() >= expirationTime) {
removeItem(key);
removeItem(exprKey);
return true;
}
}
}
function warn(message, err) {
if (!warnings) return;
if (!('console' in window) || typeof window.console.warn !== 'function') return;
window.console.warn("lscache - " + message);
if (err) window.console.warn("lscache - The error was: " + err.message);
}
function calculateMaxDate(expiryMilliseconds) {
return Math.floor(8.64e15 / expiryMilliseconds);
}
let lscache = {
/**
* Stores the value in localStorage. Expires after specified number of minutes.
* @param {string} key
* @param {Object|string} value
* @param {number} time
* @return true if the value was inserted successfully
*/
set: function (key, value, time) {
if (!supportsStorage()) return false;
// If we don't get a string value, try to stringify
// In future, localStorage may properly support storing non-strings
// and this can be removed.
if (!supportsJSON()) return false;
try {
value = JSON.stringify(value);
} catch (e) {
// Sometimes we can't stringify due to circular refs
// in complex objects, so we won't bother storing then.
return false;
}
try {
setItem(key, value);
} catch (e) {
if (isOutOfSpace(e)) {
// If we exceeded the quota, then we will sort
// by the expire time, and then remove the N oldest
var storedKeys = [];
var storedKey;
eachKey(function (key, exprKey) {
var expiration = getItem(exprKey);
if (expiration) {
expiration = parseInt(expiration, EXPIRY_RADIX);
} else {
// TODO: Store date added for non-expiring items for smarter removal
expiration = maxDate;
}
storedKeys.push({
key: key,
size: (getItem(key) || '').length,
expiration: expiration
});
});
// Sorts the keys with oldest expiration time last
storedKeys.sort(function (a, b) {
return (b.expiration - a.expiration);
});
var targetSize = (value || '').length;
while (storedKeys.length && targetSize > 0) {
storedKey = storedKeys.pop();
warn("Cache is full, removing item with key '" + key + "'");
flushItem(storedKey.key);
targetSize -= storedKey.size;
}
try {
setItem(key, value);
} catch (e) {
// value may be larger than total quota
warn("Could not add item with key '" + key + "', perhaps it's too big?", e);
return false;
}
} else {
// If it was some other error, just give up.
warn("Could not add item with key '" + key + "'", e);
return false;
}
}
// If a time is specified, store expiration info in localStorage
if (time) {
setItem(expirationKey(key), (currentTime() + time).toString(EXPIRY_RADIX));
} else {
// In case they previously set a time, remove that info from localStorage.
removeItem(expirationKey(key));
}
return true;
},
/**
* Retrieves specified value from localStorage, if not expired.
* @param {string} key
* @return {string|Object}
*/
get: function (key) {
if (!supportsStorage()) return null;
// Return the de-serialized item if not expired
if (flushExpiredItem(key)) {
return null;
}
// Tries to de-serialize stored value if its an object, and returns the normal value otherwise.
var value = getItem(key);
if (!value || !supportsJSON()) {
return value;
}
try {
// We can't tell if its JSON or a string, so we try to parse
return JSON.parse(value);
} catch (e) {
// If we can't parse, it's probably because it isn't an object
return value;
}
},
/**
* Removes a value from localStorage.
* Equivalent to 'delete' in memcache, but that's a keyword in JS.
* @param {string} key
*/
remove: function (key) {
if (!supportsStorage()) return;
flushItem(key);
},
/**
* Returns whether local storage is supported.
* Currently exposed for testing purposes.
* @return {boolean}
*/
supported: function () {
return supportsStorage();
},
/**
* Flushes all lscache items and expiry markers without affecting rest of localStorage
*/
flush: function () {
if (!supportsStorage()) return;
eachKey(function (key) {
flushItem(key);
});
},
/**
* Flushes expired lscache items and expiry markers without affecting rest of localStorage
*/
flushExpired: function () {
if (!supportsStorage()) return;
eachKey(function (key) {
flushExpiredItem(key);
});
},
/**
* Appends CACHE_PREFIX so lscache will partition data in to different buckets.
* @param {string} bucket
*/
setBucket: function (bucket) {
cacheBucket = bucket;
},
/**
* Resets the string being appended to CACHE_PREFIX so lscache will use the default storage behavior.
*/
resetBucket: function () {
cacheBucket = '';
},
/**
* @returns {number} The currently set number of milliseconds each time unit represents in
* the set() function's "time" argument.
*/
getExpiryMilliseconds: function () {
return expiryMilliseconds;
},
/**
* Sets the number of milliseconds each time unit represents in the set() function's
* "time" argument.
* Sample values:
* 1: each time unit = 1 millisecond
* 1000: each time unit = 1 second
* 60000: each time unit = 1 minute (Default value)
* 360000: each time unit = 1 hour
* @param {number} milliseconds
*/
setExpiryMilliseconds: function (milliseconds) {
expiryMilliseconds = milliseconds;
maxDate = calculateMaxDate(expiryMilliseconds);
},
/**
* Sets whether to display warnings when an item is removed from the cache or not.
*/
enableWarnings: function (enabled) {
warnings = enabled;
},
getAllKey() {
let all = []
eachKey((key) => {
all.push(key)
})
return all;
}
};
export default lscache;
...@@ -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 _ from "lodash"
const PREFIX = "_system_"
const timestamp = () => {
return Math.ceil((Date.parse(new Date()) / 1000))
}
const encode = (value, expiry = 0) => {
return {
v: value,
e: expiry ? expiry + timestamp() : 0,
}
}
const decode = (data) => {
if (
!_.isObject(data)
|| !("v" in data)
|| !("e" in data)
) {
return null;
}
return data
}
const keyName = (key) => {
return `${PREFIX}${key}`
}
export default {
get(key, def = null) {
let data = decode(window.utools.dbStorage.getItem(keyName(key)));
// 不存在/过期
if (data === null || (data.e !== 0 && data.e < timestamp())) {
// 移除过期
if (data !== null) {
this.remove(key)
}
return def;
}
return data.v
},
set(key, value, expiry = 0) {
return window.utools.dbStorage.setItem(
keyName(key),
encode(value, _.toInteger(expiry))
)
},
remove(key) {
return window.utools.dbStorage.removeItem(keyName(key))
},
// 清理过期
clear() {
for (let {_id} of window.utools.db.allDocs(PREFIX)) {
let key = _id.replace(PREFIX, "");
if (key) {
// 获取一次 过期会自动删除
this.get(key)
}
}
return true;
},
getAllKey() {
return window.utools.db.allDocs(PREFIX).map(({_id}) => {
return _id.replace(PREFIX, "");
})
}
}
\ No newline at end of file
...@@ -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);
}) })
......
import {isUtools} from '../helper'
import utoolsDb from '../adapter/utools/db'
import defaultDb from '../adapter/default/db'
const db = isUtools ? utoolsDb : defaultDb;
export default {
get(key, def = null) {
return db.get(key, def)
},
set(key, value, expiry = 0) {
return db.set(key, value, expiry)
},
remove(key) {
return db.remove(key)
},
// 清理过期
clear() {
return db.clear();
},
getAllKey() {
return db.getAllKey();
}
}
\ No newline at end of file
...@@ -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.
先完成此消息的编辑!
想要评论请 注册