Ajout gestion icones pixmap
This commit is contained in:
parent
bd5d41aa88
commit
5cd3fafb5e
@ -36,8 +36,16 @@ module.exports = React.createClass({
|
||||
_findIcon: function(iconPath) {
|
||||
|
||||
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) {
|
||||
self.setState({ icon: iconPath });
|
||||
})
|
||||
|
@ -5,6 +5,7 @@ var debug = require('debug')('pitaya:desktop-apps');
|
||||
// Constants
|
||||
var ICON_REALPATH_REGEX = /\..+$/;
|
||||
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
|
||||
@ -109,7 +110,15 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
exports.findPixmapsIcon = function(iconName) {
|
||||
var filePattern = iconName+'.{svg,png}';
|
||||
debug('Looking for pixmap icon %s', filePattern);
|
||||
return System.findFiles(filePattern, {cwd: PIXMAPS_ICONS_ROOTDIR})
|
||||
.then(function(iconPaths) {
|
||||
iconPaths = iconPaths.map(function(iconPath) {
|
||||
return path.join(PIXMAPS_ICONS_ROOTDIR, iconPath);
|
||||
});
|
||||
return exports._selectBestIcon(iconPaths);
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
exports.findIconThemes = function() {
|
||||
return System.findFiles('*/', {cwd: ICON_THEMES_ROOTDIR, realpath: true})
|
||||
@ -235,6 +245,19 @@ exports.themeIndexExists = function(themeName) {
|
||||
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
|
||||
|
||||
function clean(arr) {
|
||||
|
@ -21,9 +21,9 @@ DesktopSuite.findIconThemes = function(test) {
|
||||
|
||||
DesktopSuite.findIcon = function(test) {
|
||||
|
||||
DesktopApps.findIcon('nm-device-wireless')
|
||||
DesktopApps.findIcon('atom')
|
||||
.then(function(iconPath) {
|
||||
//console.log('findIcon', iconPath);
|
||||
console.log('findIcon', iconPath);
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user