From 8e1f5739968e00d9c32f64acf3f91ee7fa0e7eec Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Fri, 28 Oct 2022 20:03:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=94=B1=E4=BA=8E=E6=95=B0=E6=8D=AE=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=AE=BE=E5=A4=87ID=E7=A1=AE=E5=AE=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global/initPlugin.js | 11 +++++++---- src/global/readSetting.js | 11 +++++++++++ src/global/restoreSetting.js | 7 +++++-- src/utils/index.js | 6 +++++- src/views/Setting.vue | 9 +++++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/global/initPlugin.js b/src/global/initPlugin.js index 5c1c5ca..710b20b 100644 --- a/src/global/initPlugin.js +++ b/src/global/initPlugin.js @@ -9,7 +9,7 @@ const { clipboard, time } = window.exports -import { copy, paste, createFile } from '../utils' +import { copy, paste, createFile, getNativeId } from '../utils' import setting from './readSetting' export default function initPlugin() { @@ -161,7 +161,10 @@ export default function initPlugin() { } } - const db = new DB(setting.database.path) + // 根据当前设备id读取不同路径 若为旧版本则迁移数据 + const nativeId = getNativeId() + console.log(setting.database.path[nativeId]) + const db = new DB(setting.database.path[nativeId] || setting.database.path) db.init() const remove = (item) => db.removeItemViaId(item.id) @@ -228,7 +231,7 @@ export default function initPlugin() { if (!utools.isMacOs()) { // 首次启动插件 即开启监听 registerClipEvent(listener) - listener.startListening(setting.database.path) + listener.startListening(setting.database.path[nativeId]) } else { // macos 由于无法执行 clipboard-event-handler-mac 所以使用旧方法 addCommonListener() @@ -238,7 +241,7 @@ export default function initPlugin() { if (!listener.listening && !utools.isMacOs()) { // 进入插件后 如果监听已关闭 则重新开启监听 registerClipEvent(listener) - listener.startListening(setting.database.path) + listener.startListening(setting.database.path[nativeId]) } toTop() resetNav() diff --git a/src/global/readSetting.js b/src/global/readSetting.js index b79fec3..a893604 100644 --- a/src/global/readSetting.js +++ b/src/global/readSetting.js @@ -1,5 +1,16 @@ import restoreSetting from './restoreSetting' +import { getNativeId } from '../utils' const setting = utools.dbStorage.getItem('setting') || restoreSetting() +const nativeId = getNativeId() + +// 旧版本的setting中path是字符串,新版本的path是对象 +if (typeof setting.database.path === 'string') { + setting.database.path = { + [nativeId]: setting.database.path + } + // 将设置更新到数据库 + utools.dbStorage.setItem('setting', setting) +} export default setting diff --git a/src/global/restoreSetting.js b/src/global/restoreSetting.js index cd1c74f..f7df4e9 100644 --- a/src/global/restoreSetting.js +++ b/src/global/restoreSetting.js @@ -1,14 +1,17 @@ import defaultSetting from '../data/setting.json' -import { pointToObj } from '../utils' +import { pointToObj, getNativeId } from '../utils' +const { utools } = window.exports const defaultPath = `${utools.isMacOs() ? utools.getPath('userData') : utools.getPath('home')}${ window.exports.sep }_utools_clipboard_manager_storage` +const nativeId = getNativeId() + export default function restoreSetting() { // 将defaultSetting的key点语法转换为对象 const setting = pointToObj(defaultSetting) - setting.database.path = defaultPath + setting.database.path[nativeId] = defaultPath // 根据不同设备设置不同的默认路径 utools.dbStorage.setItem('setting', setting) return setting } diff --git a/src/utils/index.js b/src/utils/index.js index b4ae490..1a3a249 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -83,4 +83,8 @@ const createFile = (item) => { } } -export { dateFormat, pointToObj, copy, paste, createFile } +const getNativeId = () => { + return utools.getNativeId() +} + +export { dateFormat, pointToObj, copy, paste, createFile, getNativeId } diff --git a/src/views/Setting.vue b/src/views/Setting.vue index a64e059..65e218f 100644 --- a/src/views/Setting.vue +++ b/src/views/Setting.vue @@ -80,11 +80,13 @@ import { ElMessage, ElMessageBox } from 'element-plus' import setting from '../global/readSetting' import restoreSetting from '../global/restoreSetting' import defaultOperation from '../data/operation.json' +import { getNativeId } from '../utils' const emit = defineEmits(['back']) const { database, operation } = setting +const nativeId = getNativeId() -const path = ref(database.path) +const path = ref(database.path[nativeId]) const maxsize = ref(database.maxsize) const maxage = ref(database.maxage) @@ -136,7 +138,10 @@ const handleSaveBtnClick = () => { JSON.parse( JSON.stringify({ database: { - path: path.value, + path: { + ...database.path, + [nativeId]: path.value + }, maxsize: maxsize.value, maxage: maxage.value },