refs #901 Use ipcRenderer directly from electron
This commit is contained in:
parent
d8e84b18f8
commit
9844c35750
|
@ -1,6 +1,6 @@
|
||||||
import { createLocalVue } from '@vue/test-utils'
|
import { createLocalVue } from '@vue/test-utils'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
import { ipcMain } from '~/spec/mock/electron'
|
||||||
import App from '@/store/App'
|
import App from '@/store/App'
|
||||||
import DisplayStyle from '~/src/constants/displayStyle'
|
import DisplayStyle from '~/src/constants/displayStyle'
|
||||||
import { LightTheme, DarkTheme } from '~/src/constants/themeColor'
|
import { LightTheme, DarkTheme } from '~/src/constants/themeColor'
|
||||||
|
@ -8,7 +8,6 @@ import Theme from '~/src/constants/theme'
|
||||||
import TimeFormat from '~/src/constants/timeFormat'
|
import TimeFormat from '~/src/constants/timeFormat'
|
||||||
import Language from '~/src/constants/language'
|
import Language from '~/src/constants/language'
|
||||||
import DefaultFonts from '@/utils/fonts'
|
import DefaultFonts from '@/utils/fonts'
|
||||||
import { MyWindow } from '~/src/types/global'
|
|
||||||
|
|
||||||
const state = () => {
|
const state = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -44,7 +43,6 @@ describe('App', () => {
|
||||||
let localVue
|
let localVue
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
;(<MyWindow>window).ipcRenderer = ipcRenderer
|
|
||||||
localVue = createLocalVue()
|
localVue = createLocalVue()
|
||||||
localVue.use(Vuex)
|
localVue.use(Vuex)
|
||||||
store = new Vuex.Store({
|
store = new Vuex.Store({
|
||||||
|
|
|
@ -11,9 +11,7 @@ import { Notify } from '~/src/types/notify'
|
||||||
import { BaseConfig } from '~/src/types/preference'
|
import { BaseConfig } from '~/src/types/preference'
|
||||||
import { Appearance } from '~/src/types/appearance'
|
import { Appearance } from '~/src/types/appearance'
|
||||||
import { ProxyConfig } from 'megalodon'
|
import { ProxyConfig } from 'megalodon'
|
||||||
import { MyWindow } from '~/src/types/global'
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
const win = window as MyWindow
|
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
theme: ThemeColorType
|
theme: ThemeColorType
|
||||||
|
@ -109,22 +107,22 @@ const mutations: MutationTree<AppState> = {
|
||||||
|
|
||||||
const actions: ActionTree<AppState, RootState> = {
|
const actions: ActionTree<AppState, RootState> = {
|
||||||
watchShortcutsEvents: () => {
|
watchShortcutsEvents: () => {
|
||||||
win.ipcRenderer.on('open-preferences', () => {
|
ipcRenderer.on('open-preferences', () => {
|
||||||
router.push('/preferences/general')
|
router.push('/preferences/general')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
removeShortcutsEvents: () => {
|
removeShortcutsEvents: () => {
|
||||||
win.ipcRenderer.removeAllListeners('open-preferences')
|
ipcRenderer.removeAllListeners('open-preferences')
|
||||||
},
|
},
|
||||||
loadPreferences: ({ commit, dispatch }) => {
|
loadPreferences: ({ commit, dispatch }) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
win.ipcRenderer.send('get-preferences')
|
ipcRenderer.send('get-preferences')
|
||||||
win.ipcRenderer.once('error-get-preferences', (_, err: Error) => {
|
ipcRenderer.once('error-get-preferences', (_, err: Error) => {
|
||||||
win.ipcRenderer.removeAllListeners('response-get-preferences')
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
win.ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
win.ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
dispatch('updateTheme', conf.appearance)
|
dispatch('updateTheme', conf.appearance)
|
||||||
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle)
|
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle)
|
||||||
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize)
|
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize)
|
||||||
|
@ -168,11 +166,11 @@ const actions: ActionTree<AppState, RootState> = {
|
||||||
},
|
},
|
||||||
loadProxy: ({ commit }) => {
|
loadProxy: ({ commit }) => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
win.ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
|
ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ProxyConfig | false) => {
|
||||||
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
|
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
|
||||||
resolve(proxy)
|
resolve(proxy)
|
||||||
})
|
})
|
||||||
win.ipcRenderer.send('get-proxy-configuration')
|
ipcRenderer.send('get-proxy-configuration')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue