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 },