Skip to content

Commit

Permalink
Convert to electron app
Browse files Browse the repository at this point in the history
  • Loading branch information
tma02 committed Mar 14, 2016
1 parent 5a6b094 commit 6457e08
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 47 deletions.
8 changes: 8 additions & 0 deletions public/index.css → lib/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ body {
text-align: center;
background: rgb(50, 50, 50);
overflow: hidden;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
color: #ccc;
}

#loading {
margin-top: calc(50vh - 21px);
font-size: 42px;
}

#background {
Expand Down
12 changes: 12 additions & 0 deletions lib/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Spotispy</title>
<link type="text/css" rel="stylesheet" href="index.css">
<script src="index.js"></script>
</head>
<body>
<div id="loading">Retrieving album data...</div>
<img id="background"><img id="cover">
</body>
</html>
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('ipc').on('coverUrl', function(url) {
document.getElementById('background').src = url;
document.getElementById('cover').src = url;
});
88 changes: 65 additions & 23 deletions index.js → lib/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
'use strict';

const electron = require('electron');
// Module to control application life.
const app = electron.app;
const ipc = require('ipc');
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1366, height: 790});

// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.setFullScreen(true);

// Open the DevTools.
//mainWindow.webContents.openDevTools();

// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

const https = require('https');
const randomstring = require('randomstring');
const express = require('express');

const SERVER_PORT = 5000;
const UPDATE_INTERVAL = 1000;
Expand All @@ -14,25 +66,12 @@ const DEFAULT_HTTPS_CONFIG = {
headers: {'Origin': 'https://open.spotify.com'}
};

var app = express();
app.set('views', './views');
app.set('view engine', 'jade');
app.use('/static', express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.render('index');
});
app.get('/coverurl', function(req, res) {
res.end(coverUrl);
});
var server = app.listen(SERVER_PORT, function() {
console.log('spotispy listening on ' + SERVER_PORT);
});

var version;
var csrf;
var oauth;
var albumId;
var coverUrl;
let config;
let version;
let csrf;
let oauth;
let albumId;
let coverUrl;

function copyConfig() {
return JSON.parse(JSON.stringify(DEFAULT_HTTPS_CONFIG));
Expand Down Expand Up @@ -96,6 +135,9 @@ function getAlbumCover(id) {
getJson(config, function(data) {
console.log(data.images[0].url);
coverUrl = data.images[0].url;
if (mainWindow !== null) {
mainWindow.webContents.send('coverUrl', coverUrl);
}
});
}

Expand All @@ -110,8 +152,8 @@ config.host = 'open.spotify.com';
config.path = '/token';
config.port = 443;
getJson(config, function(data) { oauth = data.t; });
var updateTrackCover;
var waitForRequest = setInterval(function() {
let updateTrackCover;
let waitForRequest = setInterval(function() {
if (typeof version !== 'undefined' && typeof csrf !== 'undefined' && typeof oauth !== 'undefined') {
clearInterval(waitForRequest);
console.log('done.');
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "spotispy",
"version": "1.0.0",
"description": "Big album art for Spotify",
"main": "index.js",
"version": "0.0.1",
"description": "Fullscreen Spotify album art",
"main": "lib/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron lib/main.js"
},
"author": "Tianyi Ma <tn.ma@outlook.com>",
"license": "MIT",
"license": "GPL-2.0",
"devDependencies": {
"electron-prebuilt": "^0.36.0"
},
"dependencies": {
"express": "^4.13.4",
"jade": "^1.11.0",
"randomstring": "^1.1.4"
"jquery": "^2.2.1"
}
}
7 changes: 0 additions & 7 deletions public/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions views/index.jade

This file was deleted.

0 comments on commit 6457e08

Please sign in to comment.