added open in vlc feature.

This commit is contained in:
Alberto Miranda
2016-06-24 00:46:42 -03:00
parent 939ee555b7
commit a4fa9ac666
3 changed files with 36 additions and 1 deletions

View File

@@ -75,7 +75,8 @@ module.exports = {
WINDOW_WEBTORRENT: 'file://' + path.join(__dirname, 'renderer', 'webtorrent.html'),
WINDOW_MIN_HEIGHT: 38 + (120 * 2), // header height + 2 torrents
WINDOW_MIN_WIDTH: 425
WINDOW_MIN_WIDTH: 425,
OPEN_IN_VLC: false
}
function getConfigPath () {

View File

@@ -59,6 +59,10 @@ function onToggleFullScreen (flag) {
getMenuItem('Full Screen').checked = flag
}
function onToggleOpenInVlc (flag) {
getMenuItem('Open in VLC').checked = flag
}
function onWindowBlur () {
getMenuItem('Full Screen').enabled = false
getMenuItem('Float on Top').enabled = false
@@ -258,6 +262,12 @@ function getMenuTemplate () {
label: 'Add Subtitles File...',
click: () => windows.main.dispatch('openSubtitles'),
enabled: false
},
{
label: 'Open in VLC',
type: 'checkbox',
click: () => windows.main.dispatch('toggleOpenInVlc', getMenuItem('Open in VLC')),
enabled: true
}
]
},

View File

@@ -151,6 +151,16 @@ function updateElectron () {
}
}
function toggleOpenInVlc(menuItem) {
var flag = menuItem.checked;
console.log(`toggleOpenInVlc ${flag}`);
config.OPEN_IN_VLC = flag;
}
function getOpenInVlc() {
return config.OPEN_IN_VLC;
}
// Events from the UI never modify state directly. Instead they call dispatch()
function dispatch (action, ...args) {
// Log dispatch calls, for debugging
@@ -158,6 +168,9 @@ function dispatch (action, ...args) {
console.log('dispatch: %s %o', action, args)
}
if (action === 'toggleOpenInVlc') {
toggleOpenInVlc(args[0]);
}
if (action === 'onOpen') {
onOpen(args[0] /* files */)
}
@@ -1061,6 +1074,17 @@ function openPlayerFromActiveTorrent (torrentSummary, index, timeout, cb) {
return update()
}
//------------------------------------------------------
// play in VLC if set as default player (Menu: Playback / Open in VLC)
if (getOpenInVlc()) {
console.log('-- OPEN IN VLC', torrentSummary);
dispatch('vlcPlay');
update()
cb()
return;
}
//------------------------------------------------------
// otherwise, play the video
state.window.title = torrentSummary.files[state.playing.fileIndex].name
update()