persisting and reloading "Open in VLC" menu item state.

This commit is contained in:
Alberto Miranda
2016-06-24 09:28:28 -03:00
parent 8333f4893f
commit b9c82dd6b2
2 changed files with 17 additions and 4 deletions

View File

@@ -17,12 +17,24 @@ var dialog = require('./dialog')
var shell = require('./shell')
var windows = require('./windows')
var thumbnail = require('./thumbnail')
var State = require('../renderer/lib/state')
var menu
var menu, state
function init () {
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
electron.Menu.setApplicationMenu(menu)
State.load(onState)
}
function onState (err, _state) {
if (err) return onError(err)
state = _state
// Refresh menu
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
electron.Menu.setApplicationMenu(menu)
}
function onPlayerClose () {
@@ -263,7 +275,8 @@ function getMenuTemplate () {
label: 'Open in VLC',
type: 'checkbox',
click: () => windows.main.dispatch('toggleOpenInVlc', getMenuItem('Open in VLC')),
enabled: true
enabled: true,
checked: state && state.saved.openInVlc
}
]
},

View File

@@ -154,11 +154,11 @@ function updateElectron () {
function toggleOpenInVlc (menuItem) {
var flag = menuItem.checked
console.log(`toggleOpenInVlc ${flag}`)
config.OPEN_IN_VLC = flag
state.saved.openInVlc = flag;
}
function getOpenInVlc () {
return config.OPEN_IN_VLC
return state.saved.openInVlc
}
// Events from the UI never modify state directly. Instead they call dispatch()