Refactoring

This commit is contained in:
wpetit 2015-09-17 17:29:59 +02:00
parent 6a790cc5bd
commit 383f70f7f3
9 changed files with 49 additions and 37 deletions

View File

@ -120,6 +120,7 @@ html, body {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
padding: 10px; padding: 10px;
flex: 3;
} }
.edit .left-menu { .edit .left-menu {
@ -132,7 +133,7 @@ html, body {
.edit .item-form { .edit .item-form {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex: 1; flex: 2;
} }
.edit .apps-list .icon-theme-selector > select { .edit .apps-list .icon-theme-selector > select {

View File

@ -51,7 +51,7 @@ var TreeNode = React.createClass({
var ProfileTree = React.createClass({ var ProfileTree = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this.props.dispatch(actions.launcher.loadProfile('./default-profile.json')); this.props.dispatch(actions.common.loadProfile('./default-profile.json'));
}, },
render: function() { render: function() {

View File

@ -21,7 +21,7 @@ var LauncherView = React.createClass({
componentDidMount: function() { componentDidMount: function() {
var profilePath = this.props.processOpts.profile || DEFAULT_PROFILE; var profilePath = this.props.processOpts.profile || DEFAULT_PROFILE;
this.props.dispatch(actions.launcher.loadProfile(profilePath)); this.props.dispatch(actions.common.loadProfile(profilePath));
}, },
componentWillReceiveProps: function(nextProps) { componentWillReceiveProps: function(nextProps) {

View File

@ -0,0 +1,26 @@
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';
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;
})
;
};
};

View File

@ -5,6 +5,11 @@ var path = require('path');
var LOAD_DESKTOP_APPS = exports.LOAD_PROFILE = 'LOAD_DESKTOP_APPS'; var LOAD_DESKTOP_APPS = exports.LOAD_PROFILE = 'LOAD_DESKTOP_APPS';
var LOAD_DESKTOP_APPS_SUCCESS = exports.LOAD_DESKTOP_APPS_SUCCESS = 'LOAD_DESKTOP_APPS_SUCCESS'; var LOAD_DESKTOP_APPS_SUCCESS = exports.LOAD_DESKTOP_APPS_SUCCESS = 'LOAD_DESKTOP_APPS_SUCCESS';
var LOAD_DESKTOP_APPS_FAILED = exports.LOAD_DESKTOP_APPS_FAILED = 'LOAD_DESKTOP_APPS_FAILED'; var LOAD_DESKTOP_APPS_FAILED = exports.LOAD_DESKTOP_APPS_FAILED = 'LOAD_DESKTOP_APPS_FAILED';
var SAVE_PROFILE = exports.SAVE_PROFILE = 'SAVE_PROFILE';
var SAVE_PROFILE_SUCCESS = exports.SAVE_PROFILE_SUCCESS = 'SAVE_PROFILE_SUCCESS';
var SAVE_PROFILE_FAILED = exports.SAVE_PROFILE_FAILED = 'SAVE_PROFILE_FAILED';
var MOVE_PROFILE_ITEM = exports.MOVE_PROFILE_ITEM = 'MOVE_PROFILE_ITEM'; var MOVE_PROFILE_ITEM = exports.MOVE_PROFILE_ITEM = 'MOVE_PROFILE_ITEM';
var ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM'; var ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM';
var USE_ICON_THEME = exports.USE_ICON_THEME = 'USE_ICON_THEME'; var USE_ICON_THEME = exports.USE_ICON_THEME = 'USE_ICON_THEME';
@ -34,6 +39,14 @@ exports.loadDesktopApps = function() {
}; };
}; };
exports.saveProfile = function(profile) {
return function(dispatch, getState) {
};
};
exports.useIconTheme = function(theme) { exports.useIconTheme = function(theme) {
return { return {
type: USE_ICON_THEME, type: USE_ICON_THEME,

View File

@ -1,2 +1,3 @@
exports.launcher = require('./launcher'); exports.launcher = require('./launcher');
exports.edit = require('./edit'); exports.edit = require('./edit');
exports.common = require('./common');

View File

@ -1,34 +1,9 @@
var Util = require('../../util'); 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 = exports.RUN_APP = 'RUN_APP';
var RUN_APP_SUCCESS = exports.RUN_APP_SUCCESS = 'RUN_APP_SUCCESS'; var RUN_APP_SUCCESS = exports.RUN_APP_SUCCESS = 'RUN_APP_SUCCESS';
var RUN_APP_FAILED = exports.RUN_APP_FAILED = 'RUN_APP_FAILED'; 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) { exports.runApp = function(execPath) {
return function(dispatch, getState) { return function(dispatch, getState) {

View File

@ -6,7 +6,7 @@ module.exports = function(oldProfile, action) {
switch(action.type) { switch(action.type) {
case actions.launcher.LOAD_PROFILE_SUCCESS: case actions.common.LOAD_PROFILE_SUCCESS:
var newProfile = _.cloneDeep(action.profile); var newProfile = _.cloneDeep(action.profile);
tree.walk(newProfile, ensureItemKey); tree.walk(newProfile, ensureItemKey);
return newProfile; return newProfile;

View File

@ -1,3 +1,4 @@
var crypto = require('crypto');
function Cache() { function Cache() {
this._store = {}; this._store = {};
@ -20,14 +21,9 @@ Cache.prototype._serialize = function(mixedKey) {
}; };
Cache.prototype._hash = function(str) { Cache.prototype._hash = function(str) {
var hash = 0, i, chr, len; var shasum = crypto.createHash('md5');
if (str.length === 0) return hash; shasum.update(str);
for (i = 0, len = str.length; i < len; i++) { return shasum.digest('hex');
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}; };
module.exports = Cache; module.exports = Cache;