Skip to content

Commit

Permalink
keyboard shortcuts for forward, back and pause
Browse files Browse the repository at this point in the history
  • Loading branch information
arkokoley committed Dec 19, 2016
1 parent 8d3d6ba commit 23b26f9
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var BrowserWindow = require('browser-window');

var join = require('path').join;
const globalShortcut = require('electron').globalShortcut

global.onlyOSX = function(callback) {
if (process.platform === 'darwin') {
Expand Down Expand Up @@ -153,14 +154,40 @@
"title": "Saavn",
"webPreferences": {
"nodeIntegration": false,
"webSecurity": false,
"sandbox": true,
"preload": join(__dirname, 'js', 'injected.js')
}
});

saavn.window.loadURL('http://www.saavn.com', {
saavn.window.loadURL('https://www.saavn.com', {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36'
});

// Bind Media Shortcuts - This wouldn't have been required if the
// client side code listened to these keys along with KEY_NEXT, KEY_SPACE etc.
// For now trigger functionality by remapping the keys
globalShortcut.register('MediaPlayPause', function () {
saavn.window.webContents.sendInputEvent({
type: 'keyDown',
keyCode: 'Space'
})
})

globalShortcut.register('MediaNextTrack', function () {
saavn.window.webContents.sendInputEvent({
type: 'keyDown',
keyCode: 'Right'
})
})

globalShortcut.register('MediaPreviousTrack', function () {
saavn.window.webContents.sendInputEvent({
type: 'keyDown',
keyCode: 'Left'
})
})

if (config.get("useProxy")) {
var session = saavn.window.webContents.session;
var httpProxy = config.get("httpProxy");
Expand Down Expand Up @@ -201,11 +228,19 @@
saavn.window.setOverlayIcon(null, "no new messages");
}
}));

saavn.window.webContents.on("new-window", (e, url) => {
require('shell').openExternal(url);
e.preventDefault();
});
// Navigation restricted to mainWindow only
var handleUrl = function (e, url) {
e.preventDefault()

// Opening saavn urls
if (url.replace('https://', '').replace('http://', '').indexOf('www.saavn.com') == 0)
saavn.window.loadURL(url)
else
// Open External URLs in the default web browser
require('shell').openExternal(url)
}
saavn.window.webContents.on("will-navigate", handleUrl);
saavn.window.webContents.on("new-window", handleUrl);

saavn.window.on('close', onlyOSX((e) => {
if (saavn.window.forceClose !== true) {
Expand All @@ -230,10 +265,12 @@

app.on('before-quit', onlyOSX(() => {
saavn.window.forceClose = true;
globalShortcut.unregisterAll();
}));

app.on('before-quit', onlyLinux(() => {
saavn.window.forceClose = true;
globalShortcut.unregisterAll();
}));

app.on('activate-with-no-open-windows', onlyOSX(() => {
Expand All @@ -242,6 +279,7 @@

app.on('window-all-closed', onlyWin(() => {
app.quit();
globalShortcut.unregisterAll();
}));
}
};
Expand Down Expand Up @@ -297,6 +335,7 @@
"frame": true,
"webPreferences": {
"nodeIntegration": true,
"sandbox": true,
}
}
);
Expand Down

0 comments on commit 23b26f9

Please sign in to comment.