Skip to content

Commit

Permalink
Merge branch 'feature/electron'
Browse files Browse the repository at this point in the history
  • Loading branch information
benkaiser committed Dec 21, 2015
2 parents 16e1b9e + 78f8991 commit f2ba6d7
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 82 deletions.
67 changes: 36 additions & 31 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
bower: {
install: {
options: {
targetDir: 'static/lib/',
},
'bower-install-simple': {
options: {
color: true,
directory: 'bower_components',
},
def: {
production: true,
},
},

Expand All @@ -22,6 +24,10 @@ module.exports = function(grunt) {
dest: 'static/lib/font-awesome-bower/css/',
expand: true, flatten: true, filter: 'isFile',
},
headjs: {
src: 'bower_components/headjs/dist/1.0.0/head.min.js',
dest: 'static/lib/head.min.js',
},
},
uglify: {
options: {
Expand All @@ -30,26 +36,25 @@ module.exports = function(grunt) {
my_target: {
files: {
'static/lib/libs.min.js': [
'static/lib/jquery/jquery.js',
'static/lib/bootstrap/bootstrap.js',
'static/lib/jquery.ui/ui/core.js',
'static/lib/jquery.ui/ui/widget.js',
'static/lib/jquery.ui/ui/position.js',
'static/lib/jquery.ui/ui/menu.js',
'static/lib/jquery.ui/ui/mouse.js',
'static/lib/jquery.ui/ui/sortable.js',
'static/lib/underscore/underscore.js',
'static/lib/backbone/backbone.js',
'static/lib/backbone.babysitter/backbone.babysitter.js',
'static/lib/backbone.wreqr/backbone.wreqr.js',
'static/lib/marionette/backbone.marionette.js',
'static/lib/bootstrap/bootstrap.js',
'static/lib/seiyria-bootstrap-slider/bootstrap-slider.js',
'static/lib/bootbox/bootbox.js',
'static/lib/messenger/messenger.js',
'static/lib/civswig/swig.js',
'static/lib/DateJS/date.min.js',
'static/lib/lastfm-api/lastfm-api.js',
'bower_components/jquery/dist/jquery.min.js',
'bower_components/bootstrap/dist/js/bootstrap.min.js',
'bower_components/jquery.ui/ui/core.js',
'bower_components/jquery.ui/ui/widget.js',
'bower_components/jquery.ui/ui/position.js',
'bower_components/jquery.ui/ui/menu.js',
'bower_components/jquery.ui/ui/mouse.js',
'bower_components/jquery.ui/ui/sortable.js',
'bower_components/underscore/underscore-min.js',
'bower_components/backbone/backbone.js',
'bower_components/backbone.babysitter/lib/backbone.babysitter.min.js',
'bower_components/backbone.wreqr/lib/backbone.wreqr.min.js',
'bower_components/marionette/lib/backbone.marionette.min.js',
'bower_components/seiyria-bootstrap-slider/dist/bootstrap-slider.min.js',
'bower_components/bootbox/bootbox.js',
'bower_components/messenger/build/js/messenger.min.js',
'bower_components/civswig/swig.min.js',
'bower_components/DateJS/build/production/date.min.js',
'bower_components/lastfm-api/lastfm-api.js',
],
},
},
Expand All @@ -62,20 +67,20 @@ module.exports = function(grunt) {
target: {
files: {
'static/lib/libs.min.css': [
'static/lib/bootswatch/cerulean/bootstrap.min.css',
'static/lib/seiyria-bootstrap-slider/bootstrap-slider.css',
'static/lib/messenger/messenger.css',
'static/lib/messenger/messenger-theme-air.css',
'bower_components/bootswatch/cerulean/bootstrap.min.css',
'bower_components/seiyria-bootstrap-slider/dist/css/bootstrap-slider.min.css',
'bower_components/messenger/build/css/messenger.css',
'bower_components/messenger/build/css/messenger-theme-air.css',
],
},
},
},
});

grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-bower-install-simple');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');

grunt.registerTask('default', ['bower', 'copy', 'uglify', 'cssmin']);
grunt.registerTask('default', ['bower-install-simple:def', 'copy', 'uglify', 'cssmin']);
};
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down Expand Up @@ -71,3 +70,5 @@ require(__dirname + '/routes').createRoutes(app);
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});

module.exports = app;
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ function Config(app) {
}

function getUserHome() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
return process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH;
}
37 changes: 37 additions & 0 deletions electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var electronApp = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
var mainWindow = null;
electronApp.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') {
electronApp.quit();
}
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
electronApp.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600, 'node-integration': false});

// disable the menu entirely
mainWindow.setMenu(null);

// init the server
var app = require(__dirname + '/app.js');

// and load the music player page on the server
mainWindow.loadUrl('http://localhost:' + app.get('port') + '/');

// show the dev tool
mainWindow.toggleDevTools();

