Ajout police Sawaasdee, rename js to src

This commit is contained in:
2015-10-16 15:12:49 +02:00
parent 39399a5c08
commit 2d8f9bd903
40 changed files with 97 additions and 34 deletions

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.loadJSON(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;
})
;
};
};

112
src/store/actions/edit.js Normal file
View File

@ -0,0 +1,112 @@
var Util = require('../../util');
var path = require('path');
var _ = require('lodash');
// Action types
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 REMOVE_PROFILE_ITEM = exports.REMOVE_PROFILE_ITEM = 'REMOVE_PROFILE_ITEM';
var USE_ICON_THEME = exports.USE_ICON_THEME = 'USE_ICON_THEME';
var SELECT_PROFILE_ITEM = exports.SELECT_PROFILE_ITEM = 'SELECT_PROFILE_ITEM';
var UPDATE_PROFILE_ITEM = exports.UPDATE_PROFILE_ITEM = 'UPDATE_PROFILE_ITEM';
// Actions creators
exports.loadDesktopApps = function() {
return function(dispatch, getState) {
var baseDirs = global.process.env.XDG_DATA_DIRS.split(':').map(function(baseDir){
return path.join(baseDir, 'applications');
});
dispatch({ type: LOAD_DESKTOP_APPS });
return Util.DesktopApps.loadAllDesktopFiles(baseDirs)
.then(function(desktopApps) {
dispatch({ type: LOAD_DESKTOP_APPS_SUCCESS, desktopApps: desktopApps });
})
.catch(function(err) {
dispatch({ type: LOAD_DESKTOP_APPS_FAILED, error: err });
})
;
};
};
exports.saveProfile = function(destPath, profile) {
return function(dispatch, getState) {
dispatch({ type: SAVE_PROFILE, profile: profile, path: destPath });
var cleanedProfile = _.cloneDeep(profile);
Util.Tree.walk(cleanedProfile, function(item) {
delete item.selected;
delete item._key;
});
return Util.System.saveJSON(destPath, cleanedProfile)
.then(function() {
dispatch({ type: SAVE_PROFILE_SUCCESS, profile: profile, path: destPath });
})
.catch(function(err) {
dispatch({ type: SAVE_PROFILE_FAILED, error: err });
})
;
};
};
exports.useIconTheme = function(theme) {
return {
type: USE_ICON_THEME,
theme: theme
};
};
exports.moveProfileItem = function(movedItem, targetItem) {
return {
type: MOVE_PROFILE_ITEM,
movedItem: movedItem,
targetItem: targetItem
};
};
exports.removeProfileItem = function(removedItem) {
return {
type: REMOVE_PROFILE_ITEM,
removedItem: removedItem
};
};
exports.addProfileItem = function(newItem, targetItem) {
return {
type: ADD_PROFILE_ITEM,
newItem: newItem,
targetItem: targetItem
};
};
exports.selectProfileItem = function(item) {
return {
type: SELECT_PROFILE_ITEM,
item: item
};
};
exports.updateProfileItem = function(item, key, value) {
return {
type: UPDATE_PROFILE_ITEM,
item: item,
key: key,
value: value
};
};

View File

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

View File

@ -0,0 +1,26 @@
var Util = require('../../util');
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.runApp = function(execPath) {
return function(dispatch, getState) {
dispatch({ type: RUN_APP, execPath: execPath });
return Util.System.runApp(execPath, { clearFreeDesktopFlags: true })
.then(function() {
dispatch({ type: RUN_APP_SUCCESS, execPath: execPath });
return execPath;
})
.catch(function(err) {
dispatch({ type: RUN_APP_FAILED, error: err });
return err;
})
;
};
};

18
src/store/index.js Normal file
View File

@ -0,0 +1,18 @@
var redux = require('redux');
var thunkMiddleware = require('redux-thunk');
var reducers = require('./reducers');
var loggerMiddleware = require('./middlewares/logger');
var createStore = redux.applyMiddleware(
thunkMiddleware,
loggerMiddleware
)(redux.createStore);
var appReducer = redux.combineReducers({
profile: reducers.profile,
processOpts: reducers.processOpts,
desktopApps: reducers.desktopApps,
theme: reducers.theme
});
module.exports = createStore(appReducer);

