Merge pull request #813 from h3poteto/iss-209

refs #209 Add Preferences store tests
This commit is contained in:
AkiraFukushima 2018-12-30 17:02:04 +09:00 committed by GitHub
commit 679e28c69a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 766 additions and 69 deletions

View File

@ -25,4 +25,4 @@ jobs:
- node_modules
- run:
name: spec
command: npm run spec:unit
command: npm run spec

16
package-lock.json generated
View File

@ -656,6 +656,16 @@
}
}
},
"@vue/test-utils": {
"version": "1.0.0-beta.28",
"resolved": "https://registry.npmjs.org/@vue/test-utils/-/test-utils-1.0.0-beta.28.tgz",
"integrity": "sha512-uVbFJG0g/H9hf2pgWUdhvQYItRGzQ44cMFf00wp0YEo85pxuvM9e3mx8QLQfx6R2CogxbK4CvV7qvkLblehXeQ==",
"dev": true,
"requires": {
"dom-event-types": "1.0.0",
"lodash": "4.17.11"
}
},
"@webassemblyjs/ast": {
"version": "1.7.11",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.7.11.tgz",
@ -5407,6 +5417,12 @@
"utila": "0.4.0"
}
},
"dom-event-types": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/dom-event-types/-/dom-event-types-1.0.0.tgz",
"integrity": "sha512-2G2Vwi2zXTHBGqXHsJ4+ak/iP0N8Ar+G8a7LiD2oup5o4sQWytwqqrZu/O6hIMV0KMID2PL69OhpshLO0n7UJQ==",
"dev": true
},
"dom-serialize": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz",

View File

@ -39,7 +39,7 @@
"test": "npm run unit && npm run e2e",
"unit": "karma start test/unit/karma.conf.js",
"postinstall": "npm run lint:fix",
"spec:unit": "NODE_ENV=test jest -u ./spec/unit/*/**.spec.js"
"spec": "NODE_ENV=test jest -u"
},
"build": {
"productName": "Whalebird",
@ -95,7 +95,10 @@
"^@/(.+)": "<rootDir>/src/renderer/$1",
"^~/(.+)": "<rootDir>/$1",
"electron": "<rootDir>/spec/mock/electron.js"
}
},
"testMatch": [
"**/spec/**/*.spec.js?(x)"
]
},
"dependencies": {
"@panter/vue-i18next": "^0.13.0",
@ -142,6 +145,7 @@
},
"devDependencies": {
"@mapbox/stylelint-processor-arbitrary-tags": "^0.2.0",
"@vue/test-utils": "^1.0.0-beta.28",
"ajv": "^6.6.1",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",

View File

@ -0,0 +1,90 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Theme from '~/src/constants/theme'
import DisplayStyle from '~/src/constants/displayStyle'
import TimeFormat from '~/src/constants/timeFormat'
import { LightTheme, DarkTheme } from '~/src/renderer/utils/theme'
import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron'
const state = {
appearance: {
theme: Theme.Light.key,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme,
font: DefaultFonts[0]
},
fonts: []
}
const Preferences = {
namespaced: true,
state: state,
actions: Appearance.actions,
mutations: Appearance.mutations
}
const App = {
namespaced: true,
actions: {
loadPreferences: jest.fn()
}
}
describe('Preferences/Appearance', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences,
App
}
})
ipcMain.once('update-preferences', (event, config) => {
event.sender.send('response-update-preferences', config)
})
})
it('updateTheme', async () => {
await store.dispatch('Preferences/updateTheme', Theme.Dark.key)
expect(store.state.Preferences.appearance.theme).toEqual(Theme.Dark.key)
expect(App.actions.loadPreferences).toBeCalled()
})
it('updateFontSize', async () => {
await store.dispatch('Preferences/updateFontSize', 15)
expect(store.state.Preferences.appearance.fontSize).toEqual(15)
expect(App.actions.loadPreferences).toBeCalled()
})
it('updateDisplayNameStyle', async () => {
await store.dispatch('Preferences/updateDisplayNameStyle', DisplayStyle.DisplayName.value)
expect(store.state.Preferences.appearance.displayNameStyle).toEqual(DisplayStyle.DisplayName.value)
expect(App.actions.loadPreferences).toBeCalled()
})
it('updateTimeFormat', async () => {
await store.dispatch('Preferences/updateTimeFormat', TimeFormat.Relative.value)
expect(store.state.Preferences.appearance.timeFormat).toEqual(TimeFormat.Relative.value)
expect(App.actions.loadPreferences).toBeCalled()
})
it('updateCustomThemeColor', async () => {
await store.dispatch('Preferences/updateCustomThemeColor', DarkTheme)
expect(store.state.Preferences.appearance.customThemeColor).toEqual(DarkTheme)
expect(App.actions.loadPreferences).toBeCalled()
})
it('updateFont', async () => {
await store.dispatch('Preferences/updateFont', DefaultFonts[1])
expect(store.state.Preferences.appearance.font).toEqual(DefaultFonts[1])
expect(App.actions.loadPreferences).toBeCalled()
})
})

