Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
+ Port detection
+ Track info display
  • Loading branch information
tma02 committed Aug 11, 2016
1 parent 9ed8b42 commit 544f7ca
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
26 changes: 23 additions & 3 deletions lib/index.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
@font-face {
font-family: 'Montserrat';
font-style: normal;
font-weight: 200;
src: local('Montserrat-Regular'), url(Montserrat.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}

body {
text-align: center;
background: rgb(50, 50, 50);
background: #272727;
overflow: hidden;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-family: 'Montserrat', sans-serif;
font-weight: 300;
color: #ccc;
color: #fff;
}

#loading {
Expand All @@ -31,4 +39,16 @@ body {

* {
cursor: none;
}

#track-info {
position: absolute;
bottom: 7vh;
width: 100vw;
text-align: center;
}

#track-info > #title {
font-size: 20px;
margin-bottom: 6px;
}
4 changes: 4 additions & 0 deletions lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<body>
<div id="loading">Waiting for Spotify...</div>
<img id="background"><img id="cover">
<div id="track-info">
<div id="title"></div>
<span id="artist"></span> - <span id="album"></span>
</div>
</body>
</html>
14 changes: 13 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ ipc.on('coverUrl', function(url) {
document.getElementById('background').src = url;
document.getElementById('cover').src = url;
});
ipc.on('title', function(title) {
document.getElementById('title').innerHTML = title;
});
ipc.on('album', function(album) {
document.getElementById('album').innerHTML = album;
});
ipc.on('artist', function(artist) {
document.getElementById('artist').innerHTML = artist;
});
ipc.on('loadingText', function(text) {
document.getElementById('loading').innerHTML = text;
});
document.onkeydown = function(e) {
e = e || window.event;
if (e.keyCode == 27) {
if (e.keyCode == 27) { //ESC
require('remote').getCurrentWindow().close();
}
/*else if (e.keyCode == 84) { //T
}*/
};
24 changes: 14 additions & 10 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,21 @@ app.on('activate', function () {
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
process.on('uncaughtException', function (error) {
console.log(error);
if (error.code == 'ECONNRESET') {
spotifyPortOffset++;
console.log('connection failed; trying new port...');
}
});

const https = require('https');

const SERVER_PORT = 5000;
const UPDATE_INTERVAL = 1000;
const DEFAULT_RETURN_ON = ['login', 'logout', 'play', 'pause', 'error', 'ap'];
let spotifyPort = 4370;
for (var k in process.argv) {
if (process.argv[k].startsWith('--spotify-port=')) {
spotifyPort = process.argv[k].split('=')[1];
console.log('spotify port set to', spotifyPort);
break;
}
}
let spotifyPortOffset = 0;
const DEFAULT_HTTPS_CONFIG = {
host: '',
port: spotifyPort,
port: 4370,
path: '',
headers: {'Origin': 'https://open.spotify.com'}
};
Expand All @@ -119,7 +116,9 @@ let albumId;
let coverUrl;

function copyConfig() {
return JSON.parse(JSON.stringify(DEFAULT_HTTPS_CONFIG));
let configCopy = JSON.parse(JSON.stringify(DEFAULT_HTTPS_CONFIG));
configCopy.port += (spotifyPortOffset % 10);
return configCopy;
}

function generateLocalHostname() {
Expand Down Expand Up @@ -164,6 +163,11 @@ function getCurrentAlbumId() {
albumId = data.track.album_resource.uri.split(':')[2];
console.log('id:', albumId);
getAlbumCover(albumId);
if (mainWindow !== null) {
mainWindow.webContents.send('title', data.track.track_resource.name);
mainWindow.webContents.send('album', data.track.album_resource.name);
mainWindow.webContents.send('artist', data.track.artist_resource.name);
}
}
}
catch(ex) {
Expand Down

0 comments on commit 544f7ca

Please sign in to comment.