diff --git a/src/main/streaming_manager.js b/src/main/streaming_manager.js index f0b5f727..097f8d5f 100644 --- a/src/main/streaming_manager.js +++ b/src/main/streaming_manager.js @@ -1,7 +1,5 @@ -import Mastodon from 'megalodon' import Streaming from './streaming' import WebSocket from './websocket' -import log from 'electron-log' export default class StreamingManager { constructor (account, useWebsocket = false) { @@ -11,40 +9,20 @@ export default class StreamingManager { this.useWebsocket = useWebsocket } - /** - * Find Pleroma comment in the response - */ - async detectPleroma () { - const data = await Mastodon.get('/instance', {}, this.account.baseURL + '/api/v1') - if (data.version.includes('Pleroma')) { - log.info('detect Pleroma') - return true - } - return false - } - startUser (updateCallback, notificationCallback, errCallback) { - this.detectPleroma() - .then((isPleroma) => { - if (isPleroma || this.useWebsocket) { - this._startUserSocket(updateCallback, notificationCallback, errCallback) - } else { - this._startUserStreaming(updateCallback, notificationCallback, errCallback) - } - }) - .catch(err => errCallback(err)) + if (this.useWebsocket) { + this._startUserSocket(updateCallback, notificationCallback, errCallback) + } else { + this._startUserStreaming(updateCallback, notificationCallback, errCallback) + } } start (path, params, updateCallback, errCallback) { - this.detectPleroma() - .then((isPleroma) => { - if (isPleroma || this.useWebsocket) { - this._startSocket(path, params, updateCallback, errCallback) - } else { - this._startStreaming(path, params, updateCallback, errCallback) - } - }) - .catch(err => errCallback(err)) + if (this.useWebsocket) { + this._startSocket(path, params, updateCallback, errCallback) + } else { + this._startStreaming(path, params, updateCallback, errCallback) + } } stop () { diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue index cb6cbe89..3c870594 100644 --- a/src/renderer/components/TimelineSpace.vue +++ b/src/renderer/components/TimelineSpace.vue @@ -106,6 +106,7 @@ export default { }) }) + await this.$store.dispatch('TimelineSpace/detectPleroma') // Bind streamings await this.$store.dispatch('TimelineSpace/bindStreamings', account) // Start streamings diff --git a/src/renderer/components/TimelineSpace/HeaderMenu.vue b/src/renderer/components/TimelineSpace/HeaderMenu.vue index d4775967..8efce734 100644 --- a/src/renderer/components/TimelineSpace/HeaderMenu.vue +++ b/src/renderer/components/TimelineSpace/HeaderMenu.vue @@ -4,7 +4,7 @@

{{ title }}

- + @@ -74,7 +74,8 @@ export default { title: state => state.title }), ...mapState('TimelineSpace', { - useWebsocket: state => state.useWebsocket + useWebsocket: state => state.useWebsocket, + pleroma: state => state.pleroma }) }, created () { diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js index b4fe329a..0ab673ee 100644 --- a/src/renderer/store/TimelineSpace.js +++ b/src/renderer/store/TimelineSpace.js @@ -30,7 +30,8 @@ const TimelineSpace = { local: unreadSettings.Local.default, public: unreadSettings.Public.default }, - useWebsocket: false + useWebsocket: false, + pleroma: false }, mutations: { updateAccount (state, account) { @@ -57,6 +58,9 @@ const TimelineSpace = { updateUnreadNotification (state, settings) { state.unreadNotification = settings }, + changePleroma (state, pleroma) { + state.pleroma = pleroma + }, changeUseWebsocket (state, use) { state.useWebsocket = use } @@ -115,6 +119,16 @@ const TimelineSpace = { ) return 'clearAccount' }, + async detectPleroma ({ commit, state }) { + const data = await Mastodon.get('/instance', {}, state.account.baseURL + '/api/v1') + if (data.version.includes('Pleroma')) { + commit('changePleroma', true) + commit('changeUseWebsocket', true) + } else { + commit('changePleroma', false) + commit('changeUseWebsocket', false) + } + }, // ----------------------------------------------- // Shortcuts // -----------------------------------------------