105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
var Util = require('../../util');
|
|
var path = require('path');
|
|
|
|
// 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 });
|
|
|
|
return Util.System.saveJSON(destPath, profile)
|
|
.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
|
|
};
|
|
};
|