Skip to content

Commit

Permalink
[native] fix: Automatically reload from disk when resuming app
Browse files Browse the repository at this point in the history
fixes #1649

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jul 21, 2024
1 parent f8ad240 commit 38a82cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/native/NativeTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: highestId} = await Storage.get({key: `bookmarks[${this.accountId}].highestId`})
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))
const newHash = await this.bookmarksCache.hash(true)
this.highestId = parseInt(highestId)
Expand Down
1 change: 1 addition & 0 deletions src/ui/store/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const actions = {
LOAD_ACCOUNTS: 'LOAD_ACCOUNTS',
SELECT_ACCOUNT: 'SELECT_ACCOUNT',
LOAD_TREE: 'LOAD_TREE',
LOAD_TREE_FROM_DISK: 'LOAD_TREE_FROM_DISK',
CREATE_BOOKMARK: 'CREATE_BOOKMARK',
EDIT_BOOKMARK: 'EDIT_BOOKMARK',
DELETE_BOOKMARK: 'DELETE_BOOKMARK',
Expand Down
13 changes: 13 additions & 0 deletions src/ui/store/native/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export const actionsDefinition = {
const rootFolder = await tree.getBookmarksTree(true)
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}) {
const account = await Account.get(accountId)
const tree = await account.getResource()
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/native/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export default {
},
mounted() {
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() {
this.goBack()
Expand Down

0 comments on commit 38a82cf

Please sign in to comment.