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:
parent
13c8b8e638
commit
847648fd5d
@ -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
|
||||
*
|
||||
|
@ -1,11 +0,0 @@
|
||||
<template>
|
||||
<div id="global">
|
||||
global
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'global'
|
||||
}
|
||||
</script>
|
35
src/renderer/components/TimelineSpace/Public.vue
Normal file
35
src/renderer/components/TimelineSpace/Public.vue
Normal 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>
|
@ -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>
|
||||
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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: {
|
||||
|
33
src/renderer/store/TimelineSpace/Public.js
Normal file
33
src/renderer/store/TimelineSpace/Public.js
Normal 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
|
Loading…
x
Reference in New Issue
Block a user