Merge pull request #304 from h3poteto/iss-299
closes #299 Add a background streaming for local timeline
This commit is contained in:
commit
6e2b2c42d0
|
@ -237,6 +237,18 @@ app.on('window-all-closed', () => {
|
|||
userStreaming.stop()
|
||||
userStreaming = null
|
||||
}
|
||||
if (localStreaming !== null) {
|
||||
localStreaming.stop()
|
||||
localStreaming = null
|
||||
}
|
||||
if (publicStreaming !== null) {
|
||||
publicStreaming.stop()
|
||||
publicStreaming = null
|
||||
}
|
||||
if (listStreaming !== null) {
|
||||
listStreaming.stop()
|
||||
listStreaming = null
|
||||
}
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
|
|
|
@ -39,11 +39,13 @@ export default {
|
|||
},
|
||||
beforeDestroy () {
|
||||
this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
||||
this.$store.dispatch('TimelineSpace/stopLocalStreaming')
|
||||
},
|
||||
methods: {
|
||||
async clear () {
|
||||
await this.$store.dispatch('TimelineSpace/clearAccount')
|
||||
await this.$store.commit('TimelineSpace/Contents/Home/clearTimeline')
|
||||
await this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
|
||||
await this.$store.commit('TimelineSpace/Contents/Notifications/clearNotifications')
|
||||
await this.$store.dispatch('TimelineSpace/removeShortcutEvents')
|
||||
return 'clear'
|
||||
|
@ -74,6 +76,14 @@ export default {
|
|||
type: 'error'
|
||||
})
|
||||
}
|
||||
try {
|
||||
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not fetch local timeline',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
this.$store.dispatch('TimelineSpace/SideMenu/fetchLists', account)
|
||||
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
||||
.catch(() => {
|
||||
|
@ -82,6 +92,7 @@ export default {
|
|||
type: 'error'
|
||||
})
|
||||
})
|
||||
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ export default {
|
|||
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
||||
},
|
||||
beforeUpdate () {
|
||||
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline) {
|
||||
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline && this.heading) {
|
||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -27,53 +27,25 @@ export default {
|
|||
unread: state => state.TimelineSpace.Contents.Local.unreadTimeline
|
||||
})
|
||||
},
|
||||
created () {
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
text: 'Loading',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
})
|
||||
this.initialize()
|
||||
.then(() => {
|
||||
loading.close()
|
||||
})
|
||||
.catch(() => {
|
||||
loading.close()
|
||||
})
|
||||
mounted () {
|
||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', false)
|
||||
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.$store.dispatch('TimelineSpace/Contents/Local/stopLocalStreaming')
|
||||
beforeUpdate () {
|
||||
if (this.$store.state.TimelineSpace.SideMenu.unreadLocalTimeline && this.heading) {
|
||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', false)
|
||||
}
|
||||
},
|
||||
destroyed () {
|
||||
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
|
||||
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
|
||||
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
|
||||
this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
|
||||
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
|
||||
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
|
||||
document.getElementById('scrollable').scrollTop = 0
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async initialize () {
|
||||
try {
|
||||
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline')
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not fetch timeline',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
this.$store.dispatch('TimelineSpace/Contents/Local/startLocalStreaming')
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Failed to start streaming',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
},
|
||||
updateToot (message) {
|
||||
this.$store.commit('TimelineSpace/Contents/Local/updateToot', message)
|
||||
},
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
<el-menu-item :index="`/${id()}/local`">
|
||||
<icon name="users"></icon>
|
||||
<span>Local timeline</span>
|
||||
<el-badge is-dot :hidden="!unreadLocalTimeline">
|
||||
</el-badge>
|
||||
</el-menu-item>
|
||||
<el-menu-item :index="`/${id()}/public`">
|
||||
<icon name="globe"></icon>
|
||||
|
@ -74,6 +76,7 @@ export default {
|
|||
account: state => state.TimelineSpace.account,
|
||||
unreadHomeTimeline: state => state.TimelineSpace.SideMenu.unreadHomeTimeline,
|
||||
unreadNotifications: state => state.TimelineSpace.SideMenu.unreadNotifications,
|
||||
unreadLocalTimeline: state => state.TimelineSpace.SideMenu.unreadLocalTimeline,
|
||||
lists: state => state.TimelineSpace.SideMenu.lists,
|
||||
themeColor: state => state.App.theme.side_menu_color
|
||||
})
|
||||
|
|
|
@ -93,6 +93,21 @@ const TimelineSpace = {
|
|||
})
|
||||
})
|
||||
},
|
||||
startLocalStreaming ({ state, commit, rootState }, account) {
|
||||
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
||||
commit('TimelineSpace/Contents/Local/appendTimeline', update, { root: true })
|
||||
if (rootState.TimelineSpace.Contents.Local.heading && Math.random() > 0.8) {
|
||||
commit('TimelineSpace/Contents/Local/archiveTimeline', {}, { root: true })
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', true, { root: true })
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('start-local-streaming', account)
|
||||
ipcRenderer.once('error-start-local-streaming', (event, err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
async stopUserStreaming ({ commit }) {
|
||||
ipcRenderer.removeAllListeners('update-start-user-streaming')
|
||||
ipcRenderer.removeAllListeners('notification-start-user-streaming')
|
||||
|
@ -100,6 +115,12 @@ const TimelineSpace = {
|
|||
ipcRenderer.send('stop-user-streaming')
|
||||
return 'stopUserStreaming'
|
||||
},
|
||||
async stopLocalStreaming ({ commit }) {
|
||||
ipcRenderer.removeAllListeners('error-start-local-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-local-streaming')
|
||||
ipcRenderer.send('stop-local-streaming')
|
||||
return 'stopLocalStreaming'
|
||||
},
|
||||
watchShortcutEvents ({ commit }) {
|
||||
ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||
commit('TimelineSpace/Modals/NewToot/changeModal', true, { root: true })
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon from 'mastodon-api'
|
||||
|
||||
const Local = {
|
||||
|
@ -67,12 +66,12 @@ const Local = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
fetchLocalTimeline ({ state, commit, rootState }) {
|
||||
fetchLocalTimeline ({ commit }, account) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = new Mastodon(
|
||||
{
|
||||
access_token: rootState.TimelineSpace.account.accessToken,
|
||||
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||
access_token: account.accessToken,
|
||||
api_url: account.baseURL + '/api/v1'
|
||||
}
|
||||
)
|
||||
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
|
||||
|
@ -82,25 +81,6 @@ const Local = {
|
|||
})
|
||||
})
|
||||
},
|
||||
startLocalStreaming ({ state, commit, rootState }) {
|
||||
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
||||
commit('appendTimeline', update)
|
||||
if (state.heading && Math.random() > 0.8) {
|
||||
commit('archiveTimeline')
|
||||
}
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('start-local-streaming', rootState.TimelineSpace.account)
|
||||
ipcRenderer.once('error-start-local-streaming', (event, err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
stopLocalStreaming ({ commit }) {
|
||||
ipcRenderer.removeAllListeners('error-start-local-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-local-streaming')
|
||||
ipcRenderer.send('stop-local-streaming')
|
||||
},
|
||||
lazyFetchTimeline ({ state, commit, rootState }, last) {
|
||||
if (last === undefined || last === null) {
|
||||
return null
|
||||
|
|
|
@ -5,6 +5,7 @@ const SideMenu = {
|
|||
state: {
|
||||
unreadHomeTimeline: false,
|
||||
unreadNotifications: false,
|
||||
unreadLocalTimeline: false,
|
||||
lists: []
|
||||
},
|
||||
mutations: {
|
||||
|
@ -14,6 +15,9 @@ const SideMenu = {
|
|||
changeUnreadNotifications (state, value) {
|
||||
state.unreadNotifications = value
|
||||
},
|
||||
changeUnreadLocalTimeline (state, value) {
|
||||
state.unreadLocalTimeline = value
|
||||
},
|
||||
updateLists (state, lists) {
|
||||
state.lists = lists
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue