From 383f70f7f3096cd1f88ee3825198becfecb8f2f7 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 17 Sep 2015 17:29:59 +0200 Subject: [PATCH] Refactoring --- css/style.css | 3 ++- js/components/edit/profile-tree.jsx | 2 +- js/components/launcher/launcher-view.jsx | 2 +- js/store/actions/common.js | 26 ++++++++++++++++++++++++ js/store/actions/edit.js | 13 ++++++++++++ js/store/actions/index.js | 1 + js/store/actions/launcher.js | 25 ----------------------- js/store/reducers/profile.js | 2 +- js/util/cache.js | 12 ++++------- 9 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 js/store/actions/common.js diff --git a/css/style.css b/css/style.css index 6674f17..50c64db 100644 --- a/css/style.css +++ b/css/style.css @@ -120,6 +120,7 @@ html, body { display: flex; flex-direction: row; padding: 10px; + flex: 3; } .edit .left-menu { @@ -132,7 +133,7 @@ html, body { .edit .item-form { display: flex; flex-direction: row; - flex: 1; + flex: 2; } .edit .apps-list .icon-theme-selector > select { diff --git a/js/components/edit/profile-tree.jsx b/js/components/edit/profile-tree.jsx index 40f2ef1..c4bb491 100644 --- a/js/components/edit/profile-tree.jsx +++ b/js/components/edit/profile-tree.jsx @@ -51,7 +51,7 @@ var TreeNode = React.createClass({ var ProfileTree = React.createClass({ componentDidMount: function() { - this.props.dispatch(actions.launcher.loadProfile('./default-profile.json')); + this.props.dispatch(actions.common.loadProfile('./default-profile.json')); }, render: function() { diff --git a/js/components/launcher/launcher-view.jsx b/js/components/launcher/launcher-view.jsx index c17ba04..cedecc9 100644 --- a/js/components/launcher/launcher-view.jsx +++ b/js/components/launcher/launcher-view.jsx @@ -21,7 +21,7 @@ var LauncherView = React.createClass({ componentDidMount: function() { 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) { diff --git a/js/store/actions/common.js b/js/store/actions/common.js new file mode 100644 index 0000000..edcc659 --- /dev/null +++ b/js/store/actions/common.js @@ -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; + }) + ; + + }; + +}; diff --git a/js/store/actions/edit.js b/js/store/actions/edit.js index 4e97312..1ea1439 100644 --- a/js/store/actions/edit.js +++ b/js/store/actions/edit.js @@ -5,6 +5,11 @@ var path = require('path'); 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_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 ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM'; 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) { return { type: USE_ICON_THEME, diff --git a/js/store/actions/index.js b/js/store/actions/index.js index 4b05d3a..632120a 100644 --- a/js/store/actions/index.js +++ b/js/store/actions/index.js @@ -1,2 +1,3 @@ exports.launcher = require('./launcher'); exports.edit = require('./edit'); +exports.common = require('./common'); diff --git a/js/store/actions/launcher.js b/js/store/actions/launcher.js index 4c6ecbf..4c5e131 100644 --- a/js/store/actions/launcher.js +++ b/js/store/actions/launcher.js @@ -1,34 +1,9 @@ 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) { diff --git a/js/store/reducers/profile.js b/js/store/reducers/profile.js index 4348fc6..54457bb 100644 --- a/js/store/reducers/profile.js +++ b/js/store/reducers/profile.js @@ -6,7 +6,7 @@ module.exports = function(oldProfile, action) { switch(action.type) { - case actions.launcher.LOAD_PROFILE_SUCCESS: + case actions.common.LOAD_PROFILE_SUCCESS: var newProfile = _.cloneDeep(action.profile); tree.walk(newProfile, ensureItemKey); return newProfile; diff --git a/js/util/cache.js b/js/util/cache.js index a8a2bc7..f8fa453 100644 --- a/js/util/cache.js +++ b/js/util/cache.js @@ -1,3 +1,4 @@ +var crypto = require('crypto'); function Cache() { this._store = {}; @@ -20,14 +21,9 @@ Cache.prototype._serialize = function(mixedKey) { }; Cache.prototype._hash = function(str) { - var hash = 0, i, chr, len; - if (str.length === 0) return hash; - for (i = 0, len = str.length; i < len; i++) { - chr = str.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; // Convert to 32bit integer - } - return hash; + var shasum = crypto.createHash('md5'); + shasum.update(str); + return shasum.digest('hex'); }; module.exports = Cache;