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

97 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-09-11 16:25:45 +02:00
var Util = require('../../util');
2015-09-03 15:50:23 +02:00
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';
2015-09-17 17:29:59 +02:00
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';
2015-09-11 16:25:45 +02:00
var MOVE_PROFILE_ITEM = exports.MOVE_PROFILE_ITEM = 'MOVE_PROFILE_ITEM';
var ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM';
2015-09-16 17:26:56 +02:00
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';
2015-09-11 16:25:45 +02:00
// Actions creators
2015-09-03 15:50:23 +02:00
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 });
})
;
};
};
2015-09-11 16:25:45 +02:00
2015-09-18 12:13:24 +02:00
exports.saveProfile = function(destPath, profile) {
2015-09-17 17:29:59 +02:00
return function(dispatch, getState) {
2015-09-18 12:13:24 +02:00
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 });
})
;
2015-09-17 17:29:59 +02:00
};
};
2015-09-16 17:26:56 +02:00
exports.useIconTheme = function(theme) {
return {
type: USE_ICON_THEME,
theme: theme
};
};
2015-09-11 16:25:45 +02:00
exports.moveProfileItem = function(movedItem, targetItem) {
return {
2015-09-16 17:26:56 +02:00
type: MOVE_PROFILE_ITEM,
2015-09-11 16:25:45 +02:00
movedItem: movedItem,
targetItem: targetItem
};
};
exports.addProfileItem = function(newItem, targetItem) {
return {
2015-09-16 17:26:56 +02:00
type: ADD_PROFILE_ITEM,
2015-09-11 16:25:45 +02:00
newItem: newItem,
targetItem: targetItem
};
};
2015-09-16 17:26:56 +02:00
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
};
};