View File

@ -0,0 +1,74 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import General from '@/store/Preferences/General'
const state = {
general: {
sound: {
fav_rb: true,
toot: true
}
},
loading: false
}
const Preferences = {
namespaced: true,
state: state,
actions: General.actions,
mutations: General.mutations
}
describe('Preferences/General', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences
}
})
})
describe('loadGeneral', () => {
beforeEach(() => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('response-get-preferences', {
general: {
sound: {
fav_rb: false,
toot: false
}
}
})
})
})
it('should be updated', async () => {
await store.dispatch('Preferences/loadGeneral')
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.general.sound.toot).toEqual(false)
expect(store.state.Preferences.loading).toEqual(false)
})
})
describe('updateSound', () => {
beforeEach(() => {
ipcMain.once('update-preferences', (event, config) => {
event.sender.send('response-update-preferences', config)
})
})
it('should be updated', async () => {
await store.dispatch('Preferences/updateSound', {
fav_rb: false,
toot: false
})
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.general.sound.toot).toEqual(false)
expect(store.state.Preferences.loading).toEqual(false)
})
})
})

View File

@ -0,0 +1,61 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Language from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
const state = {
language: {
language: DefaultLanguage.en.key
}
}
const initState = {
namespaced: true,
state: state,
actions: Language.actions,
mutations: Language.mutations
}
describe('Preferences/Language', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Language: initState
}
})
})
describe('loadLanguage', () => {
beforeEach(() => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('response-get-preferences', {
language: {
language: DefaultLanguage.ja.key
}
})
})
})
it('should be updated', async () => {
await store.dispatch('Language/loadLanguage')
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
})
})
describe('changeLanguage', () => {
beforeEach(() => {
ipcMain.once('change-language', (event, key) => {
event.sender.send('response-change-language', key)
})
})
it('should be changed', async () => {
await store.dispatch('Language/changeLanguage', DefaultLanguage.ja.key)
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
})
})
})

View File

@ -0,0 +1,96 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Notification from '@/store/Preferences/Notification'
const state = {
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
}
}
}
const initState = {
namespaced: true,
state: state,
actions: Notification.actions,
mutations: Notification.mutations
}
const App = {
namespaced: true,
actions: {
loadPreferences: jest.fn()
}
}
describe('Preferences/Notification', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Notification: initState,
App: App
}
})
})
describe('loadNotification', () => {
beforeEach(() => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('response-get-preferences', {
notification: {
notify: {
reply: false,
reblog: false,
favourite: false,
follow: false
}
}
})
})
it('should be updated', async () => {
await store.dispatch('Notification/loadNotification')
expect(store.state.Notification.notification).toEqual({
notify: {
reply: false,
reblog: false,
favourite: false,
follow: false
}
})
})
})
})
describe('updateNotify', () => {
beforeEach(() => {
ipcMain.once('update-preferences', (event, conf) => {
event.sender.send('response-update-preferences', conf)
})
})
it('should be updated', async () => {
await store.dispatch('Notification/updateNotify', {
reply: false,
reblog: false
})
expect(store.state.Notification.notification).toEqual({
notify: {
reply: false,
reblog: false,
favourite: true,
follow: true
}
})
expect(App.actions.loadPreferences).toBeCalled()
})
})
})

View File

