pitaya-launcher/js/store/actions/launcher.js

52 lines
1.3 KiB
JavaScript

var Util = require('../../util');
var LOAD_PROFILE = exports.LOAD_PROFILE = 'LOAD_PROFILE';
var LOAD_PROFILE_SUCCESS = exports.LOAD_PROFILE_SUCCESS = 'LOAD_PROFILE_SUCCESS';
var LOAD_PROFILE_FAILED = exports.LOAD_PROFILE_FAILED = 'LOAD_PROFILE_FAILED';
var RUN_APP = exports.RUN_APP = 'RUN_APP';
var RUN_APP_SUCCESS = exports.RUN_APP_SUCCESS = 'RUN_APP_SUCCESS';
var RUN_APP_FAILED = exports.RUN_APP_FAILED = 'RUN_APP_FAILED';
exports.loadProfile = function(profilePath) {
return function(dispatch, getState) {
dispatch({ type: LOAD_PROFILE, profilePath: profilePath });
return Util.System.loadJSONFile(profilePath)
.then(function(profile) {
dispatch({ type: LOAD_PROFILE_SUCCESS, profile: profile });
return profile;
})
.catch(function(err) {
dispatch({ type: LOAD_PROFILE_FAILED, error: err });
return err;
})
;
};
};
exports.runApp = function(execPath) {
return function(dispatch, getState) {
dispatch({ type: RUN_APP, execPath: execPath });
return Util.System.runApp(execPath)
.then(function() {
dispatch({ type: RUN_APP_SUCCESS, execPath: execPath });
return execPath;
})
.catch(function(err) {
dispatch({ type: RUN_APP_FAILED, error: err });
return err;
})
;
};
};