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

55 lines
1.4 KiB
React
Raw Normal View History

2015-08-28 14:20:07 +02:00
var React = require('react');
var Util = require('../util');
var DesktopAppItem = require('./desktop-app-item.jsx');
2015-08-31 23:08:56 +02:00
var IconThemeSelector = require('./icon-theme-selector.jsx');
var path = require('path');
2015-08-31 23:08:56 +02:00
var debug = require('debug')('pitaya:desktop-app-list');
2015-08-28 14:20:07 +02:00
module.exports = React.createClass({
getInitialState: function() {
return {
2015-08-31 23:08:56 +02:00
desktopFiles: [],
selectedTheme: null
2015-08-28 14:20:07 +02:00
};
},
componentDidMount: function() {
2015-08-31 23:08:56 +02:00
2015-08-28 14:20:07 +02:00
// Load system desktop apps
var baseDirs = global.process.env.XDG_DATA_DIRS.split(':').map(function(baseDir){
return path.join(baseDir, 'applications');
});
2015-08-28 14:20:07 +02:00
Util.DesktopApps.loadAllDesktopFiles('/usr/share/applications')
.then(function(desktopFiles) {
this.setState({ desktopFiles: desktopFiles });
}.bind(this))
;
},
render: function() {
var items = this.state.desktopFiles.map(function(desktopFile, i) {
var desktopEntry = desktopFile.content['Desktop Entry'];
2015-08-31 23:08:56 +02:00
return <DesktopAppItem theme={this.state.selectedTheme} key={desktopFile.path} desktopEntry={desktopEntry} />;
}.bind(this));
2015-08-28 14:20:07 +02:00
return (
2015-08-31 23:08:56 +02:00
<div>
<IconThemeSelector onThemeSelected={this.onThemeSelected} />
<ul className="desktop-apps">
{items}
</ul>
</div>
2015-08-28 14:20:07 +02:00
);
2015-08-31 23:08:56 +02:00
},
onThemeSelected: function(theme) {
console.log('Selected theme %s', theme);
this.setState({ selectedTheme: theme });
2015-08-28 14:20:07 +02:00
}
});