@ -0,0 +1,136 @@
import Account from '@/store/Preferences/Account'
import { ipcMain } from '~/spec/mock/electron'
describe('Preferences/Account', () => {
describe('mutations', () => {
let state
beforeEach(() => {
state = {
accounts: [],
accountLoading: false
}
})
describe('updateAccounts', () => {
it('should be updated', () => {
Account.mutations.updateAccounts(state, ['account'])
expect(state.accounts).toEqual(['account'])
})
})
describe('updateAccountLoading', () => {
it('should be update', () => {
Account.mutations.updateAccountLoading(state, true)
expect(state.accountLoading).toEqual(true)
})
})
})
describe('actions', () => {
describe('loadAccounts', () => {
it('error', async () => {
ipcMain.once('list-accounts', (event, _) => {
event.sender.send('error-list-accounts', new LoadAccountsError())
})
const commitMock = jest.fn()
await Account.actions.loadAccounts({ commit: commitMock })
.catch((err) => {
expect(err instanceof LoadAccountsError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('list-accounts', (event, _) => {
event.sender.send('response-list-accounts', ['accounts'])
})
const commitMock = jest.fn()
const accounts = await Account.actions.loadAccounts({ commit: commitMock })
expect(accounts).toEqual(['accounts'])
expect(commitMock).toHaveBeenCalledWith('updateAccounts', ['accounts'])
})
})
describe('removeAccount', () => {
it('error', async () => {
ipcMain.once('remove-account', (event, _) => {
event.sender.send('error-remove-account', new RemoveAccountError())
})
const commitMock = jest.fn()
await Account.actions.removeAccount({ commit: commitMock }, 'account')
.catch((err) => {
expect(err instanceof RemoveAccountError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('remove-account', (event, _) => {
event.sender.send('response-remove-account', 1)
})
const commitMock = jest.fn()
const res = await Account.actions.removeAccount({ commit: commitMock }, 'account')
expect(res).toEqual(undefined)
})
})
describe('forwardAccount', () => {
it('error', async () => {
ipcMain.once('forward-account', (event, _) => {
event.sender.send('error-forward-account', new ForwardAccountError())
})
const commitMock = jest.fn()
await Account.actions.forwardAccount({ commit: commitMock }, 'account')
.catch((err) => {
expect(err instanceof ForwardAccountError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('forward-account', (event, _) => {
event.sender.send('response-forward-account', 1)
})
const commitMock = jest.fn()
const res = await Account.actions.forwardAccount({ commit: commitMock }, 'account')
expect(res).toEqual(undefined)
})
})
describe('backwardAccount', () => {
it('error', async () => {
ipcMain.once('backward-account', (event, _) => {
event.sender.send('error-backward-account', new BackwardAccountError())
})
const commitMock = jest.fn()
await Account.actions.backwardAccount({ commit: commitMock }, 'account')
.catch((err) => {
expect(err instanceof BackwardAccountError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('backward-account', (event, _) => {
event.sender.send('response-backward-account', 1)
})
const commitMock = jest.fn()
const res = await Account.actions.backwardAccount({ commit: commitMock }, 'account')
expect(res).toEqual(undefined)
})
})
describe('removeAllAccounts', () => {
it('error', async () => {
ipcMain.once('remove-all-accounts', (event, _) => {
event.sender.send('error-remove-all-accounts', new RemoveAllAccountsError())
})
const commitMock = jest.fn()
await Account.actions.removeAllAccounts({ commit: commitMock }, 'account')
.catch((err) => {
expect(err instanceof RemoveAllAccountsError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('remove-all-accounts', (event, _) => {
event.sender.send('response-remove-all-accounts', 1)
})
const commitMock = jest.fn()
const res = await Account.actions.removeAllAccounts({ commit: commitMock }, 'account')
expect(res).toEqual(undefined)
})
})
})
})
class LoadAccountsError extends Error {}
class RemoveAccountError extends Error {}
class ForwardAccountError extends Error {}
class BackwardAccountError extends Error {}
class RemoveAllAccountsError extends Error {}

View File

@ -0,0 +1,93 @@
import Theme from '~/src/constants/theme'
import DisplayStyle from '~/src/constants/displayStyle'
import TimeFormat from '~/src/constants/timeFormat'
import { LightTheme } from '~/src/renderer/utils/theme'
import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron'
describe('Preferences/Appearance', () => {
let state
beforeEach(() => {
state = {
appearance: {
theme: Theme.Light.key,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme,
font: DefaultFonts[0]
},
fonts: []
}
})
describe('mutations', () => {
describe('updateAppearance', () => {
it('should be changed', () => {
Appearance.mutations.updateAppearance(state, {
theme: Theme.Dark.key
})
expect(state.appearance.theme).toEqual(Theme.Dark.key)
})
})
describe('updateFonts', () => {
it('should be changed', () => {
Appearance.mutations.updateFonts(state, ['font'])
expect(state.fonts).toEqual(['font'])
})
})
})
describe('actions', () => {
describe('loadAppearance', () => {
it('error', async () => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('error-get-preferences', new LoadAppearanceError())
})
const commitMock = jest.fn()
await Appearance.actions.loadAppearance({ commit: commitMock })
.catch((err) => {
expect(err instanceof LoadAppearanceError).toEqual(true)
})
})
it('success', async () => {
const conf = {
appearance: {
theme: Theme.Dark.key
}
}
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('response-get-preferences', conf)
})
const commitMock = jest.fn()
const c = await Appearance.actions.loadAppearance({ commit: commitMock })
expect(c).toEqual(conf)
expect(commitMock).toHaveBeenCalledWith('updateAppearance', conf.appearance)
})
})
describe('loadFonts', () => {
it('error', async () => {
ipcMain.once('list-fonts', (event, _) => {
event.sender.send('error-list-fonts', new ListFontsError())
})
const commitMock = jest.fn()
await Appearance.actions.loadFonts({ commit: commitMock })
.catch((err) => {
expect(err instanceof ListFontsError).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('list-fonts', (event, _) => {
event.sender.send('response-list-fonts', ['fonts'])
})
const commitMock = jest.fn()
const fonts = await Appearance.actions.loadFonts({ commit: commitMock })
expect(fonts).toEqual(['fonts'])
expect(commitMock).toHaveBeenCalledWith('updateFonts', [DefaultFonts[0]].concat(['fonts']))
})
})
})
})
class LoadAppearanceError extends Error {}
class ListFontsError extends Error {}

View File

@ -0,0 +1,29 @@
import General from '@/store/Preferences/General'
describe('Preferences/General', () => {
let state
beforeEach(() => {
state = {
general: {
sound: {
fav_rb: true,
toot: true
}
},
loading: false
}
})
describe('mutations', () => {
it('updateGeneral', () => {
General.mutations.updateGeneral(state, {
sound: {
fav_rb: false,
toot: false
}
})
expect(state.general.sound.fav_rb).toEqual(false)
expect(state.general.sound.toot).toEqual(false)
})
})
})

View File

@ -0,0 +1,29 @@
import Language from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
describe('Preferences/Language', () => {
let state
beforeEach(() => {
state = {
language: {
language: DefaultLanguage.en.key
}
}
})
describe('mutations', () => {
describe('updateLanguage', () => {
it('should be updated', () => {
Language.mutations.updateLanguage(state, {
language: DefaultLanguage.ja.key
})
expect(state.language.language).toEqual(DefaultLanguage.ja.key)
})
})
describe('changeLanguage', () => {
it('should be changed', () => {
Language.mutations.changeLanguage(state, DefaultLanguage.ja.key)
expect(state.language.language).toEqual(DefaultLanguage.ja.key)
})
})
})
})

View File

@ -0,0 +1,35 @@
import Notification from '@/store/Preferences/Notification'
describe('Preferences/Notification', () => {
let state
beforeEach(() => {
state = {
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
}
}
}
})
describe('mutations', () => {
it('updateNotification', () => {
Notification.mutations.updateNotification(state, {
notify: {
reply: false,
reblog: false,
favourite: false,
follow: false
}
})
expect(state.notification.notify).toEqual({
reply: false,
reblog: false,
favourite: false,
follow: false
})
})
})
})

View File

@ -146,8 +146,8 @@ export default {
this.$store.dispatch('Preferences/Appearance/loadFonts')
},
methods: {
updateFontSize (value) {
this.$store.dispatch('Preferences/Appearance/updateFontSize', value)
async updateFontSize (value) {
await this.$store.dispatch('Preferences/Appearance/updateFontSize', value)
}
}
}

View File

@ -62,14 +62,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences', err)
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance)
})
})
},
updateFontSize ({ dispatch, commit, state }, fontSize) {
@ -79,14 +83,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance)
})
})
},
updateDisplayNameStyle ({ dispatch, commit, state }, value) {
@ -96,14 +104,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
dispatch('App/loadPreferences', null, { root: true })
commit('updateAppearance', conf.appearance)
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
dispatch('App/loadPreferences', null, { root: true })
commit('updateAppearance', conf.appearance)
resolve(conf.appearance)
})
})
},
updateTimeFormat ({ dispatch, commit, state }, value) {
@ -113,14 +125,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
dispatch('App/loadPreferences', null, { root: true })
commit('updateAppearance', conf.appearance)
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
dispatch('App/loadPreferences', null, { root: true })
commit('updateAppearance', conf.appearance)
resolve(conf.appearance)
})
})
},
updateCustomThemeColor ({ dispatch, state, commit }, value) {
@ -131,14 +147,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance)
})
})
},
updateFont ({ dispatch, state, commit }, value) {
@ -148,14 +168,18 @@ export default {
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance)
})
})
}
}

View File

@ -46,15 +46,19 @@ const General = {
const config = {
general: newGeneral
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
commit('changeLoading', false)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateGeneral', conf.general)
commit('changeLoading', false)
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
commit('changeLoading', false)
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateGeneral', conf.general)
commit('changeLoading', false)
resolve(conf)
})
})
}
}

View File

@ -32,9 +32,12 @@ export default {
})
},
changeLanguage ({ commit }, key) {
ipcRenderer.send('change-language', key)
ipcRenderer.once('response-change-language', (event, value) => {
commit('changeLanguage', value)
return new Promise((resolve, reject) => {
ipcRenderer.send('change-language', key)
ipcRenderer.once('response-change-language', (event, value) => {
commit('changeLanguage', value)
resolve(value)
})
})
},
relaunch () {

View File

@ -40,10 +40,13 @@ export default {
const config = {
notification: newNotification
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('response-update-preferences', (event, conf) => {
commit('updateNotification', conf.notification)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('response-update-preferences', (event, conf) => {
commit('updateNotification', conf.notification)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.notification)
})
})
}
}