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
ipcMain.on('change-language', (event: IpcMainEvent, value: string) => {
ipcMain.handle('change-language', async (_: IpcMainInvokeEvent, value: string) => {
const preferences = new Preferences(preferencesDBPath)
preferences
.update({
language: {
language: value
}
})
.then(conf => {
i18next.changeLanguage(conf.language.language)
event.sender.send('response-change-language', conf.language.language)
})
const conf = await preferences.update({
language: {
language: value
}
})
i18next.changeLanguage(conf.language.language)
return conf.language.language
})
// hashtag

View File

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