[native] fix: Automatically reload from disk when resuming app
fixes #1649 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Родитель
f8ad240f62
Коммит
38a82cf23c
|
@ -21,7 +21,7 @@ export default class NativeTree extends CachingAdapter implements BulkImportReso
|
||||||
const {value: tree} = await Storage.get({key: `bookmarks[${this.accountId}].tree`})
|
const {value: tree} = await Storage.get({key: `bookmarks[${this.accountId}].tree`})
|
||||||
const {value: highestId} = await Storage.get({key: `bookmarks[${this.accountId}].highestId`})
|
const {value: highestId} = await Storage.get({key: `bookmarks[${this.accountId}].highestId`})
|
||||||
if (tree) {
|
if (tree) {
|
||||||
const oldHash = this.bookmarksCache && await this.bookmarksCache.hash(true)
|
const oldHash = this.bookmarksCache && await this.bookmarksCache.clone(false).hash(true)
|
||||||
this.bookmarksCache = Folder.hydrate(JSON.parse(tree))
|
this.bookmarksCache = Folder.hydrate(JSON.parse(tree))
|
||||||
const newHash = await this.bookmarksCache.hash(true)
|
const newHash = await this.bookmarksCache.hash(true)
|
||||||
this.highestId = parseInt(highestId)
|
this.highestId = parseInt(highestId)
|
||||||
|
|
|
@ -6,6 +6,7 @@ export const actions = {
|
||||||
LOAD_ACCOUNTS: 'LOAD_ACCOUNTS',
|
LOAD_ACCOUNTS: 'LOAD_ACCOUNTS',
|
||||||
SELECT_ACCOUNT: 'SELECT_ACCOUNT',
|
SELECT_ACCOUNT: 'SELECT_ACCOUNT',
|
||||||
LOAD_TREE: 'LOAD_TREE',
|
LOAD_TREE: 'LOAD_TREE',
|
||||||
|
LOAD_TREE_FROM_DISK: 'LOAD_TREE_FROM_DISK',
|
||||||
CREATE_BOOKMARK: 'CREATE_BOOKMARK',
|
CREATE_BOOKMARK: 'CREATE_BOOKMARK',
|
||||||
EDIT_BOOKMARK: 'EDIT_BOOKMARK',
|
EDIT_BOOKMARK: 'EDIT_BOOKMARK',
|
||||||
DELETE_BOOKMARK: 'DELETE_BOOKMARK',
|
DELETE_BOOKMARK: 'DELETE_BOOKMARK',
|
||||||
|
|
|
@ -33,6 +33,19 @@ export const actionsDefinition = {
|
||||||
const rootFolder = await tree.getBookmarksTree(true)
|
const rootFolder = await tree.getBookmarksTree(true)
|
||||||
await commit(mutations.LOAD_TREE, rootFolder)
|
await commit(mutations.LOAD_TREE, rootFolder)
|
||||||
},
|
},
|
||||||
|
async [actions.LOAD_TREE_FROM_DISK]({ commit, dispatch, state }, id) {
|
||||||
|
const account = await Account.get(id)
|
||||||
|
if (account.syncing) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const tree = await account.getResource()
|
||||||
|
const changed = await tree.load()
|
||||||
|
const rootFolder = await tree.getBookmarksTree(true)
|
||||||
|
await commit(mutations.LOAD_TREE, rootFolder)
|
||||||
|
if (changed) {
|
||||||
|
await dispatch(actions.TRIGGER_SYNC, id)
|
||||||
|
}
|
||||||
|
},
|
||||||
async [actions.CREATE_BOOKMARK]({commit}, {accountId, bookmark}) {
|
async [actions.CREATE_BOOKMARK]({commit}, {accountId, bookmark}) {
|
||||||
const account = await Account.get(accountId)
|
const account = await Account.get(accountId)
|
||||||
const tree = await account.getResource()
|
const tree = await account.getResource()
|
||||||
|
|
|
@ -431,6 +431,7 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.dispatch(actions.LOAD_TREE, this.$route.params.accountId)
|
this.$store.dispatch(actions.LOAD_TREE, this.$route.params.accountId)
|
||||||
|
App.addListener('resume', () => this.$store.dispatch(actions.LOAD_TREE_FROM_DISK, this.$route.params.accountId))
|
||||||
},
|
},
|
||||||
backButton() {
|
backButton() {
|
||||||
this.goBack()
|
this.goBack()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче