Chargement séquentiel des applications/icones

This commit is contained in:
wpetit 2015-10-13 14:32:22 +02:00
parent 7db3d9eb69
commit 747f3519e0
5 changed files with 43 additions and 26 deletions

View File

@ -21,11 +21,9 @@ var EditView = React.createClass({
return ( return (
<div className="edit"> <div className="edit">
<div className="menu-bar">
<ProfileMenu />
</div>
<div className="workspace"> <div className="workspace">
<div className="left-menu"> <div className="left-menu">
<ProfileMenu />
<IconThemeSelector onThemeSelected={this.handleThemeSelect} /> <IconThemeSelector onThemeSelected={this.handleThemeSelect} />
<DesktopAppList <DesktopAppList
theme={this.props.theme} theme={this.props.theme}

View File

@ -10,8 +10,8 @@ var ProfileMenu = React.createClass({
return ( return (
<div className="profile-menu"> <div className="profile-menu">
<button className="btn btn-default" onClick={this.handleOpenClick}>Ouvrir</button> <button className="btn btn-default btn-sm" onClick={this.handleOpenClick}>Ouvrir</button>
<button className="btn btn-primary" onClick={this.handleSaveClick}>Enregistrer</button> <button className="btn btn-primary btn-sm" onClick={this.handleSaveClick}>Enregistrer</button>
</div> </div>
); );

View File

@ -55,6 +55,7 @@ var ProfileTree = React.createClass({
return ( return (
<div className="profile-tree"> <div className="profile-tree">
<button className="btn btn-primary pull-right btn-sm" onClick={this.handleAddNewNode}>Ajouter un noeud</button>
{this.renderTreeNode(this.props.profile)} {this.renderTreeNode(this.props.profile)}
</div> </div>
); );

View File

@ -2,6 +2,7 @@ var path = require('path');
var System = require('./system'); var System = require('./system');
var debug = require('./debug')('desktop-apps'); var debug = require('./debug')('desktop-apps');
var Cache = require('./cache'); var Cache = require('./cache');
var promises = require('./promises');
// Constants // Constants
var ICON_REALPATH_REGEX = /\..+$/; var ICON_REALPATH_REGEX = /\..+$/;
@ -19,11 +20,9 @@ exports.loadAllDesktopFiles = function(rootDirs) {
return exports.findAllDesktopFiles(rootDirs) return exports.findAllDesktopFiles(rootDirs)
.then(function(filePaths) { .then(function(filePaths) {
var promises = filePaths.map(function(path) { return promises.seq(filePaths, function(path) {
return exports.loadDesktopFile(path); return exports.loadDesktopFile(path);
}); })
return Promise.all(promises)
.then(function(contents) { .then(function(contents) {
return contents.map(function(content, i) { return contents.map(function(content, i) {
return { content: content, path: filePaths[i] }; return { content: content, path: filePaths[i] };
@ -48,11 +47,9 @@ exports.findAllDesktopFiles = function(baseDirs) {
baseDirs = [baseDirs]; baseDirs = [baseDirs];
} }
var promises = baseDirs.map(function(baseDir) { return promises.seq(baseDirs, function(baseDir) {
return System.findFiles('**/*.desktop', {cwd: baseDir, realpath: true}); return System.findFiles('**/*.desktop', {cwd: baseDir, realpath: true});
}); })
return Promise.all(promises)
.then(function(apps) { .then(function(apps) {
return uniq(flatten(apps)); return uniq(flatten(apps));
}) })
@ -104,10 +101,9 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
return exports.findIconThemes() return exports.findIconThemes()
.then(function(themes) { .then(function(themes) {
themeIgnore = themeIgnore || []; themeIgnore = themeIgnore || [];
var promises = themes.map(function(theme) { return promises.seq(themes, function(theme) {
return exports.findIcon(iconName, theme, size, themeIgnore); return exports.findIcon(iconName, theme, size, themeIgnore);
}); })
return Promise.all(promises)
.then(exports._selectBestIcon) .then(exports._selectBestIcon)
; ;
}) })
@ -160,11 +156,9 @@ exports.findParentsThemeIcon = function(iconName, themeName, size, themeIgnore)
debug('Found parents %j', parents); debug('Found parents %j', parents);
var promises = parents.map(function(themeName) { return promises.seq(parents, function(themeName) {
return exports.findIcon(iconName, themeName, size, themeIgnore); return exports.findIcon(iconName, themeName, size, themeIgnore);
}); })
return Promise.all(promises)
.then(exports._selectBestIcon) .then(exports._selectBestIcon)
; ;
@ -278,7 +272,6 @@ exports._selectBestIcon = function(iconPaths) {
return iconSelection.scalable || iconSelection.bitmap; return iconSelection.scalable || iconSelection.bitmap;
}; };
// Array helpers // Array helpers
function clean(arr) { function clean(arr) {

25
js/util/promises.js Normal file
View File

@ -0,0 +1,25 @@
exports.seq = function(items, generator) {
var results = [];
var p = Promise.resolve();
for(var i = 0, len = items.length; i < len; ++i) {
p = p.then(generateNextHandler(items[i], i === 0));
}
return p.then(function(lastResult) {
results.push(lastResult);
return results;
});
// Internal helper
function generateNextHandler(item, ignoreResult) {
return function(prevResult) {
if(!ignoreResult) results.push(prevResult);
return generator(item, prevResult);
};
}
};