refactor: Use invoke for ipc to change language

This commit is contained in:
AkiraFukushima 2020-11-29 22:47:23 +09:00
parent 2b84a9402e
commit 5d4428038b
2 changed files with 12 additions and 19 deletions

View File

@ -977,18 +977,15 @@ ipcMain.handle('update-proxy-config', async (_event: IpcMainInvokeEvent, proxy:
}) })
// language // language
ipcMain.on('change-language', (event: IpcMainEvent, value: string) => { ipcMain.handle('change-language', async (_: IpcMainInvokeEvent, value: string) => {
const preferences = new Preferences(preferencesDBPath) const preferences = new Preferences(preferencesDBPath)
preferences const conf = await preferences.update({
.update({
language: { language: {
language: value language: value
} }
}) })
.then(conf => {
i18next.changeLanguage(conf.language.language) i18next.changeLanguage(conf.language.language)
event.sender.send('response-change-language', conf.language.language) return conf.language.language
})
}) })
// hashtag // hashtag

View File

@ -37,14 +37,10 @@ const actions: ActionTree<LanguageState, RootState> = {
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet) commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet)
return conf return conf
}, },
changeLanguage: ({ commit }, key: string) => { changeLanguage: async ({ commit }, key: string) => {
return new Promise(resolve => { const value: string = await win.ipcRenderer.invoke('change-language', key)
win.ipcRenderer.send('change-language', key)
win.ipcRenderer.once('response-change-language', (_, value: string) => {
commit(MUTATION_TYPES.CHANGE_LANGUAGE, value) commit(MUTATION_TYPES.CHANGE_LANGUAGE, value)
resolve(value) return value
})
})
}, },
relaunch: () => { relaunch: () => {
win.ipcRenderer.send('relaunch') win.ipcRenderer.send('relaunch')