Lanceur d’application pour GNU/Linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7KB

  1. var React = require('react');
  2. var Util = require('../util');
  3. var LazyLoad = require('./mixins/lazy-load');
  4. var LOADING_ICON = 'img/hourglass.svg';
  5. module.exports = React.createClass({
  6. mixins: [LazyLoad],
  7. getInitialState: function() {
  8. return { icon: LOADING_ICON, currentTheme: undefined };
  9. },
  10. onInViewport: function() {
  11. this.updateIconIfInViewport();
  12. },
  13. updateIconIfInViewport: function() {
  14. var currentTheme = this.state.currentTheme;
  15. var newTheme = this.props.theme;
  16. if( !this.isInViewport() || newTheme === currentTheme ) return;
  17. this.setState({ icon: LOADING_ICON, currentTheme: newTheme });
  18. var desktopEntry = this.props.desktopEntry;
  19. this._findIcon(desktopEntry.Icon, newTheme);
  20. },
  21. componentDidUpdate: function() {
  22. this.updateIconIfInViewport();
  23. },
  24. render: function() {
  25. var desktopEntry = this.props.desktopEntry;
  26. var label = desktopEntry.Name;
  27. var category = desktopEntry.Categories;
  28. return (
  29. <li className="desktop-app">
  30. <img src={this.state.icon} className="desktop-app-icon" />
  31. <span className="desktop-app-label">{label}</span>
  32. </li>
  33. );
  34. },
  35. _findIcon: function(iconPath, theme) {
  36. var self = this;
  37. var DEFAULT_ICON = 'application-default-icon';
  38. console.log('Search icon %s:%s', iconPath, theme);
  39. Util.DesktopApps.findIcon(iconPath || DEFAULT_ICON, theme)
  40. .then(function(iconPath) {
  41. if( !iconPath || /\.xpm$/.test(iconPath) ) {
  42. return Util.DesktopApps.findIcon(DEFAULT_ICON, theme);
  43. }
  44. return iconPath;
  45. })
  46. .then(function(iconPath) {
  47. global.window.requestAnimationFrame(function() {
  48. self.setState({ icon: iconPath });
  49. });
  50. })
  51. ;
  52. }
  53. });