pitaya-launcher/js/components/desktop-app-item.jsx

77 lines
1.7 KiB
React
Raw Normal View History

2015-08-28 14:20:07 +02:00
var React = require('react');
var Util = require('../util');
var LazyLoad = require('./mixins/lazy-load');
2015-08-28 14:20:07 +02:00
2015-08-31 23:08:56 +02:00
var LOADING_ICON = 'img/hourglass.svg';
2015-08-28 14:20:07 +02:00
module.exports = React.createClass({
mixins: [LazyLoad],
2015-08-28 14:20:07 +02:00
getInitialState: function() {
2015-08-31 23:08:56 +02:00
return { icon: LOADING_ICON, currentTheme: undefined };
},
onInViewport: function() {
2015-08-31 23:08:56 +02:00
this.updateIconIfInViewport();
},
updateIconIfInViewport: function() {
var currentTheme = this.state.currentTheme;
var newTheme = this.props.theme;
if( !this.isInViewport() || newTheme === currentTheme ) return;
this.setState({ icon: LOADING_ICON, currentTheme: newTheme });
var desktopEntry = this.props.desktopEntry;
this._findIcon(desktopEntry.Icon, newTheme);
},
componentDidUpdate: function() {
this.updateIconIfInViewport();
2015-08-28 14:20:07 +02:00
},
render: function() {
var desktopEntry = this.props.desktopEntry;
var label = desktopEntry.Name;
var category = desktopEntry.Categories;
return (
<li className="desktop-app">
<img src={this.state.icon} className="desktop-app-icon" />
2015-08-28 14:20:07 +02:00
<span className="desktop-app-label">{label}</span>
</li>
);
},
2015-08-31 23:08:56 +02:00
_findIcon: function(iconPath, theme) {
2015-08-28 14:20:07 +02:00
var self = this;
2015-08-31 12:24:55 +02:00
var DEFAULT_ICON = 'application-default-icon';
2015-08-31 23:08:56 +02:00
console.log('Search icon %s:%s', iconPath, theme);
2015-08-28 14:20:07 +02:00
2015-08-31 12:24:55 +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;
})
2015-08-28 14:20:07 +02:00
.then(function(iconPath) {
2015-08-31 23:08:56 +02:00
global.window.requestAnimationFrame(function() {
self.setState({ icon: iconPath });
});
})
2015-08-28 14:20:07 +02:00
;
}
});