diff --git a/.circleci/config.yml b/.circleci/config.yml index 55cc62df..30c3029b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,4 +25,4 @@ jobs: - node_modules - run: name: spec - command: npm run spec:unit + command: npm run spec diff --git a/package-lock.json b/package-lock.json index 817683b7..73dc76d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 13d3b4c6..40322aa0 100644 --- a/package.json +++ b/package.json @@ -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 @@ "^@/(.+)": "/src/renderer/$1", "^~/(.+)": "/$1", "electron": "/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", diff --git a/spec/integration/store/Preferences/Appearance.spec.js b/spec/integration/store/Preferences/Appearance.spec.js new file mode 100644 index 00000000..9f7f40f4 --- /dev/null +++ b/spec/integration/store/Preferences/Appearance.spec.js @@ -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() + }) +}) diff --git a/spec/integration/store/Preferences/General.spec.js b/spec/integration/store/Preferences/General.spec.js new file mode 100644 index 00000000..2ed26472 --- /dev/null +++ b/spec/integration/store/Preferences/General.spec.js @@ -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) + }) + }) +}) diff --git a/spec/integration/store/Preferences/Language.spec.js b/spec/integration/store/Preferences/Language.spec.js new file mode 100644 index 00000000..9ad2e1ec --- /dev/null +++ b/spec/integration/store/Preferences/Language.spec.js @@ -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) + }) + }) +}) diff --git a/spec/integration/store/Preferences/Notification.spec.js b/spec/integration/store/Preferences/Notification.spec.js new file mode 100644 index 00000000..860e5efd --- /dev/null +++ b/spec/integration/store/Preferences/Notification.spec.js @@ -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() + }) + }) +}) diff --git a/spec/unit/store/Preferences/Account.spec.js b/spec/unit/store/Preferences/Account.spec.js new file mode 100644 index 00000000..a0367676 --- /dev/null +++ b/spec/unit/store/Preferences/Account.spec.js @@ -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 {} diff --git a/spec/unit/store/Preferences/Appearance.spec.js b/spec/unit/store/Preferences/Appearance.spec.js new file mode 100644 index 00000000..3c6bafe9 --- /dev/null +++ b/spec/unit/store/Preferences/Appearance.spec.js @@ -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 {} diff --git a/spec/unit/store/Preferences/General.spec.js b/spec/unit/store/Preferences/General.spec.js new file mode 100644 index 00000000..cd0bbc24 --- /dev/null +++ b/spec/unit/store/Preferences/General.spec.js @@ -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) + }) + }) +}) diff --git a/spec/unit/store/Preferences/Language.spec.js b/spec/unit/store/Preferences/Language.spec.js new file mode 100644 index 00000000..1527e0e1 --- /dev/null +++ b/spec/unit/store/Preferences/Language.spec.js @@ -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) + }) + }) + }) +}) diff --git a/spec/unit/store/Preferences/Notification.spec.js b/spec/unit/store/Preferences/Notification.spec.js new file mode 100644 index 00000000..49376cd2 --- /dev/null +++ b/spec/unit/store/Preferences/Notification.spec.js @@ -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 + }) + }) + }) +}) diff --git a/src/renderer/components/Preferences/Appearance.vue b/src/renderer/components/Preferences/Appearance.vue index d6304ffe..e78877ef 100644 --- a/src/renderer/components/Preferences/Appearance.vue +++ b/src/renderer/components/Preferences/Appearance.vue @@ -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) } } } diff --git a/src/renderer/store/Preferences/Appearance.js b/src/renderer/store/Preferences/Appearance.js index e19ecfd6..4866d6c1 100644 --- a/src/renderer/store/Preferences/Appearance.js +++ b/src/renderer/store/Preferences/Appearance.js @@ -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) + }) }) } } diff --git a/src/renderer/store/Preferences/General.js b/src/renderer/store/Preferences/General.js index 92e7f423..56cf8ac5 100644 --- a/src/renderer/store/Preferences/General.js +++ b/src/renderer/store/Preferences/General.js @@ -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) + }) }) } } diff --git a/src/renderer/store/Preferences/Language.js b/src/renderer/store/Preferences/Language.js index 1edd74c2..3e4e416a 100644 --- a/src/renderer/store/Preferences/Language.js +++ b/src/renderer/store/Preferences/Language.js @@ -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 () { diff --git a/src/renderer/store/Preferences/Notification.js b/src/renderer/store/Preferences/Notification.js index 836e8e5b..2d90d1a3 100644 --- a/src/renderer/store/Preferences/Notification.js +++ b/src/renderer/store/Preferences/Notification.js @@ -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) + }) }) } }