1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

embed hotkey, config to preferences modal & fix datasaving sequence(Async, Queue)

This commit is contained in:
Rokt33r
2016-01-08 14:38:29 +09:00
parent ee280d5c7b
commit 09735b7f47
14 changed files with 461 additions and 194 deletions

View File

@@ -105,7 +105,7 @@ export function init () {
folders: [defaultFolder],
version: '0.4'
}
jetpack.write(getLocalPath(), data)
queueSave()
}
}
@@ -114,18 +114,44 @@ export function getData () {
return data
}
let timer = null
let isSaving = false
let saveAgain = false
function saveData () {
timer = null
isSaving = true
jetpack.writeAsync(getLocalPath(), data)
.then(function () {
isSaving = false
if (saveAgain) {
saveAgain = false
queueSave()
}
})
}
function queueSave () {
if (!isSaving) {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(saveData, 3000)
} else {
saveAgain = true
}
}
export function setArticles (articles) {
if (!_.isArray(articles)) throw new Error('Articles must be an array')
let data = getData()
data.articles = articles
jetpack.write(getLocalPath(), data)
queueSave()
}
export function setFolders (folders) {
if (!_.isArray(folders)) throw new Error('Folders must be an array')
let data = getData()
data.folders = folders
jetpack.write(getLocalPath(), data)
queueSave()
}
function isFinderCalled () {