Ajout gestion icones pixmap

This commit is contained in:
wpetit 2015-08-31 12:24:55 +02:00
parent bd5d41aa88
commit 5cd3fafb5e
3 changed files with 46 additions and 15 deletions

View File

@ -36,8 +36,16 @@ module.exports = React.createClass({
_findIcon: function(iconPath) { _findIcon: function(iconPath) {
var self = this; var self = this;
var DEFAULT_ICON = 'application-default-icon';
var theme = null;
Util.DesktopApps.findIcon(iconPath || 'application-default-icon') Util.DesktopApps.findIcon(iconPath || DEFAULT_ICON, theme)
.then(function(iconPath) {
if( !iconPath || /\.xpm$/.test(iconPath) ) {
return Util.DesktopApps.findIcon(DEFAULT_ICON, theme);
}
return iconPath;
})
.then(function(iconPath) { .then(function(iconPath) {
self.setState({ icon: iconPath }); self.setState({ icon: iconPath });
}) })

View File

@ -5,6 +5,7 @@ var debug = require('debug')('pitaya:desktop-apps');
// Constants // Constants
var ICON_REALPATH_REGEX = /\..+$/; var ICON_REALPATH_REGEX = /\..+$/;
var ICON_THEMES_ROOTDIR = '/usr/share/icons'; var ICON_THEMES_ROOTDIR = '/usr/share/icons';
var PIXMAPS_ICONS_ROOTDIR = '/usr/share/pixmaps';
/** /**
* Find and load all the desktop files in the subdirectories of given dirs * Find and load all the desktop files in the subdirectories of given dirs
@ -109,7 +110,15 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
debug('No icon found. Search in parents...'); debug('No icon found. Search in parents...');
return exports.findParentsThemeIcon(iconName, themeName, size, themeIgnore); return exports.findParentsThemeIcon(iconName, themeName, size, themeIgnore)
.then(function(iconPath) {
if(iconPath) return iconPath;
return exports.findPixmapsIcon(iconName);
})
;
}) })
; ;
@ -205,17 +214,18 @@ exports.findClosestSizeIcon = function(iconName, themeName, size) {
}; };
exports._selectBestIcon = function(iconPaths) { exports.findPixmapsIcon = function(iconName) {
var iconSelection = iconPaths.reduce(function(iconSelection, iconPath) { var filePattern = iconName+'.{svg,png}';
if(iconPath) { debug('Looking for pixmap icon %s', filePattern);
var key = iconPath.indexOf('scalable') !== -1 ? 'scalable' : 'bitmap'; return System.findFiles(filePattern, {cwd: PIXMAPS_ICONS_ROOTDIR})
iconSelection[key] = iconPath; .then(function(iconPaths) {
} iconPaths = iconPaths.map(function(iconPath) {
return iconSelection; return path.join(PIXMAPS_ICONS_ROOTDIR, iconPath);
}, {scalable: null, bitmap: null}); });
debug('Icon selection %j', iconSelection); return exports._selectBestIcon(iconPaths);
return iconSelection.scalable || iconSelection.bitmap; })
} ;
};
exports.findIconThemes = function() { exports.findIconThemes = function() {
return System.findFiles('*/', {cwd: ICON_THEMES_ROOTDIR, realpath: true}) return System.findFiles('*/', {cwd: ICON_THEMES_ROOTDIR, realpath: true})
@ -235,6 +245,19 @@ exports.themeIndexExists = function(themeName) {
return System.exists(themeIndexPath); return System.exists(themeIndexPath);
}; };
exports._selectBestIcon = function(iconPaths) {
var iconSelection = iconPaths.reduce(function(iconSelection, iconPath) {
if(iconPath) {
var key = iconPath.indexOf('scalable') !== -1 ? 'scalable' : 'bitmap';
iconSelection[key] = iconPath;
}
return iconSelection;
}, {scalable: null, bitmap: null});
debug('Icon selection %j', iconSelection);
return iconSelection.scalable || iconSelection.bitmap;
};
// Array helpers // Array helpers
function clean(arr) { function clean(arr) {

View File

@ -21,9 +21,9 @@ DesktopSuite.findIconThemes = function(test) {
DesktopSuite.findIcon = function(test) { DesktopSuite.findIcon = function(test) {
DesktopApps.findIcon('nm-device-wireless') DesktopApps.findIcon('atom')
.then(function(iconPath) { .then(function(iconPath) {
//console.log('findIcon', iconPath); console.log('findIcon', iconPath);
test.done(); test.done();
}) })
.catch(function(err) { .catch(function(err) {