2015-09-03 15:50:23 +02:00
|
|
|
var React = require('react');
|
2015-09-04 12:10:08 +02:00
|
|
|
var Util = require('../../util');
|
|
|
|
var LazyLoad = require('../mixins/lazy-load');
|
|
|
|
var debug = Util.Debug('common:app-icon');
|
2015-09-03 15:50:23 +02:00
|
|
|
|
|
|
|
var LOADING_ICON = 'img/hourglass.svg';
|
|
|
|
var DEFAULT_ICON = 'img/default-icon.svg';
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
|
|
|
|
mixins: [LazyLoad],
|
|
|
|
|
|
|
|
getInitialState: function() {
|
2015-09-11 16:25:45 +02:00
|
|
|
return { icon: DEFAULT_ICON, currentTheme: '' };
|
2015-09-03 15:50:23 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onInViewport: function() {
|
|
|
|
this.updateIconIfInViewport();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateIconIfInViewport: function() {
|
|
|
|
|
|
|
|
var currentTheme = this.state.currentTheme;
|
|
|
|
var newTheme = this.props.theme;
|
|
|
|
|
2015-09-11 16:25:45 +02:00
|
|
|
if( !this.isInViewport() || newTheme === currentTheme ) return;
|
2015-09-03 15:50:23 +02:00
|
|
|
|
|
|
|
this.setState({ icon: LOADING_ICON, currentTheme: newTheme });
|
|
|
|
|
|
|
|
var desktopEntry = this.props.desktopEntry;
|
|
|
|
|
|
|
|
this._findIcon(this.props.icon, newTheme);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function() {
|
|
|
|
this.updateIconIfInViewport();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
|
|
|
|
var icon = this.state.icon;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<img src={icon} className="app-icon" />
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_findIcon: function(iconPath, theme) {
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2015-09-04 12:10:08 +02:00
|
|
|
debug('Search icon %s:%s', iconPath, theme);
|
2015-09-03 15:50:23 +02:00
|
|
|
|
|
|
|
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) {
|
2015-09-04 12:10:08 +02:00
|
|
|
self.setState({ icon: iconPath });
|
2015-09-03 15:50:23 +02:00
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|