Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
movestill committed Jan 5, 2017
1 parent bd882cb commit e37768d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
Pandora-*/
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pandora App

This uses Nativefier (https://github.com/jiahaog/nativefier) to build a native
app for running Pandora on a desktop. It provides support for playing and
pausing using the play/pause button on the keyboard no matter if the app has
the focus or not.

## Building

Install Nativefier according to its instructions.

```shell
npm install nativefier -g
```

Install Google Chrome if you don't already have it (its Flash plugin is
required).

In Chrome, find the path to the Flash plugin by typing `chrome://plugins` in
the location bar.

Edit `build.sh` and update the `FLASH` variable with the location of your Flash
plugin.

```shell
./build.sh
```
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Update Flash path whenever Flash updated.
# Enter chrome://plugins in Chrome to find location.
export FLASH="/Users/tim/Library/Application Support/Google/Chrome/PepperFlash/24.0.0.186/PepperFlashPlayer.plugin"

nativefier --name Pandora --flash --flash-path "$FLASH" --inject pandora.js "http://pandora.com"
33 changes: 33 additions & 0 deletions pandora.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Connect the play/pause button to Pandora.
ipc = require('electron').ipcRenderer;
globalShortcut = require('electron').remote.globalShortcut;
BrowserWindow = require('electron').remote.BrowserWindow;

// Ensure a reload event doesn't leave references to garbage collected
// functions.
globalShortcut.unregisterAll();

// Send the key press to the play-pause channel of the Pandora window.
function sendKey() {
var mainWindow = BrowserWindow.getAllWindows()[0];
mainWindow.webContents.send('play-pause');
}

globalShortcut.register('MediaPlayPause', sendKey);

// Also use Ctrl-Shift-1 as a backup if the keyboard doesn't have a
// play/pause button.
globalShortcut.register('ctrl+shift+1', sendKey);

// Subscribe to the play-pause channel in the renderer process.
ipc.on('play-pause', function () {
var pauseBtn = document.getElementsByClassName('pauseButton')[0];
var child;
if(pauseBtn.style.display === 'block') {
child = pauseBtn.childNodes[0];
} else {
var playBtn = document.getElementsByClassName('playButton')[0];
child = playBtn.childNodes[0];
}
child.click();
});

0 comments on commit e37768d

Please sign in to comment.