From 1d1e70c30838d5b0e85e94fa0a5192984933b02d Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Sun, 18 Sep 2022 14:30:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=B7=AF=E5=BE=84=E5=88=9D=E5=A7=8B=E5=8C=96=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E4=BA=86initPlugin=E5=87=BD=E6=95=B0=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global/initPlugin.js | 15 +++++---------- src/global/readSetting.js | 6 ++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/global/initPlugin.js b/src/global/initPlugin.js index 463bd00..8d37c59 100644 --- a/src/global/initPlugin.js +++ b/src/global/initPlugin.js @@ -3,12 +3,7 @@ const { utools, existsSync, readFileSync, writeFileSync, mkdirSync, crypto, list import setting from './readSetting' export default function initPlugin() { - const sep = utools.isWindows() ? '\\' : '/' - const DBPath = - setting.database.path || - `${ - utools.isMacOs() ? utools.getPath('userData') : utools.getPath('home') - }${sep}_utools_clipboard_manager_storage` + const SEP = utools.isWindows() ? '\\' : '/' class DB { constructor(path) { const d = new Date() @@ -153,7 +148,7 @@ export default function initPlugin() { const createFile = (item) => { const tempPath = utools.getPath('temp') - const folderPath = tempPath + sep + 'utools-clipboard-manager' + const folderPath = tempPath + SEP + 'utools-clipboard-manager' if (!existsSync(folderPath)) { try { mkdirSync(folderPath) @@ -165,17 +160,17 @@ export default function initPlugin() { if (type === 'image') { const base64Data = item.data.replace(/^data:image\/\w+;base64,/, '') // remove the prefix const buffer = Buffer.from(base64Data, 'base64') // to Buffer - const filePath = folderPath + sep + new Date().valueOf() + '.png' + const filePath = folderPath + SEP + new Date().valueOf() + '.png' writeFileSync(filePath, buffer) return filePath } else if (type === 'text') { - const filePath = folderPath + sep + new Date().valueOf() + '.txt' + const filePath = folderPath + SEP + new Date().valueOf() + '.txt' writeFileSync(filePath, item.data) return filePath } } - const db = new DB(DBPath) + const db = new DB(setting.database.path) db.init() const remove = (item) => db.removeItemViaId(item.id) diff --git a/src/global/readSetting.js b/src/global/readSetting.js index 3718d9a..a1eb2b1 100644 --- a/src/global/readSetting.js +++ b/src/global/readSetting.js @@ -1,5 +1,10 @@ import defaultSetting from '../data/setting.json' +const sep = utools.isWindows() ? '\\' : '/' +const defaultPath = `${ + utools.isMacOs() ? utools.getPath('userData') : utools.getPath('home') +}${sep}_utools_clipboard_manager_storage` + let setting = utools.dbStorage.getItem('setting') if (!setting) { // 将defaultSetting的key点语法转换为对象 @@ -16,6 +21,7 @@ if (!setting) { } } } + setting.database.path = defaultPath utools.dbStorage.setItem('setting', setting) }