From 52e600dc134810303eeb38b0ac1e60e0e4e5c7cb Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:07:47 +0000 Subject: [PATCH] Bugfix: load of subscriptions at startup (#1216) --- src/renderer/App.js | 41 +++++++++++--------- src/renderer/App.vue | 1 + src/renderer/store/modules/profile.js | 54 +++++++++++++++------------ 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/renderer/App.js b/src/renderer/App.js index 7d8b6891..b7147b99 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -41,6 +41,7 @@ export default Vue.extend({ }, data: function () { return { + dataReady: false, hideOutlines: true, showUpdatesBanner: false, showBlogBanner: false, @@ -85,26 +86,30 @@ export default Vue.extend({ } }, mounted: function () { - this.$store.dispatch('grabUserSettings').then((result) => { - this.$store.dispatch('grabHistory') - this.$store.dispatch('grabAllProfiles', this.$t('Profile.All Channels')) - this.$store.dispatch('grabAllPlaylists') - this.$store.commit('setUsingElectron', useElectron) - this.checkThemeSettings() - this.checkLocale() + const v = this + this.$store.dispatch('grabUserSettings').then(() => { + this.$store.dispatch('grabAllProfiles', this.$t('Profile.All Channels')).then(() => { + this.$store.dispatch('grabHistory') + this.$store.dispatch('grabAllPlaylists') + this.$store.commit('setUsingElectron', useElectron) + this.checkThemeSettings() + this.checkLocale() - if (useElectron) { - console.log('User is using Electron') - this.activateKeyboardShortcuts() - this.openAllLinksExternally() - this.enableOpenUrl() - this.setBoundsOnClose() - } + v.dataReady = true - setTimeout(() => { - this.checkForNewUpdates() - this.checkForNewBlogPosts() - }, 500) + if (useElectron) { + console.log('User is using Electron') + this.activateKeyboardShortcuts() + this.openAllLinksExternally() + this.enableOpenUrl() + this.setBoundsOnClose() + } + + setTimeout(() => { + this.checkForNewUpdates() + this.checkForNewBlogPosts() + }, 500) + }) }) }, methods: { diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 82bb9c0b..46c21784 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -27,6 +27,7 @@ /> diff --git a/src/renderer/store/modules/profile.js b/src/renderer/store/modules/profile.js index d934aedd..f190673b 100644 --- a/src/renderer/store/modules/profile.js +++ b/src/renderer/store/modules/profile.js @@ -47,38 +47,44 @@ const getters = { const actions = { grabAllProfiles ({ rootState, dispatch, commit }, defaultName = null) { - profileDb.find({}, (err, results) => { - if (!err) { - if (results.length === 0) { - dispatch('createDefaultProfile', defaultName) - } else { - // We want the primary profile to always be first - // So sort with that then sort alphabetically by profile name - const profiles = results.sort((a, b) => { - if (a._id === 'allChannels') { - return -1 - } + return new Promise((resolve, reject) => { + profileDb.find({}, (err, results) => { + if (!err) { + if (results.length === 0) { + dispatch('createDefaultProfile', defaultName) + } else { + // We want the primary profile to always be first + // So sort with that then sort alphabetically by profile name + const profiles = results.sort((a, b) => { + if (a._id === 'allChannels') { + return -1 + } - if (b._id === 'allChannels') { - return 1 - } + if (b._id === 'allChannels') { + return 1 + } - return b.name - a.name - }) - - if (state.profileList.length < profiles.length) { - const profileIndex = profiles.findIndex((profile) => { - return profile._id === rootState.settings.defaultProfile + return b.name - a.name }) - if (profileIndex !== -1) { - dispatch('updateActiveProfile', profileIndex) + if (state.profileList.length < profiles.length) { + const profileIndex = profiles.findIndex((profile) => { + return profile._id === rootState.settings.defaultProfile + }) + + if (profileIndex !== -1) { + commit('setActiveProfile', profileIndex) + } } + + commit('setProfileList', profiles) } - commit('setProfileList', profiles) + resolve() + } else { + reject(err) } - } + }) }) },