Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playlists feature #871

Merged
merged 7 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function init () {
thumbar.enable()
})

ipc.on('onPlayerUpdate', function (e, ...args) {
menu.onPlayerUpdate(...args)
thumbar.onPlayerUpdate(...args)
})

ipc.on('onPlayerClose', function () {
menu.setPlayerOpen(false)
powerSaveBlocker.disable()
Expand Down
51 changes: 51 additions & 0 deletions src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
setPlayerOpen,
setWindowFocus,
setAllowNav,
onPlayerUpdate,
onToggleAlwaysOnTop,
onToggleFullScreen
}
Expand All @@ -25,13 +26,31 @@ function init () {

function setPlayerOpen (flag) {
getMenuItem('Play/Pause').enabled = flag
getMenuItem('Skip Next').enabled = flag
getMenuItem('Skip Previous').enabled = flag
getMenuItem('Enable Shuffle').enabled = flag
getMenuItem('Enable Repeat').enabled = flag
getMenuItem('Increase Volume').enabled = flag
getMenuItem('Decrease Volume').enabled = flag
getMenuItem('Step Forward').enabled = flag
getMenuItem('Step Backward').enabled = flag
getMenuItem('Increase Speed').enabled = flag
getMenuItem('Decrease Speed').enabled = flag
getMenuItem('Add Subtitles File...').enabled = flag

if (flag === false) {
getMenuItem('Skip Next').enabled = false
getMenuItem('Skip Previous').enabled = false
getMenuItem('Enable Shuffle').checked = false
getMenuItem('Enable Repeat').checked = false
}
}

function onPlayerUpdate (state) {
getMenuItem('Skip Next').enabled = state.hasNext
getMenuItem('Skip Previous').enabled = state.hasPrevious
getMenuItem('Enable Shuffle').checked = state.shuffle
getMenuItem('Enable Repeat').checked = state.repeat
}

function setWindowFocus (flag) {
Expand Down Expand Up @@ -187,6 +206,38 @@ function getMenuTemplate () {
{
type: 'separator'
},
{
label: 'Skip Next',
accelerator: 'N',
click: () => windows.main.dispatch('nextTrack'),
enabled: false
},
{
label: 'Skip Previous',
accelerator: 'P',
click: () => windows.main.dispatch('previousTrack'),
enabled: false
},
{
type: 'separator'
},
{
label: 'Enable Shuffle',
type: 'checkbox',
checked: false,
click: () => windows.main.dispatch('toggleShuffle'),
enabled: false
},
{
label: 'Enable Repeat',
type: 'checkbox',
checked: false,
click: () => windows.main.dispatch('toggleRepeat'),
enabled: false
},
{
type: 'separator'
},
{
label: 'Increase Volume',
accelerator: 'CmdOrCtrl+Up',
Expand Down
10 changes: 10 additions & 0 deletions src/main/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ function enable () {
'MediaPlayPause',
() => windows.main.dispatch('playPause')
)
electron.globalShortcut.register(
'MediaNextTrack',
() => windows.main.dispatch('nextTrack')
)
electron.globalShortcut.register(
'MediaPreviousTrack',
() => windows.main.dispatch('previousTrack')
)
}

function disable () {
// Return the media key to the OS, so other apps can use it.
electron.globalShortcut.unregister('MediaPlayPause')
electron.globalShortcut.unregister('MediaNextTrack')
electron.globalShortcut.unregister('MediaPreviousTrack')
}
69 changes: 53 additions & 16 deletions src/main/thumbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
disable,
enable,
onPlayerPause,
onPlayerPlay
onPlayerPlay,
onPlayerUpdate
}

/**
Expand All @@ -16,39 +17,75 @@ var config = require('../config')

var windows = require('./windows')

const PREV_ICON = path.join(config.STATIC_PATH, 'PreviousTrackThumbnailBarButton.png')
const PLAY_ICON = path.join(config.STATIC_PATH, 'PlayThumbnailBarButton.png')
const PAUSE_ICON = path.join(config.STATIC_PATH, 'PauseThumbnailBarButton.png')
const NEXT_ICON = path.join(config.STATIC_PATH, 'NextTrackThumbnailBarButton.png')

// Array indices for each button
const PREV = 0
const PLAY_PAUSE = 1
const NEXT = 2

var buttons = []

/**
* Show the Windows thumbnail toolbar buttons.
*/
function enable () {
update(false)
buttons = [
{
tooltip: 'Previous Track',
icon: PREV_ICON,
click: () => windows.main.dispatch('previousTrack')
},
{
tooltip: 'Pause',
icon: PAUSE_ICON,
click: () => windows.main.dispatch('playPause')
},
{
tooltip: 'Next Track',
icon: NEXT_ICON,
click: () => windows.main.dispatch('nextTrack')
}
]
update()
}

/**
* Hide the Windows thumbnail toolbar buttons.
*/
function disable () {
windows.main.win.setThumbarButtons([])
buttons = []
update()
}

function onPlayerPause () {
update(true)
if (!isEnabled()) return
buttons[PLAY_PAUSE].tooltip = 'Play'
buttons[PLAY_PAUSE].icon = PLAY_ICON
update()
}

function onPlayerPlay () {
update(false)
if (!isEnabled()) return
buttons[PLAY_PAUSE].tooltip = 'Pause'
buttons[PLAY_PAUSE].icon = PAUSE_ICON
update()
}

function update (isPaused) {
var icon = isPaused
? 'PlayThumbnailBarButton.png'
: 'PauseThumbnailBarButton.png'
function onPlayerUpdate (state) {
if (!isEnabled()) return
buttons[PREV].flags = [ state.hasPrevious ? 'enabled' : 'disabled' ]
buttons[NEXT].flags = [ state.hasNext ? 'enabled' : 'disabled' ]
update()
}

var buttons = [
{
tooltip: isPaused ? 'Play' : 'Pause',
icon: path.join(config.STATIC_PATH, icon),
click: () => windows.main.dispatch('playPause')
}
]
function isEnabled () {
return buttons.length > 0
}

function update () {
windows.main.win.setThumbarButtons(buttons)
}
3 changes: 2 additions & 1 deletion src/renderer/controllers/media-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = class MediaController {

openExternalPlayer () {
var state = this.state
ipcRenderer.send('openExternalPlayer', state.saved.prefs.externalPlayerPath, state.server.localURL, state.window.title)
var mediaURL = state.server.localURL + '/' + state.playlist.getCurrent().fileIndex
ipcRenderer.send('openExternalPlayer', state.saved.prefs.externalPlayerPath, mediaURL, state.window.title)
state.playing.location = 'external'
}

Expand Down
Loading