mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-06-06 13:24:06 +08:00
fix: 修复多端同步内存数据更新失效的问题
This commit is contained in:
parent
b7b5e785c0
commit
8ac19335f2
@ -1,4 +1,4 @@
|
||||
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs')
|
||||
const { existsSync, readFileSync, writeFileSync, mkdirSync, watch } = require('fs')
|
||||
const crypto = require('crypto')
|
||||
const listener = require('./listener')
|
||||
const { clipboard } = require('electron')
|
||||
@ -10,6 +10,7 @@ window.exports = {
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
mkdirSync,
|
||||
watch,
|
||||
crypto,
|
||||
listener,
|
||||
clipboard,
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user