added Playback preferences; added Play in VLC preference.

This commit is contained in:
Alberto Miranda
2016-06-25 17:36:50 -03:00
parent a9e36472c5
commit 2043dc2161
4 changed files with 63 additions and 40 deletions

View File

@@ -17,32 +17,12 @@ var dialog = require('./dialog')
var shell = require('./shell') var shell = require('./shell')
var windows = require('./windows') var windows = require('./windows')
var thumbnail = require('./thumbnail') var thumbnail = require('./thumbnail')
var State = require('../renderer/lib/state')
var menu, state var menu
function init () { function init () {
menu = electron.Menu.buildFromTemplate(getMenuTemplate()) menu = electron.Menu.buildFromTemplate(getMenuTemplate())
electron.Menu.setApplicationMenu(menu) 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 onError (err) {
console.error(err.stack || err)
state.errors.push({
time: new Date().getTime(),
message: err.message || err
})
} }
function onPlayerClose () { function onPlayerClose () {
@@ -278,13 +258,6 @@ function getMenuTemplate () {
label: 'Add Subtitles File...', label: 'Add Subtitles File...',
click: () => windows.main.dispatch('openSubtitles'), click: () => windows.main.dispatch('openSubtitles'),
enabled: false enabled: false
},
{
label: 'Open in VLC',
type: 'checkbox',
click: () => windows.main.dispatch('toggleOpenInVlc', getMenuItem('Open in VLC')),
enabled: true,
checked: state && state.saved.openInVlc
} }
] ]
}, },

View File

@@ -1078,6 +1078,14 @@ video::-webkit-media-text-track-container {
vertical-align: text-bottom; vertical-align: text-bottom;
} }
.preferences .checkbox {
width: auto;
}
.checkbox-label {
vertical-align: middle;
}
/* /*
* MEDIA OVERLAY / AUDIO DETAILS * MEDIA OVERLAY / AUDIO DETAILS

View File

@@ -151,14 +151,8 @@ function updateElectron () {
} }
} }
function toggleOpenInVlc (menuItem) {
var flag = menuItem.checked
console.log(`toggleOpenInVlc ${flag}`)
state.saved.openInVlc = flag
}
function getOpenInVlc () { function getOpenInVlc () {
return state.saved.openInVlc return state.saved.prefs.playInVlc
} }
// Events from the UI never modify state directly. Instead they call dispatch() // Events from the UI never modify state directly. Instead they call dispatch()
@@ -167,9 +161,6 @@ function dispatch (action, ...args) {
if (!['mediaMouseMoved', 'mediaTimeUpdate'].includes(action)) { if (!['mediaMouseMoved', 'mediaTimeUpdate'].includes(action)) {
console.log('dispatch: %s %o', action, args) console.log('dispatch: %s %o', action, args)
} }
if (action === 'toggleOpenInVlc') {
toggleOpenInVlc(args[0])
}
if (action === 'onOpen') { if (action === 'onOpen') {
onOpen(args[0] /* files */) onOpen(args[0] /* files */)
} }
@@ -1073,9 +1064,8 @@ function openPlayerFromActiveTorrent (torrentSummary, index, timeout, cb) {
return update() return update()
} }
// play in VLC if set as default player (Menu: Playback / Open in VLC) // play in VLC if set as default player (Preferences / Playback / Play in VLC)
if (getOpenInVlc()) { if (getOpenInVlc()) {
console.log('-- OPEN IN VLC', torrentSummary)
dispatch('vlcPlay') dispatch('vlcPlay')
update() update()
cb() cb()

View File

@@ -10,6 +10,7 @@ function Preferences (state) {
return hx` return hx`
<div class='preferences'> <div class='preferences'>
${renderGeneralSection(state)} ${renderGeneralSection(state)}
${renderPlaybackSection(state)}
</div> </div>
` `
} }
@@ -24,6 +25,29 @@ function renderGeneralSection (state) {
]) ])
} }
function renderPlaybackSection (state) {
return renderSection({
title: 'Playback',
description: '',
icon: 'settings'
}, [
renderPlayInVlcSelector(state)
])
}
function renderPlayInVlcSelector (state) {
return renderCheckbox({
label: 'Play in VLC',
description: 'Media will play in VLC',
property: 'playInVlc',
value: state.saved.prefs.playInVlc
},
state.unsaved.prefs.playInVlc,
function (value) {
setStateValue('playInVlc', value)
})
}
function renderDownloadDirSelector (state) { function renderDownloadDirSelector (state) {
return renderFileSelector({ return renderFileSelector({
label: 'Download Path', label: 'Download Path',
@@ -64,6 +88,34 @@ function renderSection (definition, controls) {
` `
} }
function renderCheckbox(definition, value, callback) {
var checked = ''
if (value) checked = 'checked'
return hx`
<div class='control-group'>
<div class='controls'>
<label class='control-label'>
<div class='preference-title'>${definition.label}</div>
</label>
<div class='controls'>
<label>
<input type='checkbox' class='checkbox'
onclick=${handleClick}
id=${definition.property}
${checked} />
<span class="checkbox-label">${definition.description}</span>
</label>
</div>
</div>
</div>
`
function handleClick () {
callback(this.checked)
}
}
// Creates a file chooser // Creates a file chooser
// - defition should be {label, description, options} // - defition should be {label, description, options}
// options are passed to dialog.showOpenDialog // options are passed to dialog.showOpenDialog