View File

@ -0,0 +1,15 @@
var debug = require('../../util/debug')('store:logger');
module.exports = function loggerMiddleware(store) {
return function(next) {
return function(action) {
debug('Action %j', action);
debug('Store current state %j', store.getState());
next(action);
debug('Store new state %j', store.getState());
if(action.error) {
console.error(action.error.stack || action.error);
}
};
};
};

View File

@ -0,0 +1,13 @@
var actions = require('../actions');
module.exports = function(state, action) {
var desktopApps = state || [];
if( action.type === actions.edit.LOAD_DESKTOP_APPS_SUCCESS ) {
desktopApps = action.desktopApps;
}
return desktopApps;
};

View File

@ -0,0 +1,3 @@
exports.desktopApps = require('./desktop-apps');
exports.profile = require('./profile');
exports.theme = require('./theme');

View File

@ -0,0 +1,111 @@
var _ = require('lodash');
var actions = require('../actions');
var tree = require('../../util/tree');
module.exports = function(oldProfile, action) {
var newProfile = oldProfile || { items: [] };
switch(action.type) {
case actions.common.LOAD_PROFILE_SUCCESS:
newProfile = _.cloneDeep(action.profile);
break;
case actions.edit.MOVE_PROFILE_ITEM:
newProfile = moveProfileItem(oldProfile, action.movedItem, action.targetItem);
break;
case actions.edit.REMOVE_PROFILE_ITEM:
newProfile = removeProfileItem(oldProfile, action.removedItem);
break;
case actions.edit.ADD_PROFILE_ITEM:
newProfile = addProfileItem(oldProfile, action.newItem, action.targetItem);
break;
case actions.edit.UPDATE_PROFILE_ITEM:
newProfile = updateProfileItem(oldProfile, action.item, action.key, action.value);
break;
case actions.edit.SELECT_PROFILE_ITEM:
newProfile = selectProfileItem(oldProfile, action.item);
break;
}
if(newProfile) tree.walk(newProfile, ensureItemKey);
return newProfile;
};
function selectProfileItem(oldProfile, item) {
var newProfile = _.cloneDeep(oldProfile);
tree.walk(newProfile, function(currentItem) {
delete currentItem.selected;
if( _.isEqual(currentItem, item) ) {
currentItem.selected = true;
}
});
return newProfile;
}
function updateProfileItem(oldProfile, targetItem, key, value) {
var newProfile = _.cloneDeep(oldProfile);
var item = tree.find(newProfile, targetItem).item;
item[key] = value;
return newProfile;
}
function removeProfileItem(oldProfile, removedItem) {
var newProfile = _.cloneDeep(oldProfile);
var parent = tree.find(newProfile, removedItem).parent;
parent.items = _.reject(parent.items, function(item) {
return _.isEqual(item, removedItem);
});
return newProfile;
}
function moveProfileItem(oldProfile, movedItem, targetItem) {
var newProfile = _.cloneDeep(oldProfile);
var previousParent = tree.find(newProfile, movedItem).parent;
var newParent = tree.find(newProfile, targetItem).item;
previousParent.items = _.reject(previousParent.items, function(item) {
return _.isEqual(item, movedItem);
});
newParent.items = newParent.items || [];
newParent.items.push(_.cloneDeep(movedItem));
return newProfile;
}
function addProfileItem(oldProfile, newItem, targetItem) {
var newProfile = _.cloneDeep(oldProfile);
var newParent = tree.find(newProfile, targetItem).item;
newParent.items = newParent.items || [];
newItem = _.cloneDeep(newItem);
ensureItemKey(newItem);
newParent.items.push(newItem);
return newProfile;
}
var _inc = 0;
function ensureItemKey(item) {
if( item && !('_key' in item) ) {
item._key = 'item_'+Date.now()+'_'+_inc++;
}
}

View File

@ -0,0 +1,14 @@
var actions = require('../actions');
module.exports = function(currentTheme, action) {
switch(action.type) {
case actions.edit.USE_ICON_THEME:
return action.theme;
default:
return currentTheme || null;
}
};