[native] fix: Automatically reload from disk when resuming app

fixes #1649

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-07-21 11:01:22 +02:00
Родитель f8ad240f62
Коммит 38a82cf23c
4 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -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()