Skip to content

Commit

Permalink
Added 'check for updates' button
Browse files Browse the repository at this point in the history
* Added 'check for updates' button

* Added GitHub API integration for update checker

* Removed dummy tag for testing

* Changed update dialog text strings

* Added logo to dialogs
  • Loading branch information
vjanssens authored and gillesdemey committed Apr 16, 2016
1 parent cc50a7f commit d9cab3b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
44 changes: 36 additions & 8 deletions app/js/components/mediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,15 +24,14 @@ function getStateFromStores() {
}
}

var githubUrl = 'http://github.com/gillesdemey/Cumulus';

var MediaPlayer = React.createClass({

menu: function() {
var menu = new Menu();

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' }));
Expand Down Expand Up @@ -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() {
Expand Down
43 changes: 43 additions & 0 deletions app/js/utils/github.js
Original file line number Diff line number Diff line change
@@ -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();
Binary file added cumulus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d9cab3b

Please sign in to comment.