diff --git a/app/js/components/mediaPlayer.js b/app/js/components/mediaPlayer.js index a41e5b2..2f8f4f5 100644 --- a/app/js/components/mediaPlayer.js +++ b/app/js/components/mediaPlayer.js @@ -5,13 +5,17 @@ var Actions = require('../actions/actionCreators') var CurrentTrackStore = require('../stores/currentTrackStore') var time = require('../utils/time') +var github = require('../utils/github') var classNames = require('classnames') var _ = require('lodash') -var remote = window.require('remote'); -var Menu = remote.require('menu'); -var MenuItem = remote.require('menu-item'); -var pjson = remote.require('./package.json'); +var remote = window.require('remote') +var Menu = remote.require('menu') +var MenuItem = remote.require('menu-item') +var pjson = remote.require('./package.json') +var app = remote.require('app') +var dialog = remote.require('dialog'); +var icon = remote.nativeImage.createFromPath(app.getAppPath() + '/cumulus.png'); function getStateFromStores() { return { @@ -20,8 +24,6 @@ function getStateFromStores() { } } -var githubUrl = 'http://github.com/gillesdemey/Cumulus'; - var MediaPlayer = React.createClass({ menu: function() { @@ -29,6 +31,7 @@ var MediaPlayer = React.createClass({ menu.append(new MenuItem({ label : 'Cumulus v' + pjson.version, enabled : false })); menu.append(new MenuItem({ label : 'Report a bug...', click : this.report })); + menu.append(new MenuItem({ label : 'Check for updates...', click : this.update })); menu.append(new MenuItem({ type : 'separator' })); menu.append(new MenuItem({ label : 'About', click : this.about })); menu.append(new MenuItem({ type : 'separator' })); @@ -122,11 +125,36 @@ var MediaPlayer = React.createClass({ }, about: function() { - this.openExternal(githubUrl); + this.openExternal(github.getRepoUrl()); }, report: function() { - this.openExternal(githubUrl + '/issues'); + this.openExternal(github.getRepoUrl() + '/issues'); + }, + + update: function() { + github.checkForUpdates().then(function(upToDateMessage) { + // cumulus is up-to-date + var options = { + icon: icon, + message: upToDateMessage, + buttons: ["OK"] + } + + dialog.showMessageBox(options); + }, function(outdatedMessage) { + var options = { + icon: icon, + message: outdatedMessage, + buttons: ["Download latest version", "Cancel"] + } + + dialog.showMessageBox(options, function(buttonId) { + if(buttonId === 0) { + remote.require('shell').openExternal(github.getRepoUrl() + '/releases/latest') + } + }) + }) }, openPermalink: function() { diff --git a/app/js/utils/github.js b/app/js/utils/github.js new file mode 100644 index 0000000..27a5d46 --- /dev/null +++ b/app/js/utils/github.js @@ -0,0 +1,43 @@ +'use strict'; + +var remote = window.require('remote'); +var pjson = remote.require('./package.json'); +var rp = window.require('request-promise') +var _ = require('lodash') + +var GitHub = function(options) { + this._repo = 'http://github.com/gillesdemey/Cumulus' + this._endpoint = 'https://api.github.com/repos/gillesdemey/cumulus' +} + +GitHub.prototype.getRepoUrl = function() { + return this._repo; +} + +GitHub.prototype.checkForUpdates = function() { + return this.getLatestRelease().then(function(response) { + var tag = response.tag_name.replace(/v/g, '') + + if(pjson.version == tag) { + return Promise.resolve('Cumulus is currently up-to-date.') + } else { + return Promise.reject('A new version of Cumulus is available.') + } + }, function(error) { + return Promise.reject('Cumulus was not able to check version information.'); + }) +} + +GitHub.prototype.getLatestRelease = function() { + var options = { + uri: this._endpoint + '/releases/latest', + json: true, + headers: { + 'User-Agent': 'gillesdemey/Cumulus' + }, + } + + return rp(options); +} + +module.exports = new GitHub(); diff --git a/cumulus.png b/cumulus.png new file mode 100644 index 0000000..35c0eec Binary files /dev/null and b/cumulus.png differ