fix: 修复多端同步内存数据更新失效的问题

This commit is contained in:
ZiuChen
2022-10-10 18:47:42 +08:00
parent b7b5e785c0
commit 8ac19335f2
2 changed files with 20 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ const {
readFileSync,
writeFileSync,
mkdirSync,
watch,
crypto,
listener,
clipboard,
@@ -53,6 +54,23 @@ export default function initPlugin() {
this.dataBase = defaultDB
this.updateDataBaseLocal(defaultDB)
}
watchDataBaseUpdate() {
watch(this.path, (eventType, filename) => {
if (eventType === 'change') {
// 更新内存中的数据
const data = readFileSync(this.path, {
encoding: 'utf8'
})
try {
const dataBase = JSON.parse(data)
this.dataBase = dataBase
} catch (err) {
utools.showNotification('读取剪切板出错: ' + err)
return
}
}
})
}
updateDataBase() {
// 更新内存数据
this.dataBase.updateTime = new Date().getTime()