mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-06-08 06:16:18 +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 crypto = require('crypto')
|
||||||
const listener = require('./listener')
|
const listener = require('./listener')
|
||||||
const { clipboard } = require('electron')
|
const { clipboard } = require('electron')
|
||||||
@ -10,6 +10,7 @@ window.exports = {
|
|||||||
readFileSync,
|
readFileSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
mkdirSync,
|
mkdirSync,
|
||||||
|
watch,
|
||||||
crypto,
|
crypto,
|
||||||
listener,
|
listener,
|
||||||
clipboard,
|
clipboard,
|
||||||
|
@ -4,6 +4,7 @@ const {
|
|||||||
readFileSync,
|
readFileSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
mkdirSync,
|
mkdirSync,
|
||||||
|
watch,
|
||||||
crypto,
|
crypto,
|
||||||
listener,
|
listener,
|
||||||
clipboard,
|
clipboard,
|
||||||
@ -53,6 +54,23 @@ export default function initPlugin() {
|
|||||||
this.dataBase = defaultDB
|
this.dataBase = defaultDB
|
||||||
this.updateDataBaseLocal(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() {
|
updateDataBase() {
|
||||||
// 更新内存数据
|
// 更新内存数据
|
||||||
this.dataBase.updateTime = new Date().getTime()
|
this.dataBase.updateTime = new Date().getTime()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user