Browse Source

Ajout gestion icones pixmap

feature/profil_enr
William Petit 4 years ago
parent
commit
5cd3fafb5e
3 changed files with 46 additions and 15 deletions
  1. 9
    1
      js/components/desktop-app-item.jsx
  2. 35
    12
      js/util/desktop-apps.js
  3. 2
    2
      test/desktop.js

+ 9
- 1
js/components/desktop-app-item.jsx View File

@@ -36,8 +36,16 @@ module.exports = React.createClass({
36 36
   _findIcon: function(iconPath) {
37 37
 
38 38
     var self = this;
39
+    var DEFAULT_ICON = 'application-default-icon';
40
+    var theme = null;
39 41
 
40
-    Util.DesktopApps.findIcon(iconPath || 'application-default-icon')
42
+    Util.DesktopApps.findIcon(iconPath || DEFAULT_ICON, theme)
43
+      .then(function(iconPath) {
44
+        if( !iconPath || /\.xpm$/.test(iconPath) ) {
45
+          return Util.DesktopApps.findIcon(DEFAULT_ICON, theme);
46
+        }
47
+        return iconPath;
48
+      })
41 49
       .then(function(iconPath) {
42 50
         self.setState({ icon: iconPath });
43 51
       })

+ 35
- 12
js/util/desktop-apps.js View File

@@ -5,6 +5,7 @@ var debug = require('debug')('pitaya:desktop-apps');
5 5
 // Constants
6 6
 var ICON_REALPATH_REGEX = /\..+$/;
7 7
 var ICON_THEMES_ROOTDIR = '/usr/share/icons';
8
+var PIXMAPS_ICONS_ROOTDIR = '/usr/share/pixmaps';
8 9
 
9 10
 /**
10 11
  * Find and load all the desktop files in the subdirectories of given dirs
@@ -109,7 +110,15 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
109 110
 
110 111
       debug('No icon found. Search in parents...');
111 112
 
112
-      return exports.findParentsThemeIcon(iconName, themeName, size, themeIgnore);
113
+      return exports.findParentsThemeIcon(iconName, themeName, size, themeIgnore)
114
+        .then(function(iconPath) {
115
+
116
+          if(iconPath) return iconPath;
117
+
118
+          return exports.findPixmapsIcon(iconName);
119
+
120
+        })
121
+      ;
113 122
 
114 123
     })
115 124
   ;
@@ -205,17 +214,18 @@ exports.findClosestSizeIcon = function(iconName, themeName, size) {
205 214
 
206 215
 };
207 216
 
208
-exports._selectBestIcon = function(iconPaths) {
209
-  var iconSelection = iconPaths.reduce(function(iconSelection, iconPath) {
210
-    if(iconPath) {
211
-      var key = iconPath.indexOf('scalable') !== -1 ? 'scalable' : 'bitmap';
212
-      iconSelection[key] = iconPath;
213
-    }
214
-    return iconSelection;
215
-  }, {scalable: null, bitmap: null});
216
-  debug('Icon selection %j', iconSelection);
217
-  return iconSelection.scalable || iconSelection.bitmap;
218
-}
217
+exports.findPixmapsIcon = function(iconName) {
218
+  var filePattern = iconName+'.{svg,png}';
219
+  debug('Looking for pixmap icon %s', filePattern);
220
+  return System.findFiles(filePattern, {cwd: PIXMAPS_ICONS_ROOTDIR})
221
+    .then(function(iconPaths) {
222
+      iconPaths = iconPaths.map(function(iconPath) {
223
+        return path.join(PIXMAPS_ICONS_ROOTDIR, iconPath);
224
+      });
225
+      return exports._selectBestIcon(iconPaths);
226
+    })
227
+  ;
228
+};
219 229
 
220 230
 exports.findIconThemes = function() {
221 231
   return System.findFiles('*/', {cwd: ICON_THEMES_ROOTDIR, realpath: true})
@@ -235,6 +245,19 @@ exports.themeIndexExists = function(themeName) {
235 245
   return System.exists(themeIndexPath);
236 246
 };
237 247
 
248
+exports._selectBestIcon = function(iconPaths) {
249
+  var iconSelection = iconPaths.reduce(function(iconSelection, iconPath) {
250
+    if(iconPath) {
251
+      var key = iconPath.indexOf('scalable') !== -1 ? 'scalable' : 'bitmap';
252
+      iconSelection[key] = iconPath;
253
+    }
254
+    return iconSelection;
255
+  }, {scalable: null, bitmap: null});
256
+  debug('Icon selection %j', iconSelection);
257
+  return iconSelection.scalable || iconSelection.bitmap;
258
+};
259
+
260
+
238 261
 // Array helpers
239 262
 
240 263
 function clean(arr) {

+ 2
- 2
test/desktop.js View File

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

Loading…
Cancel
Save