From ba97ac2447acebb47e1c8701bbd49cfa34926eb9 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Wed, 4 Dec 2019 22:48:55 +0900
Subject: [PATCH] Use ipcRenderer through window to mock ipc method in Settings
---
src/renderer/store/Settings/Timeline.ts | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/renderer/store/Settings/Timeline.ts b/src/renderer/store/Settings/Timeline.ts
index 301601e7..fd5952fc 100644
--- a/src/renderer/store/Settings/Timeline.ts
+++ b/src/renderer/store/Settings/Timeline.ts
@@ -1,8 +1,10 @@
-import { ipcRenderer } from 'electron'
import unreadSettings from '~/src/constants/unreadNotification'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
import { UnreadNotification } from '~/src/types/unreadNotification'
+import { MyWindow } from '~/src/types/global'
+
+const win = window as MyWindow
export type TimelineState = {
unreadNotification: UnreadNotification
@@ -29,13 +31,13 @@ const mutations: MutationTree = {
const actions: ActionTree = {
loadUnreadNotification: ({ commit, rootState }): Promise => {
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(true)
})
- 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')
const settings: UnreadNotification = {
direct: unreadSettings.Direct.default,
local: unreadSettings.Local.default,
@@ -44,7 +46,7 @@ const actions: ActionTree = {
commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings)
resolve(false)
})
- ipcRenderer.send('get-unread-notification', rootState.Settings.accountID)
+ win.ipcRenderer.send('get-unread-notification', rootState.Settings.accountID)
})
},
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise => {
@@ -52,16 +54,16 @@ const actions: ActionTree = {
accountID: rootState.Settings.accountID
})
return new Promise((resolve, reject) => {
- ipcRenderer.once('response-update-unread-notification', () => {
- ipcRenderer.removeAllListeners('error-update-unread-notification')
+ win.ipcRenderer.once('response-update-unread-notification', () => {
+ win.ipcRenderer.removeAllListeners('error-update-unread-notification')
dispatch('loadUnreadNotification')
resolve(true)
})
- ipcRenderer.once('error-update-unread-notification', (_, err: Error) => {
- ipcRenderer.removeAllListeners('response-update-unread-notification')
+ win.ipcRenderer.once('error-update-unread-notification', (_, err: Error) => {
+ win.ipcRenderer.removeAllListeners('response-update-unread-notification')
reject(err)
})
- ipcRenderer.send('update-unread-notification', settings)
+ win.ipcRenderer.send('update-unread-notification', settings)
})
}
}