mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2024-12-29 10:13:36 +01:00
Use ipcRenderer through window to mock ipc method
This commit is contained in:
parent
a805ce6a49
commit
ec9ce16c47
@ -1,7 +1,9 @@
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
||||
import GlobalHeader, { GlobalHeaderState } from '~/src/renderer/store/GlobalHeader'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
;(window as MyWindow).ipcRenderer = ipcRenderer
|
||||
|
||||
const state = (): GlobalHeaderState => {
|
||||
return {
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
||||
import Mastodon, { Instance, Response } from 'megalodon'
|
||||
import Login, { LoginState } from '@/store/Login'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
;(window as MyWindow).ipcRenderer = ipcRenderer
|
||||
|
||||
jest.mock('megalodon')
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
import Mastodon, { Emoji, Instance, Response } from 'megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
||||
import TimelineSpace, { TimelineSpaceState, blankAccount } from '~/src/renderer/store/TimelineSpace'
|
||||
import unreadSettings from '~/src/constants/unreadNotification'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
;(window as MyWindow).ipcRenderer = ipcRenderer
|
||||
|
||||
jest.mock('megalodon')
|
||||
|
||||
|
@ -11,7 +11,9 @@ import { Notify } from '~/src/types/notify'
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { ProxyConfig } from 'megalodon'
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type AppState = {
|
||||
theme: ThemeColorType
|
||||
@ -107,22 +109,22 @@ const mutations: MutationTree<AppState> = {
|
||||
|
||||
const actions: ActionTree<AppState, RootState> = {
|
||||
watchShortcutsEvents: () => {
|
||||
ipcRenderer.on('open-preferences', () => {
|
||||
win.ipcRenderer.on('open-preferences', () => {
|
||||
router.push('/preferences/general')
|
||||
})
|
||||
},
|
||||
removeShortcutsEvents: () => {
|
||||
ipcRenderer.removeAllListeners('open-preferences')
|
||||
win.ipcRenderer.removeAllListeners('open-preferences')
|
||||
},
|
||||
loadPreferences: ({ commit, dispatch }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-preferences')
|
||||
ipcRenderer.once('error-get-preferences', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
win.ipcRenderer.send('get-preferences')
|
||||
win.ipcRenderer.once('error-get-preferences', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
win.ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
win.ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
dispatch('updateTheme', conf.appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle)
|
||||
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize)
|
||||
@ -166,11 +168,11 @@ const actions: ActionTree<AppState, RootState> = {
|
||||
},
|
||||
loadProxy: ({ commit }) => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
|
||||
win.ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
|
||||
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
|
||||
resolve(proxy)
|
||||
})
|
||||
ipcRenderer.send('get-proxy-configuration')
|
||||
win.ipcRenderer.send('get-proxy-configuration')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { Module, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type AuthorizeState = {}
|
||||
|
||||
@ -9,13 +11,13 @@ const state = (): AuthorizeState => ({})
|
||||
const actions: ActionTree<AuthorizeState, RootState> = {
|
||||
submit: (_, code: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-access-token', code.trim())
|
||||
ipcRenderer.once('response-get-access-token', (_, id: string) => {
|
||||
ipcRenderer.removeAllListeners('error-get-access-token')
|
||||
win.ipcRenderer.send('get-access-token', code.trim())
|
||||
win.ipcRenderer.once('response-get-access-token', (_, id: string) => {
|
||||
win.ipcRenderer.removeAllListeners('error-get-access-token')
|
||||
resolve(id)
|
||||
})
|
||||
ipcRenderer.once('error-get-access-token', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-get-access-token')
|
||||
win.ipcRenderer.once('error-get-access-token', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-access-token')
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import router from '@/router'
|
||||
import { LocalAccount } from '~/src/types/localAccount'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { StreamingError } from '~src/errors/streamingError'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type GlobalHeaderState = {
|
||||
accounts: Array<LocalAccount>
|
||||
@ -61,13 +63,13 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
||||
},
|
||||
listAccounts: ({ dispatch, commit }): Promise<Array<LocalAccount>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('list-accounts', 'list')
|
||||
ipcRenderer.once('error-list-accounts', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-list-accounts')
|
||||
win.ipcRenderer.send('list-accounts', 'list')
|
||||
win.ipcRenderer.once('error-list-accounts', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-list-accounts')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-list-accounts', (_, accounts: Array<LocalAccount>) => {
|
||||
ipcRenderer.removeAllListeners('error-list-accounts')
|
||||
win.ipcRenderer.once('response-list-accounts', (_, accounts: Array<LocalAccount>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-list-accounts')
|
||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||
dispatch('refreshAccounts')
|
||||
resolve(accounts)
|
||||
@ -77,20 +79,20 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
||||
// Fetch account informations and save current state when GlobalHeader is displayed
|
||||
refreshAccounts: ({ commit }): Promise<Array<LocalAccount>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('refresh-accounts')
|
||||
ipcRenderer.once('error-refresh-accounts', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-refresh-accounts')
|
||||
win.ipcRenderer.send('refresh-accounts')
|
||||
win.ipcRenderer.once('error-refresh-accounts', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-refresh-accounts')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-refresh-accounts', (_, accounts: Array<LocalAccount>) => {
|
||||
ipcRenderer.removeAllListeners('error-refresh-accounts')
|
||||
win.ipcRenderer.once('response-refresh-accounts', (_, accounts: Array<LocalAccount>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-refresh-accounts')
|
||||
commit(MUTATION_TYPES.UPDATE_ACCOUNTS, accounts)
|
||||
resolve(accounts)
|
||||
})
|
||||
})
|
||||
},
|
||||
watchShortcutEvents: ({ state, commit, rootState, rootGetters }) => {
|
||||
ipcRenderer.on('change-account', (_, account: LocalAccount) => {
|
||||
win.ipcRenderer.on('change-account', (_, account: LocalAccount) => {
|
||||
if (state.changing) {
|
||||
return null
|
||||
}
|
||||
@ -108,13 +110,13 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
||||
})
|
||||
},
|
||||
removeShortcutEvents: async () => {
|
||||
ipcRenderer.removeAllListeners('change-account')
|
||||
win.ipcRenderer.removeAllListeners('change-account')
|
||||
return true
|
||||
},
|
||||
loadHide: ({ commit }): Promise<boolean> => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.send('get-global-header')
|
||||
ipcRenderer.once('response-get-global-header', (_, hide: boolean) => {
|
||||
win.ipcRenderer.send('get-global-header')
|
||||
win.ipcRenderer.once('response-get-global-header', (_, hide: boolean) => {
|
||||
commit(MUTATION_TYPES.CHANGE_HIDE, hide)
|
||||
resolve(hide)
|
||||
})
|
||||
@ -122,8 +124,8 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
||||
},
|
||||
switchHide: ({ dispatch }, hide: boolean): Promise<boolean> => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.send('change-global-header', hide)
|
||||
ipcRenderer.once('response-change-global-header', () => {
|
||||
win.ipcRenderer.send('change-global-header', hide)
|
||||
win.ipcRenderer.once('response-change-global-header', () => {
|
||||
dispatch('loadHide')
|
||||
resolve(true)
|
||||
})
|
||||
@ -132,18 +134,18 @@ const actions: ActionTree<GlobalHeaderState, RootState> = {
|
||||
startUserStreamings: ({ state }): Promise<{}> => {
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('error-start-all-user-streamings', (_, err: StreamingError) => {
|
||||
win.ipcRenderer.once('error-start-all-user-streamings', (_, err: StreamingError) => {
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.send('start-all-user-streamings', state.accounts)
|
||||
win.ipcRenderer.send('start-all-user-streamings', state.accounts)
|
||||
})
|
||||
},
|
||||
stopUserStreamings: () => {
|
||||
ipcRenderer.send('stop-all-user-streamings')
|
||||
win.ipcRenderer.send('stop-all-user-streamings')
|
||||
},
|
||||
bindNotification: () => {
|
||||
ipcRenderer.removeAllListeners('open-notification-tab')
|
||||
ipcRenderer.on('open-notification-tab', (_, id: string) => {
|
||||
win.ipcRenderer.removeAllListeners('open-notification-tab')
|
||||
win.ipcRenderer.on('open-notification-tab', (_, id: string) => {
|
||||
router.push(`/${id}/home`)
|
||||
// We have to wait until change el-menu-item
|
||||
setTimeout(() => router.push(`/${id}/notifications`), 500)
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon, { Instance } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type LoginState = {
|
||||
selectedInstance: string | null
|
||||
@ -30,13 +32,13 @@ const mutations: MutationTree<LoginState> = {
|
||||
const actions: ActionTree<LoginState, RootState> = {
|
||||
fetchLogin: (_, instance: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-auth-url', instance)
|
||||
ipcRenderer.once('error-get-auth-url', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-get-auth-url')
|
||||
win.ipcRenderer.send('get-auth-url', instance)
|
||||
win.ipcRenderer.once('error-get-auth-url', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-auth-url')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-auth-url', (_, url: string) => {
|
||||
ipcRenderer.removeAllListeners('response-get-auth-url')
|
||||
win.ipcRenderer.once('response-get-auth-url', (_, url: string) => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-auth-url')
|
||||
resolve(url)
|
||||
})
|
||||
})
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon, { Account, Emoji, Instance, Status, Notification as NotificationType } from 'megalodon'
|
||||
import SideMenu, { SideMenuState } from './TimelineSpace/SideMenu'
|
||||
import HeaderMenu, { HeaderMenuState } from './TimelineSpace/HeaderMenu'
|
||||
@ -11,6 +10,9 @@ import { RootState } from '@/store'
|
||||
import { UnreadNotification } from '~/src/types/unreadNotification'
|
||||
import { AccountLoadError } from '@/errors/load'
|
||||
import { TimelineFetchError } from '@/errors/fetch'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type TimelineSpaceState = {
|
||||
account: LocalAccount
|
||||
@ -120,13 +122,13 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// -------------------------------------------------
|
||||
localAccount: async ({ dispatch, commit }, id: string): Promise<LocalAccount> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-local-account', id)
|
||||
ipcRenderer.once('error-get-local-account', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-get-local-account')
|
||||
win.ipcRenderer.send('get-local-account', id)
|
||||
win.ipcRenderer.once('error-get-local-account', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-local-account')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-local-account', (_, account: LocalAccount) => {
|
||||
ipcRenderer.removeAllListeners('error-get-local-account')
|
||||
win.ipcRenderer.once('response-get-local-account', (_, account: LocalAccount) => {
|
||||
win.ipcRenderer.removeAllListeners('error-get-local-account')
|
||||
|
||||
if (account.username === undefined || account.username === null || account.username === '') {
|
||||
dispatch('fetchAccount', account)
|
||||
@ -146,13 +148,13 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
},
|
||||
fetchAccount: (_, account: LocalAccount): Promise<LocalAccount> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('update-account', account)
|
||||
ipcRenderer.once('error-update-account', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-update-account')
|
||||
win.ipcRenderer.send('update-account', account)
|
||||
win.ipcRenderer.once('error-update-account', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-update-account')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-account', (_, account: LocalAccount) => {
|
||||
ipcRenderer.removeAllListeners('error-update-account')
|
||||
win.ipcRenderer.once('response-update-account', (_, account: LocalAccount) => {
|
||||
win.ipcRenderer.removeAllListeners('error-update-account')
|
||||
resolve(account)
|
||||
})
|
||||
})
|
||||
@ -173,16 +175,16 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// Shortcuts
|
||||
// -----------------------------------------------
|
||||
watchShortcutEvents: ({ commit, dispatch }) => {
|
||||
ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||
win.ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||
dispatch('TimelineSpace/Modals/NewToot/openModal', {}, { root: true })
|
||||
})
|
||||
ipcRenderer.on('CmdOrCtrl+K', () => {
|
||||
win.ipcRenderer.on('CmdOrCtrl+K', () => {
|
||||
commit('TimelineSpace/Modals/Jump/changeModal', true, { root: true })
|
||||
})
|
||||
},
|
||||
removeShortcutEvents: async () => {
|
||||
ipcRenderer.removeAllListeners('CmdOrCtrl+N')
|
||||
ipcRenderer.removeAllListeners('CmdOrCtrl+K')
|
||||
win.ipcRenderer.removeAllListeners('CmdOrCtrl+N')
|
||||
win.ipcRenderer.removeAllListeners('CmdOrCtrl+K')
|
||||
return true
|
||||
},
|
||||
/**
|
||||
@ -209,13 +211,13 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
},
|
||||
loadUnreadNotification: ({ commit }, accountID: string) => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => {
|
||||
ipcRenderer.removeAllListeners('error-get-unread-notification')
|
||||
win.ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => {
|
||||
win.ipcRenderer.removeAllListeners('error-get-unread-notification')
|
||||
commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings)
|
||||
resolve(settings)
|
||||
})
|
||||
ipcRenderer.once('error-get-unread-notification', () => {
|
||||
ipcRenderer.removeAllListeners('response-get-unread-notification')
|
||||
win.ipcRenderer.once('error-get-unread-notification', () => {
|
||||
win.ipcRenderer.removeAllListeners('response-get-unread-notification')
|
||||
commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, {
|
||||
direct: unreadSettings.Direct.default,
|
||||
local: unreadSettings.Local.default,
|
||||
@ -223,7 +225,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
} as UnreadNotification)
|
||||
resolve({})
|
||||
})
|
||||
ipcRenderer.send('get-unread-notification', accountID)
|
||||
win.ipcRenderer.send('get-unread-notification', accountID)
|
||||
})
|
||||
},
|
||||
fetchContentsTimelines: async ({ dispatch, state }) => {
|
||||
@ -297,7 +299,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
await dispatch('waitToUnbindUserStreaming')
|
||||
|
||||
commit(MUTATION_TYPES.UPDATE_BINDING_ACCOUNT, state.account)
|
||||
ipcRenderer.on(`update-start-all-user-streamings-${state.account._id!}`, (_, update: Status) => {
|
||||
win.ipcRenderer.on(`update-start-all-user-streamings-${state.account._id!}`, (_, update: Status) => {
|
||||
commit('TimelineSpace/Contents/Home/appendTimeline', update, { root: true })
|
||||
// Sometimes archive old statuses
|
||||
if (rootState.TimelineSpace.Contents.Home.heading && Math.random() > 0.8) {
|
||||
@ -305,35 +307,35 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', true, { root: true })
|
||||
})
|
||||
ipcRenderer.on(`notification-start-all-user-streamings-${state.account._id!}`, (_, notification: NotificationType) => {
|
||||
win.ipcRenderer.on(`notification-start-all-user-streamings-${state.account._id!}`, (_, notification: NotificationType) => {
|
||||
commit('TimelineSpace/Contents/Notifications/appendNotifications', notification, { root: true })
|
||||
if (rootState.TimelineSpace.Contents.Notifications.heading && Math.random() > 0.8) {
|
||||
commit('TimelineSpace/Contents/Notifications/archiveNotifications', null, { root: true })
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true })
|
||||
})
|
||||
ipcRenderer.on(`mention-start-all-user-streamings-${state.account._id!}`, (_, mention: NotificationType) => {
|
||||
win.ipcRenderer.on(`mention-start-all-user-streamings-${state.account._id!}`, (_, mention: NotificationType) => {
|
||||
commit('TimelineSpace/Contents/Mentions/appendMentions', mention, { root: true })
|
||||
if (rootState.TimelineSpace.Contents.Mentions.heading && Math.random() > 0.8) {
|
||||
commit('TimelineSpace/Contents/Mentions/archiveMentions', null, { root: true })
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadMentions', true, { root: true })
|
||||
})
|
||||
ipcRenderer.on(`delete-start-all-user-streamings-${state.account._id!}`, (_, id: string) => {
|
||||
win.ipcRenderer.on(`delete-start-all-user-streamings-${state.account._id!}`, (_, id: string) => {
|
||||
commit('TimelineSpace/Contents/Home/deleteToot', id, { root: true })
|
||||
commit('TimelineSpace/Contents/Notifications/deleteToot', id, { root: true })
|
||||
commit('TimelineSpace/Contents/Mentions/deleteToot', id, { root: true })
|
||||
})
|
||||
},
|
||||
bindLocalStreaming: ({ commit, rootState }) => {
|
||||
ipcRenderer.on('update-start-local-streaming', (_, update: Status) => {
|
||||
win.ipcRenderer.on('update-start-local-streaming', (_, update: Status) => {
|
||||
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 })
|
||||
})
|
||||
ipcRenderer.on('delete-start-local-streaming', (_, id: string) => {
|
||||
win.ipcRenderer.on('delete-start-local-streaming', (_, id: string) => {
|
||||
commit('TimelineSpace/Contents/Local/deleteToot', id, { root: true })
|
||||
})
|
||||
},
|
||||
@ -341,23 +343,23 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
ipcRenderer.send('start-local-streaming', {
|
||||
win.ipcRenderer.send('start-local-streaming', {
|
||||
account: state.account
|
||||
})
|
||||
ipcRenderer.once('error-start-local-streaming', (_, err: Error) => {
|
||||
win.ipcRenderer.once('error-start-local-streaming', (_, err: Error) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
bindPublicStreaming: ({ commit, rootState }) => {
|
||||
ipcRenderer.on('update-start-public-streaming', (_, update: Status) => {
|
||||
win.ipcRenderer.on('update-start-public-streaming', (_, update: Status) => {
|
||||
commit('TimelineSpace/Contents/Public/appendTimeline', update, { root: true })
|
||||
if (rootState.TimelineSpace.Contents.Public.heading && Math.random() > 0.8) {
|
||||
commit('TimelineSpace/Contents/Public/archiveTimeline', {}, { root: true })
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', true, { root: true })
|
||||
})
|
||||
ipcRenderer.on('delete-start-public-streaming', (_, id: string) => {
|
||||
win.ipcRenderer.on('delete-start-public-streaming', (_, id: string) => {
|
||||
commit('TimelineSpace/Contents/Public/deleteToot', id, { root: true })
|
||||
})
|
||||
},
|
||||
@ -365,23 +367,23 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
ipcRenderer.send('start-public-streaming', {
|
||||
win.ipcRenderer.send('start-public-streaming', {
|
||||
account: state.account
|
||||
})
|
||||
ipcRenderer.once('error-start-public-streaming', (_, err: Error) => {
|
||||
win.ipcRenderer.once('error-start-public-streaming', (_, err: Error) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
bindDirectMessagesStreaming: ({ commit, rootState }) => {
|
||||
ipcRenderer.on('update-start-directmessages-streaming', (_, update: Status) => {
|
||||
win.ipcRenderer.on('update-start-directmessages-streaming', (_, update: Status) => {
|
||||
commit('TimelineSpace/Contents/DirectMessages/appendTimeline', update, { root: true })
|
||||
if (rootState.TimelineSpace.Contents.DirectMessages.heading && Math.random() > 0.8) {
|
||||
commit('TimelineSpace/Contents/DirectMessages/archiveTimeline', {}, { root: true })
|
||||
}
|
||||
commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', true, { root: true })
|
||||
})
|
||||
ipcRenderer.on('delete-start-directmessages-streaming', (_, id: string) => {
|
||||
win.ipcRenderer.on('delete-start-directmessages-streaming', (_, id: string) => {
|
||||
commit('TimelineSpace/Contents/DirectMessages/deleteToot', id, { root: true })
|
||||
})
|
||||
},
|
||||
@ -389,10 +391,10 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
ipcRenderer.send('start-directmessages-streaming', {
|
||||
win.ipcRenderer.send('start-directmessages-streaming', {
|
||||
account: state.account
|
||||
})
|
||||
ipcRenderer.once('error-start-directmessages-streaming', (_, err: Error) => {
|
||||
win.ipcRenderer.once('error-start-directmessages-streaming', (_, err: Error) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
@ -401,10 +403,10 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
// When unbind is called, sometimes account is already cleared and account does not have _id.
|
||||
// So we have to get previous account to unbind streamings.
|
||||
if (state.bindingAccount) {
|
||||
ipcRenderer.removeAllListeners(`update-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
ipcRenderer.removeAllListeners(`mention-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
ipcRenderer.removeAllListeners(`notification-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
ipcRenderer.removeAllListeners(`delete-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
win.ipcRenderer.removeAllListeners(`update-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
win.ipcRenderer.removeAllListeners(`mention-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
win.ipcRenderer.removeAllListeners(`notification-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
win.ipcRenderer.removeAllListeners(`delete-start-all-user-streamings-${state.bindingAccount._id!}`)
|
||||
// And we have to clear binding account after unbind.
|
||||
commit(MUTATION_TYPES.UPDATE_BINDING_ACCOUNT, null)
|
||||
} else {
|
||||
@ -412,28 +414,28 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
||||
}
|
||||
},
|
||||
unbindLocalStreaming: () => {
|
||||
ipcRenderer.removeAllListeners('error-start-local-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-local-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-local-streaming')
|
||||
win.ipcRenderer.removeAllListeners('error-start-local-streaming')
|
||||
win.ipcRenderer.removeAllListeners('update-start-local-streaming')
|
||||
win.ipcRenderer.removeAllListeners('delete-start-local-streaming')
|
||||
},
|
||||
stopLocalStreaming: () => {
|
||||
ipcRenderer.send('stop-local-streaming')
|
||||
win.ipcRenderer.send('stop-local-streaming')
|
||||
},
|
||||
unbindPublicStreaming: () => {
|
||||
ipcRenderer.removeAllListeners('error-start-public-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-public-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-public-streaming')
|
||||
win.ipcRenderer.removeAllListeners('error-start-public-streaming')
|
||||
win.ipcRenderer.removeAllListeners('update-start-public-streaming')
|
||||
win.ipcRenderer.removeAllListeners('delete-start-public-streaming')
|
||||
},
|
||||
stopPublicStreaming: () => {
|
||||
ipcRenderer.send('stop-public-streaming')
|
||||
win.ipcRenderer.send('stop-public-streaming')
|
||||
},
|
||||
unbindDirectMessagesStreaming: () => {
|
||||
ipcRenderer.removeAllListeners('error-start-directmessages-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-directmessages-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-directmessages-streaming')
|
||||
win.ipcRenderer.removeAllListeners('error-start-directmessages-streaming')
|
||||
win.ipcRenderer.removeAllListeners('update-start-directmessages-streaming')
|
||||
win.ipcRenderer.removeAllListeners('delete-start-directmessages-streaming')
|
||||
},
|
||||
stopDirectMessagesStreaming: () => {
|
||||
ipcRenderer.send('stop-directmessages-streaming')
|
||||
win.ipcRenderer.send('stop-directmessages-streaming')
|
||||
},
|
||||
updateTootForAllTimelines: ({ commit, state }, status: Status): boolean => {
|
||||
commit('TimelineSpace/Contents/Home/updateToot', status, { root: true })
|
||||
|
Loading…
Reference in New Issue
Block a user