refs #1348 Save and load auto hide menu bar settings

This commit is contained in:
AkiraFukushima 2020-06-08 22:48:52 +09:00
parent 8c68072686
commit de6e173781
3 changed files with 38 additions and 9 deletions

View File

@ -52,6 +52,7 @@ import { Proxy } from '~/src/types/proxy'
import ProxyConfiguration from './proxy'
import confirm from './timelines'
import { EnabledTimelines } from '~/src/types/enabledTimelines'
import { Menu as MenuPreferences } from '~/src/types/preference'
/**
* Context menu
@ -199,6 +200,12 @@ async function getLanguage() {
}
}
const getMenuPreferences = async (): Promise<MenuPreferences> => {
const preferences = new Preferences(preferencesDBPath)
const conf = await preferences.load()
return conf.menu
}
async function createWindow() {
/**
* List accounts
@ -226,7 +233,13 @@ async function createWindow() {
/**
* Set application menu
*/
ApplicationMenu(accountsChange, i18next)
const menuPreferences = await getMenuPreferences()
const menu = ApplicationMenu(accountsChange, menuPreferences, i18next)
Menu.setApplicationMenu(menu)
let autoHideMenuBar = false
if (menuPreferences.autoHideMenu) {
autoHideMenuBar = true
}
/**
* Set dock menu for mac
@ -262,6 +275,7 @@ async function createWindow() {
height: mainWindowState.height,
useContentSize: true,
icon: path.resolve(__dirname, '../../build/icons/256x256.png'),
autoHideMenuBar: autoHideMenuBar,
webPreferences: {
// It is required to use ipcRenderer in renderer process.
// But it is not secure, so if you want to disable this option, please use preload script.
@ -1192,9 +1206,9 @@ app.on('ready', () => {
class EmptyTokenError {}
/**
* Set application menu
* Genrate application menu
*/
const ApplicationMenu = (accountsChange: Array<MenuItemConstructorOptions>, i18n: I18n) => {
const ApplicationMenu = (accountsChange: Array<MenuItemConstructorOptions>, menu: MenuPreferences, i18n: I18n): Menu => {
/**
* For mac menu
*/
@ -1333,7 +1347,7 @@ const ApplicationMenu = (accountsChange: Array<MenuItemConstructorOptions>, i18n
{
label: i18n.t('main_menu.window.always_show_menu_bar'),
type: 'checkbox',
checked: true,
checked: !menu.autoHideMenu,
click: item => {
changeMenuAutoHide(!item.checked)
}
@ -1375,8 +1389,7 @@ const ApplicationMenu = (accountsChange: Array<MenuItemConstructorOptions>, i18n
}
]
const menu: Menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
return Menu.buildFromTemplate(template)
}
const TrayMenu = (accountsChange: Array<MenuItemConstructorOptions>, i18n: I18n): Menu => {
@ -1403,12 +1416,18 @@ const TrayMenu = (accountsChange: Array<MenuItemConstructorOptions>, i18n: I18n)
return menu
}
async function changeMenuAutoHide(autoHide: boolean) {
const changeMenuAutoHide = async (autoHide: boolean) => {
if (mainWindow === null) {
return null
}
mainWindow.autoHideMenuBar = autoHide
mainWindow.setMenuBarVisibility(!autoHide)
const preferences = new Preferences(preferencesDBPath)
preferences.update({
menu: {
autoHideMenu: autoHide
}
})
return null
}

View File

@ -12,7 +12,7 @@ import { Timeline } from '~/src/types/timeline'
import { Notify } from '~/src/types/notify'
import { Appearance } from '~/src/types/appearance'
import { Language as LanguageSet } from '~/src/types/language'
import { General, State, Notification, BaseConfig, Other } from '~/src/types/preference'
import { General, State, Notification, BaseConfig, Other, Menu } from '~/src/types/preference'
import { Proxy, ProxySource } from '~/src/types/proxy'
const sound: Sound = {
@ -79,13 +79,18 @@ const proxy: Proxy = {
}
}
const menu: Menu = {
autoHideMenu: false
}
const Base: BaseConfig = {
general: general,
state: state,
language: language,
notification: notification,
appearance: appearance,
proxy: proxy
proxy: proxy,
menu: menu
}
export default class Preferences {

View File

@ -24,6 +24,10 @@ export type Notification = {
notify: Notify
}
export type Menu = {
autoHideMenu: boolean
}
export type BaseConfig = {
general: General
state: State
@ -31,4 +35,5 @@ export type BaseConfig = {
notification: Notification
appearance: Appearance
proxy: Proxy
menu: Menu
}