1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-01-27 07:46:15 +01:00

refs #24 Listen public streaming in main process, and display public timeline

This commit is contained in:
AkiraFukushima 2018-03-14 14:54:20 +09:00
parent 13c8b8e638
commit 847648fd5d
7 changed files with 108 additions and 16 deletions

View File

@ -291,6 +291,39 @@ ipcMain.on('stop-local-streaming', (event, _) => {
localStreaming = null
})
let publicStreaming = null
ipcMain.on('start-public-streaming', (event, ac) => {
const account = new Account(db)
account.getAccount(ac._id)
.catch((err) => {
event.sender.send('error-start-public-streaming', err)
})
.then((account) => {
// Stop old public streaming
if (publicStreaming !== null) {
publicStreaming.stop()
publicStreaming = null
}
publicStreaming = new Streaming(account)
publicStreaming.start(
'/streaming/public',
(update) => {
event.sender.send('update-start-public-streaming', update)
},
(err) => {
event.sender.send('error-start-public-streaming', err)
}
)
})
})
ipcMain.on('stop-public-streaming', (event, _) => {
publicStreaming.stop()
publicStreaming = null
})
/**
* Auto Updater
*

View File

@ -1,11 +0,0 @@
<template>
<div id="global">
global
</div>
</template>
<script>
export default {
name: 'global'
}
</script>

View File

@ -0,0 +1,35 @@
<template>
<div id="public">
<div class="public-timeline" v-for="message in timeline" v-bind:key="message.id">
<toot :message="message"></toot>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import Toot from './Cards/Toot'
export default {
name: 'public',
components: { Toot },
computed: {
...mapState({
account: state => state.TimelineSpace.account,
timeline: state => state.TimelineSpace.Public.timeline
})
},
created () {
this.$store.dispatch('TimelineSpace/Public/startPublicStreaming', this.account)
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Public/stopPublicStreaming')
}
}
</script>
<style lang="scss" scoped>
#public {
margin-left: 16px;
}
</style>

View File

@ -29,7 +29,7 @@
<icon name="users"></icon>
<span>LocalTimeline</span>
</el-menu-item>
<el-menu-item :index="`/${id()}/global`">
<el-menu-item :index="`/${id()}/public`">
<icon name="globe"></icon>
<span>PublicTimeline</span>
</el-menu-item>

View File

@ -46,9 +46,9 @@ export default new Router({
component: require('@/components/TimelineSpace/Local').default
},
{
path: 'global',
name: 'global',
component: require('@/components/TimelineSpace/Global').default
path: 'public',
name: 'public',
component: require('@/components/TimelineSpace/Public').default
}
]
}

View File

@ -3,6 +3,7 @@ import Mastodon from 'mastodon-api'
import SideMenu from './TimelineSpace/SideMenu'
import Favourites from './TimelineSpace/Favourites'
import Local from './TimelineSpace/Local'
import Public from './TimelineSpace/Public'
import router from '../router'
const TimelineSpace = {
@ -10,7 +11,8 @@ const TimelineSpace = {
modules: {
SideMenu,
Favourites,
Local
Local,
Public
},
state: {
account: {

View File

@ -0,0 +1,33 @@
import { ipcRenderer } from 'electron'
const Public = {
namespaced: true,
state: {
timeline: []
},
mutations: {
appendTimeline (state, update) {
state.timeline = [update].concat(state.timeline)
}
},
actions: {
startPublicStreaming ({ commit }, account) {
ipcRenderer.on('update-start-public-streaming', (event, update) => {
commit('appendTimeline', update)
})
return new Promise((resolve, reject) => {
ipcRenderer.send('start-public-streaming', account)
ipcRenderer.once('error-start-public-streaming', (event, err) => {
reject(err)
})
})
},
stopPublicStreaming ({ commit }) {
ipcRenderer.removeAllListeners('error-start-public-streaming')
ipcRenderer.removeAllListeners('update-start-public-streaming')
ipcRenderer.send('stop-public-streaming')
}
}
}
export default Public