diff --git a/src/common.js b/src/common.js deleted file mode 100644 index 6c34719..0000000 --- a/src/common.js +++ /dev/null @@ -1,57 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -exports.fofo = { - pluginInfo: function () { - return JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json'))) - }, - - isDev: function () { - return /[a-zA-Z0-9\-]+\.asar/.test(__dirname) ? false : true - }, - - getDB: id => { - var db = utools.db.get(id), - dbData = db ? db.data : {}; - return dbData; - }, - - putDB: (key, value, id) => { - var db = utools.db.get(id); - if (db) { - var rev = db._rev - var data = db.data - data[key] = value; - utools.db.put({ _id: id, data: data, _rev: rev }); - } else { - var data = {}; - data[key] = value; - utools.db.put({ _id: id, data: data }); - } - }, - - showChangeLog: function () { - this.putDB('version', this.pluginInfo().version, 'plugin') - fs.readFile(path.join(__dirname, 'CHANGELOG.md'), { encoding: 'utf8' }, (err, data) => { - if (data) utools.ubrowser.goto(data, '更新日志').run({ - width: 1280, - height: 920 - }) - }) - }, - - isRunningAtFirstTime: function () { - var historyVersion = this.getDB('plugin').version - if (!historyVersion) return 'init' - if (this.pluginInfo().version > historyVersion) return 'update' - return false - }, - - GetFilePath: function (Path, File) { - if (this.isDev()) { - return path.join(__dirname, Path, File) - } else { - return path.join(__dirname.replace(/([a-zA-Z0-9\-]+\.asar)/,'$1.unpacked'), Path, File) - } - } -} diff --git a/src/preload.js b/src/preload.js index f4c019e..2ee1c3c 100644 --- a/src/preload.js +++ b/src/preload.js @@ -9,7 +9,6 @@ const util = require("util") const PinyinMatch = require('pinyin-match'); const axios = require('axios'); // axios.defaults.adapter = require('axios/lib/adapters/http') -fofoCommon = require('./common').fofo if (!utools.isWindows()) process.env.PATH += ':/usr/local/bin:/usr/local/sbin' @@ -326,6 +325,22 @@ swalOneByOne = options => { swal.getQueueStep() ? Swal.insertQueueStep(options) : Swal.queue([options]) } +pluginInfo = () => { + return JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json'))) +} + +isDev = () => { + return /[a-zA-Z0-9\-]+\.asar/.test(__dirname) ? false : true +} + +let GetFilePath = (Path, File) => { + if (isDev()) { + return path.join(__dirname, Path, File) + } else { + return path.join(__dirname.replace(/([a-zA-Z0-9\-]+\.asar)/,'$1.unpacked'), Path, File) + } +} + let getSleepCodeByShell = ms => { var cmd, tempFilePath if (utools.isWindows()) { @@ -342,7 +357,7 @@ let modWindowHeight = height => { } // 屏蔽危险函数 -let getuToolsLite = () => { +getuToolsLite = () => { var utoolsLite = Object.assign({}, utools) delete utoolsLite.db delete utoolsLite.removeFeature @@ -531,7 +546,7 @@ htmlEncode = (value, raw) => { py_beautify = (code, cb) => { var file = getQuickCommandScriptFile('py') fs.writeFile(file, code, { encoding: 'utf8' }, err => { - var cmd = `python "${fofoCommon.GetFilePath('assets/plugins', 'autopep8.py')}" "${file}"` + var cmd = `python "${GetFilePath('assets/plugins', 'autopep8.py')}" "${file}"` child_process.exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => { var codec = utools.isWindows() ? 'cp936' : 'utf8' cb(iconv.decode(stdout, codec).trim()) @@ -603,6 +618,7 @@ yuQueClient = axios.create({ baseURL: 'https://www.yuque.com/api/v2/', headers: { 'Content-Type': 'application/json', + // 只读权限 'X-Auth-Token': 'WNrd0Z4kfCZLFrGLVAaas93DZ7sbG6PirKq7VxBL' } });