From a4fa9ac66642433e9a6c34fe1df1e5c037d91415 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Fri, 24 Jun 2016 00:46:42 -0300 Subject: [PATCH] added open in vlc feature. --- config.js | 3 ++- main/menu.js | 10 ++++++++++ renderer/main.js | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index d01b5390..889b604e 100644 --- a/config.js +++ b/config.js @@ -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 () { diff --git a/main/menu.js b/main/menu.js index 61f17417..0b05e48a 100644 --- a/main/menu.js +++ b/main/menu.js @@ -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 } ] }, diff --git a/renderer/main.js b/renderer/main.js index 0f4ad4eb..64137334 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -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()