Skip to content

Commit

Permalink
Fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tma02 committed Nov 29, 2017
1 parent 41f6817 commit 2bc30d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "Baritone",
"version": "1.0.8",
"version": "1.0.9",
"description": "A Spotify controller that lives in the menubar.",
"main": "index.js",
"dependencies": {
"auto-launch": "^2.0.1",
"font-awesome": "^4.6.1",
"menubar": "latest"
"menubar": "latest",
"request": "^2.83.0"
},
"devDependencies": {
"electron-prebuilt": "^0.37.8"
Expand Down
27 changes: 17 additions & 10 deletions spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ process.on('uncaughtException', function (error) {

const https = require('https');
const exec = require('child_process').exec;
const request = require('request');

const SERVER_PORT = 5000;
const UPDATE_INTERVAL = 1000;
const DEFAULT_RETURN_ON = ['login', 'logout', 'play', 'pause', 'error', 'ap'];
let spotifyPortOffset = 0;
const DEFAULT_HTTPS_CONFIG = {
host: '',
port: 4370,
port: 4380,
path: '',
headers: {
'Origin': 'https://open.spotify.com',
Expand Down Expand Up @@ -52,20 +53,25 @@ module.exports.generateLocalHostname = function() {
return '127.0.0.1';
};

module.exports.generateUrl = function(host, port, path) {
return `http${port == 443 ? 's' : ''}://${host}:${port}${path}`;
}

module.exports.getUrl = function(path) {
mod.generateLocalHostname() + '/' + path;
};

module.exports.getJson = function(config, callback) {
var port = config.port;
https.get(config, function(res) {
var body = '';
res.on('data', function (d) {
body += d;
});
res.on('end', function () {
callback(JSON.parse(body), port);
});
var options = {
url: mod.generateUrl(config.host, config.port, config.path),
rejectUnauthorized: false,
headers: config.headers
}
request(options, function (error, response, body) {
//console.log('error:', error);
//console.log('statusCode:', response && response.statusCode);
//console.log('body:', body);
callback(JSON.parse(body));
});
};

Expand Down Expand Up @@ -161,6 +167,7 @@ module.exports.grabTokens = function() {
if (typeof mainWindow !== 'undefined') {
mainWindow.webContents.send('loadingText', 'Connecting to Spotify...');
}
config = copyConfig();
config.host = mod.generateLocalHostname();
config.path = '/simplecsrf/token.json';
mod.getJson(config, function(data) { csrf = data.token; });
Expand Down

0 comments on commit 2bc30d1

Please sign in to comment.