Chargement des profils distant via HTTP

This commit is contained in:
2015-11-05 16:40:42 +01:00
parent 996ccd90f1
commit 736d7600c0
7 changed files with 113 additions and 20 deletions

View File

@ -88,9 +88,19 @@ var LauncherView = React.createClass({
onItemClick: function(evt, itemPath, item) {
if(item.exec) {
console.log(item);
if(item.items) {
this.play(this.refs.appList, 'slide-out-left 250ms ease-in-out')
.then(function() {
this.setState({ currentItemPath: itemPath, currentItem: item });
return this.play(this.refs.appList, 'slide-in-right 250ms ease-in-out');
}.bind(this))
;
} else if(item.exec) {
logger.debug('Launching application "'+item.exec+'"...');
var el = evt.currentTarget;
el.classList.add('pulse');
@ -104,12 +114,7 @@ var LauncherView = React.createClass({
;
} else {
this.play(this.refs.appList, 'slide-out-left 250ms ease-in-out')
.then(function() {
this.setState({ currentItemPath: itemPath, currentItem: item });
return this.play(this.refs.appList, 'slide-in-right 250ms ease-in-out');
}.bind(this))
;
logger.info('No action associated with item "'+item.label+'".');
}
},

View File

@ -3,14 +3,47 @@ var cp = require('child_process');
var glob = require('glob');
var ini = require('ini');
var Cache = require('./cache');
var request = require('request');
var HTTP_REGEX = /^https?:\/\//i;
/**
* Load a JSON file
* Load a JSON file (http or local)
*
* @param filePath The path of the json file
* @return Promise
*/
exports.loadJSON = function(filePath) {
exports.loadJSON = function(jsonUrl) {
if( HTTP_REGEX.test(jsonUrl) ) {
return exports.fetchRemoteJSON(jsonUrl);
} else {
return exports.loadLocalJSON(jsonUrl);
}
};
/**
* Load a remote JSON file via http
*
* @param filePath The path of the json file
* @return Promise
*/
exports.fetchRemoteJSON = function(fileUrl) {
return new Promise(function(resolve, reject) {
request(fileUrl, { followRedirect: true, json: true }, function (err, res, body) {
if(err) return reject(err);
console.log(body);
return resolve(body);
});
});
};
/**
* Load a local JSON file
*
* @param filePath The path of the json file
* @return Promise
*/
exports.loadLocalJSON = function(filePath) {
return new Promise(function(resolve, reject) {
fs.readFile(filePath, 'utf8', function(err, fileContent) {
if(err) return reject(err);