From c9f8d85926c319d9efd8b7f7326e05080ca2ad18 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 14 May 2018 09:21:11 +0900
Subject: [PATCH 1/3] refs #299 Clean streaming when window-all-close
---
src/main/index.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/main/index.js b/src/main/index.js
index 2d79195b..3cbafe46 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -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()
}
From d0fe2ffa57e4877438e909e2e9a49533906371d5 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 14 May 2018 21:37:34 +0900
Subject: [PATCH 2/3] refs #299 Start local streaming when initialize timeline
space
---
src/renderer/components/TimelineSpace.vue | 11 ++++++
.../TimelineSpace/Contents/Local.vue | 36 +------------------
src/renderer/store/TimelineSpace.js | 20 +++++++++++
.../store/TimelineSpace/Contents/Local.js | 26 ++------------
4 files changed, 35 insertions(+), 58 deletions(-)
diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue
index c6d549b6..40f7ad7a 100644
--- a/src/renderer/components/TimelineSpace.vue
+++ b/src/renderer/components/TimelineSpace.vue
@@ -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)
}
}
}
diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue
index b06bcefd..a16945b2 100644
--- a/src/renderer/components/TimelineSpace/Contents/Local.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Local.vue
@@ -27,53 +27,19 @@ 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 () {
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
},
- beforeDestroy () {
- this.$store.dispatch('TimelineSpace/Contents/Local/stopLocalStreaming')
- },
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)
},
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index 0526152e..f72641a3 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -93,6 +93,20 @@ 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 })
+ }
+ })
+ 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 +114,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 })
diff --git a/src/renderer/store/TimelineSpace/Contents/Local.js b/src/renderer/store/TimelineSpace/Contents/Local.js
index 84e7c94b..e7cf7267 100644
--- a/src/renderer/store/TimelineSpace/Contents/Local.js
+++ b/src/renderer/store/TimelineSpace/Contents/Local.js
@@ -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
From ea120ae97ecaf9cfdbfc75d9ba25ba3f6a192891 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 14 May 2018 21:52:04 +0900
Subject: [PATCH 3/3] refs #299 Manage unread mark for local timeline
---
src/renderer/components/TimelineSpace/Contents/Home.vue | 2 +-
src/renderer/components/TimelineSpace/Contents/Local.vue | 6 ++++++
src/renderer/components/TimelineSpace/SideMenu.vue | 3 +++
src/renderer/store/TimelineSpace.js | 1 +
src/renderer/store/TimelineSpace/SideMenu.js | 4 ++++
5 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/renderer/components/TimelineSpace/Contents/Home.vue b/src/renderer/components/TimelineSpace/Contents/Home.vue
index 2ea00022..a2b698a3 100644
--- a/src/renderer/components/TimelineSpace/Contents/Home.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Home.vue
@@ -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)
}
},
diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue
index a16945b2..b6da97f4 100644
--- a/src/renderer/components/TimelineSpace/Contents/Local.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Local.vue
@@ -28,8 +28,14 @@ export default {
})
},
mounted () {
+ this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', false)
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
},
+ 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')
diff --git a/src/renderer/components/TimelineSpace/SideMenu.vue b/src/renderer/components/TimelineSpace/SideMenu.vue
index 8c4a3651..daad2a56 100644
--- a/src/renderer/components/TimelineSpace/SideMenu.vue
+++ b/src/renderer/components/TimelineSpace/SideMenu.vue
@@ -41,6 +41,8 @@
Local timeline
+
+
@@ -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
})
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index f72641a3..c27fcfe8 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -99,6 +99,7 @@ const TimelineSpace = {
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)
diff --git a/src/renderer/store/TimelineSpace/SideMenu.js b/src/renderer/store/TimelineSpace/SideMenu.js
index b9471b4c..22b630da 100644
--- a/src/renderer/store/TimelineSpace/SideMenu.js
+++ b/src/renderer/store/TimelineSpace/SideMenu.js
@@ -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
}