Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Client } = require('discord-rpc'),
spotifyWeb = require('./spotify'),
spotify = require('./spotify'),
log = require("fancy-log"),
events = require('events'),
fs = require('fs'),
Expand All @@ -19,7 +19,7 @@ if (process.platform !== "win32" && fs.existsSync("/etc/hosts")) {
}

const rpc = new Client({ transport: keys.rpcTransportType }),
s = new spotifyWeb.SpotifyWebHelper(),
s = new spotify.Spotify(),
appClient = keys.appClientID,
largeImageKey = keys.imageKeys.large,
smallImageKey = keys.imageKeys.small,
Expand Down
34 changes: 17 additions & 17 deletions spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const request = require('request'),
child_process = require('child_process');

// global variables, used when running on windows
var wintools, spotifyWebHelperWinProcRegex;
var wintools, SpotifyWinProcRegex;

const DEFAULT_PORT = 4381,
DEFAULT_RETURN_ON = ['login', 'logout', 'play', 'pause', 'error', 'ap'],
Expand Down Expand Up @@ -79,7 +79,7 @@ async function getOauthToken(cb) {
});
}

async function isSpotifyWebHelperRunning(cb) {
async function isSpotifyRunning(cb) {
cb = cb || function () { };
// not doing anything for non windows, for now
if (process.platform != 'win32') {
Expand All @@ -92,34 +92,34 @@ async function isSpotifyWebHelperRunning(cb) {
return cb(err);
}

spotifyWebHelperWinProcRegex = spotifyWebHelperWinProcRegex || new RegExp('spotifywebhelper.exe', 'i');
SpotifyWinProcRegex = SpotifyWinProcRegex || new RegExp('Spotify.exe', 'i');

for (var k in lst) {
if (spotifyWebHelperWinProcRegex.test(lst[k].desc)) {
if (SpotifyWinProcRegex.test(lst[k].desc)) {
return cb(null, true);
}
spotifyWebHelperWinProcRegex.lastIndex = 0;
SpotifyWinProcRegex.lastIndex = 0;
};
cb(null, false);
});
}

function getWindowsSpotifyWebHelperPath() {
function getWindowsSpotifyPath() {
if (!process.env.USERPROFILE) {
return null;
}

return path.join(process.env.USERPROFILE, 'AppData\\Roaming\\Spotify\\Data\\SpotifyWebHelper.exe');
return path.join(process.env.USERPROFILE, 'AppData\\Roaming\\Spotify\\Spotify.exe');
}

function launchSpotifyWebhelper(cb) {
function launchSpotify(cb) {
cb = cb || function () { };
// not doing anything for non windows, for now
if (process.platform != 'win32') {
return cb(null, true);
}

isSpotifyWebHelperRunning(function (err, res) {
isSpotifyRunning(function (err, res) {
if (err) {
return cb(err);
}
Expand All @@ -128,10 +128,10 @@ function launchSpotifyWebhelper(cb) {
return cb(null, res);
}

var exePath = getWindowsSpotifyWebHelperPath();
var exePath = getWindowsSpotifyPath();

if (!exePath) {
return cb(new Error('Failed to retreive SpotifyWebHelper exe path'));
return cb(new Error('Failed to retreive Spotify exe path'));
}

var child = child_process.spawn(exePath, { detached: true, stdio: 'ignore' });
Expand All @@ -142,9 +142,9 @@ function launchSpotifyWebhelper(cb) {

}

function SpotifyWebHelper(opts) {
if (!(this instanceof SpotifyWebHelper)) {
return new SpotifyWebHelper(opts);
function Spotify(opts) {
if (!(this instanceof Spotify)) {
return new Spotify(opts);
}

opts = opts || {};
Expand Down Expand Up @@ -181,13 +181,13 @@ function SpotifyWebHelper(opts) {
return cb();
}

launchSpotifyWebhelper(function (err, res) {
launchSpotify(function (err, res) {
if (err) {
return cb(err);
}

if (!res) {
return cb(new Error('SpotifyWebHelper not running, failed to start it'));
return cb(new Error('Spotify not running, failed to start it'));
}

getOauthToken(function (err, oauthToken) {
Expand Down Expand Up @@ -300,4 +300,4 @@ function SpotifyWebHelper(opts) {
}
}

module.exports.SpotifyWebHelper = SpotifyWebHelper;
module.exports.Spotify = Spotify;