From 4ac8652cbe93838a3796b7b1f5c2b4768eedb531 Mon Sep 17 00:00:00 2001 From: fofolee Date: Wed, 17 Jun 2020 23:27:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0commonjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/common.js diff --git a/src/common.js b/src/common.js new file mode 100644 index 0000000..7a55feb --- /dev/null +++ b/src/common.js @@ -0,0 +1,52 @@ +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 + }, + + pushData: function (databases, data) { + var db = utools.db.get(databases); + if (db) { + utools.db.put({ _id: databases, data: data, _rev: db._rev }); + } else { + utools.db.put({ _id: databases, data: data }); + } + }, + + showChangeLog: function () { + this.pushData('plugin', { version: this.pluginInfo().version }) + fs.readFile(path.join(__dirname, 'CHANGELOG.md'), { encoding: 'utf8' }, (err, data) => { + if (data) utools.ubrowser.goto(data, '更新日志').run({ + width: 1080, + height: 860 + }) + }) + }, + + isRunningAtFirstTime: function () { + try { + var historyVersion = utools.db.get('plugin').data.version + if (historyVersion != this.pluginInfo().version) { + return true + } else { + return false + } + } catch (error) { + return true + } + }, + + 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) + } + } +} \ No newline at end of file