mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-06-09 15:34:04 +08:00
feat: 增加历史条数限制与保存时间限制
This commit is contained in:
parent
fe486baea7
commit
86b13fd67f
@ -23,29 +23,30 @@ class DB {
|
|||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
const isExist = fs.existsSync(this.path)
|
const isExist = fs.existsSync(this.path)
|
||||||
|
|
||||||
if (isExist) {
|
if (isExist) {
|
||||||
const data = fs.readFileSync(this.path, {
|
const data = fs.readFileSync(this.path, {
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 读取磁盘记录到内存
|
||||||
const dataBase = JSON.parse(data)
|
const dataBase = JSON.parse(data)
|
||||||
this.dataBase = dataBase
|
this.dataBase = dataBase
|
||||||
|
// 将超过14天的数据删除
|
||||||
|
const now = new Date().getTime()
|
||||||
|
const deleteTime = now - '\u0031\u0034' * '\u0032\u0034' * 60 * 60 * 1000 // unicode
|
||||||
|
this.dataBase.data = this.dataBase.data.filter((item) => item.updateTime > deleteTime)
|
||||||
|
this.updateDataBaseLocal()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
utools.showNotification('读取剪切板出错' + err)
|
utools.showNotification('读取剪切板出错' + err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultDB = {
|
const defaultDB = {
|
||||||
data: [],
|
data: [],
|
||||||
createTime: this.createTime,
|
createTime: this.createTime,
|
||||||
updateTime: this.updateTime
|
updateTime: this.updateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataBase = defaultDB
|
this.dataBase = defaultDB
|
||||||
this.updateDataBaseLocal(defaultDB)
|
this.updateDataBaseLocal(defaultDB)
|
||||||
}
|
}
|
||||||
@ -65,6 +66,15 @@ class DB {
|
|||||||
addItem(cItem) {
|
addItem(cItem) {
|
||||||
this.dataBase.data.unshift(cItem)
|
this.dataBase.data.unshift(cItem)
|
||||||
this.updateDataBase()
|
this.updateDataBase()
|
||||||
|
// unicode
|
||||||
|
if (this.dataBase.data.length > '\u0035\u0030\u0030') {
|
||||||
|
// 达到条数限制
|
||||||
|
this.dataBase.data.pop()
|
||||||
|
// 仍然大于: 超出了不止一条
|
||||||
|
if (this.dataBase.data.length > '\u0035\u0030\u0030') {
|
||||||
|
this.dataBase.data = this.dataBase.data.splice(0, 499)
|
||||||
|
}
|
||||||
|
}
|
||||||
this.updateDataBaseLocal()
|
this.updateDataBaseLocal()
|
||||||
}
|
}
|
||||||
emptyDataBase() {
|
emptyDataBase() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user