// 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;
});
});
38 changes: 19 additions & 19 deletions library_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,25 @@ exports.ytDownload = function(data, finalCallback) {
var now = Date.now();
var song;

var saveData = function(song) {
app.db.songs.insert(song, function(err, newDoc) {
addToPlaylist(newDoc._id, 'Youtube');

// update the browser the song has been added
broadcast('yt_update', {
type: 'added',
content: newDoc,
});

// lazy save the id3 tags to the file
saveID3(song);

// call the final callback because we are finished downloading
if (finalCallback)
finalCallback();
});
};

// decide how to build the metadata based on if we have it or not
if (!data.title) {
var dashpos = trackInfo.title.indexOf('-');
Expand Down Expand Up @@ -653,25 +672,6 @@ exports.ytDownload = function(data, finalCallback) {
song.cover_location = cover_location;
saveData(song);
});
}

var saveData = function(song) {
app.db.songs.insert(song, function(err, newDoc) {
addToPlaylist(newDoc._id, 'Youtube');

// update the browser the song has been added
broadcast('yt_update', {
type: 'added',
content: newDoc,
});

// lazy save the id3 tags to the file
saveID3(song);

// call the final callback because we are finished downloading
if (finalCallback)
finalCallback();
});
};
} else {
if (typeof error != Object) {
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "node-music-player",
"version": "0.0.1",
"main": "electron.js",
"private": true,
"scripts": {
"start": "nodemon app.js -e 'html css js'"
Expand All @@ -13,11 +14,6 @@
"errorhandler": "^1.4.2",
"express-http-proxy": "^0.3.0",
"express.oi": "0.0.19",
"grunt": "^0.4.5",
"grunt-bower-task": "^0.4.0",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.12.2",
"grunt-contrib-uglify": "^0.8.0",
"md5": "*",
"mkdirp": "*",
"mobile-detect": "^0.4.3",
Expand All @@ -35,5 +31,12 @@
"optionalDependencies": {
"ffmetadata": "^1.3.0",
"fluent-ffmpeg": "~2.0.0-rc1"
},
"devDependencies": {
"grunt-bower-install-simple": "^1.2.0",
"grunt": "^0.4.5",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.12.2",
"grunt-contrib-uglify": "^0.8.0"
}
}
49 changes: 26 additions & 23 deletions static/js/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,36 +314,39 @@ function PlayState() {
this.current_song = this.queue_pool[this.current_index];
}

// skip resetting the song if it's the same song playing and we don't need to force restart
if (id == this.playing_id && !force_restart) {
return;
} else {
this.playing_id = id;
}
// only continue if the song was defined
if (this.current_song) {
// skip resetting the song if it's the same song playing and we don't need to force restart
if (id == this.playing_id && !force_restart) {
return;
} else {
this.playing_id = id;
}

// update the audio element
this.PlayMethodAbstracter.playTrack(this.current_song);
// update the audio element
this.PlayMethodAbstracter.playTrack(this.current_song);

// set the state to playing
this.setIsPlaying(true);
// set the state to playing
this.setIsPlaying(true);

// show the songs info
info = new InfoView();
MusicApp.infoRegion.show(info);
// show the songs info
info = new InfoView();
MusicApp.infoRegion.show(info);

// update the selected item
$('tr').removeClass('light-blue');
$('#' + id).addClass('light-blue');
// update the selected item
$('tr').removeClass('light-blue');
$('#' + id).addClass('light-blue');

// update the window title
window.document.title = this.current_song.attributes.title + ' - ' + this.current_song.attributes.display_artist;
// update the window title
window.document.title = this.current_song.attributes.title + ' - ' + this.current_song.attributes.display_artist;

// update the cover photo if it's showing fullscreen and the new song has cover art
if (cover_is_visible && cover_is_current && this.current_song.attributes.cover_location) {
showCover('/cover/' + this.current_song.attributes.cover_location);
}
// update the cover photo if it's showing fullscreen and the new song has cover art
if (cover_is_visible && cover_is_current && this.current_song.attributes.cover_location) {
showCover('/cover/' + this.current_song.attributes.cover_location);
}

this.displayNotification();
this.displayNotification();
}
};

this.setIsPlaying = function(isPlaying) {
Expand Down
4 changes: 2 additions & 2 deletions views/base/main_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<title>{% block title %}Desktop Command Remote{% endblock %}</title>

<script type="text/javascript" src="/static/lib/headjs/head.min.js"></script>
<script type="text/javascript" src="/static/lib/head.min.js"></script>

<script type="text/javascript">
head.load(
"/static/lib/font-awesome-bower/css/font-awesome.css",
"/static/lib/libs.min.css",
"/static/css/main.css"
);
var music_dir = "{{music_dir}}";
var music_dir = "{{music_dir|addslashes}}";
var music_dir_set = "{{music_dir_set}}" === "true";
</script>
{% block head %}
Expand Down

0 comments on commit f2ba6d7

Please sign in to comment.