Reflect language settings without relaunch
This commit is contained in:
parent
acf7c74ea3
commit
da4a8bc37c
|
@ -217,6 +217,33 @@ const getMenuPreferences = async (): Promise<MenuPreferences> => {
|
|||
return conf.menu
|
||||
}
|
||||
|
||||
/**
|
||||
* Set application menu
|
||||
* @return Whether the menu bar is auto hide.
|
||||
*/
|
||||
const updateApplicationMenu = async (accountsChange: Array<MenuItemConstructorOptions>): Promise<boolean> => {
|
||||
const menuPreferences = await getMenuPreferences()
|
||||
const menu = ApplicationMenu(accountsChange, menuPreferences, i18next)
|
||||
Menu.setApplicationMenu(menu)
|
||||
let autoHideMenuBar = false
|
||||
if (menuPreferences.autoHideMenu) {
|
||||
autoHideMenuBar = true
|
||||
}
|
||||
return autoHideMenuBar
|
||||
}
|
||||
|
||||
/**
|
||||
* Set dock menu for mac
|
||||
*/
|
||||
const updateDockMenu = async (accountsChange: Array<MenuItemConstructorOptions>) => {
|
||||
if (process.platform !== 'darwin') {
|
||||
return
|
||||
}
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate(accountsChange)
|
||||
app.dock.setMenu(dockMenu)
|
||||
}
|
||||
|
||||
async function createWindow() {
|
||||
/**
|
||||
* List accounts
|
||||
|
@ -247,23 +274,14 @@ async function createWindow() {
|
|||
nativeTheme.themeSource = 'system'
|
||||
|
||||
/**
|
||||
* Set application menu
|
||||
* Set Application Menu
|
||||
*/
|
||||
const menuPreferences = await getMenuPreferences()
|
||||
const menu = ApplicationMenu(accountsChange, menuPreferences, i18next)
|
||||
Menu.setApplicationMenu(menu)
|
||||
let autoHideMenuBar = false
|
||||
if (menuPreferences.autoHideMenu) {
|
||||
autoHideMenuBar = true
|
||||
}
|
||||
const autoHideMenuBar = await updateApplicationMenu(accountsChange)
|
||||
|
||||
/**
|
||||
* Set dock menu for mac
|
||||
*/
|
||||
if (process.platform === 'darwin') {
|
||||
const dockMenu = Menu.buildFromTemplate(accountsChange)
|
||||
app.dock.setMenu(dockMenu)
|
||||
}
|
||||
await updateDockMenu(accountsChange)
|
||||
|
||||
/**
|
||||
* Windows10 don't notify, so we have to set appId
|
||||
|
@ -1018,6 +1036,21 @@ ipcMain.handle('change-language', async (_: IpcMainInvokeEvent, value: string) =
|
|||
}
|
||||
})
|
||||
i18next.changeLanguage(conf.language.language)
|
||||
|
||||
const accounts = await listAccounts()
|
||||
const accountsChange: Array<MenuItemConstructorOptions> = accounts.map((a, index) => {
|
||||
return {
|
||||
label: a.domain,
|
||||
accelerator: `CmdOrCtrl+${index + 1}`,
|
||||
click: () => changeAccount(a, index)
|
||||
}
|
||||
})
|
||||
|
||||
await updateApplicationMenu(accountsChange)
|
||||
await updateDockMenu(accountsChange)
|
||||
if (process.platform !== 'darwin' && tray !== null) {
|
||||
tray.setContextMenu(TrayMenu(accountsChange, i18next))
|
||||
}
|
||||
return conf.language.language
|
||||
})
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@ export default {
|
|||
return this.$store.state.Preferences.Language.language.language
|
||||
},
|
||||
set(value) {
|
||||
this.$store.dispatch('Preferences/Language/changeLanguage', value).then(() => {
|
||||
this.confirm()
|
||||
this.$store.dispatch('Preferences/Language/changeLanguage', value).then(key => {
|
||||
this.$i18n.i18next.changeLanguage(key)
|
||||
})
|
||||
}
|
||||
},
|
||||
|
|
|
@ -44,12 +44,12 @@ const mutations: MutationTree<LanguageState> = {
|
|||
}
|
||||
|
||||
const actions: ActionTree<LanguageState, RootState> = {
|
||||
loadLanguage: async ({ commit }) => {
|
||||
loadLanguage: async ({ commit }): Promise<string> => {
|
||||
const conf: BaseConfig = await win.ipcRenderer.invoke('get-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet)
|
||||
return conf
|
||||
return conf.language.language
|
||||
},
|
||||
changeLanguage: async ({ commit }, key: string) => {
|
||||
changeLanguage: async ({ commit }, key: string): Promise<string> => {
|
||||
const value: string = await win.ipcRenderer.invoke('change-language', key)
|
||||
commit(MUTATION_TYPES.CHANGE_LANGUAGE, value)
|
||||
return value
|
||||
|
|
Loading…
Reference in New Issue