From 8f2ed91f1a19fb9f5ff029d4bae9f1844e2f12b9 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 27 Aug 2015 17:35:00 +0200 Subject: [PATCH 1/4] Base chargement/parsing fichiers Desktop --- js/fs.js | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 js/fs.js diff --git a/js/fs.js b/js/fs.js new file mode 100644 index 0000000..7830b1e --- /dev/null +++ b/js/fs.js @@ -0,0 +1,104 @@ +(function(Pitaya) { + + "use strict"; + + var ini = require('ini'); + var glob = require('glob'); + var path = require('path'); + var fs = require('fs'); + + var FS = Pitaya.FS = {}; + + FS.loadAllDesktopFiles = function(rootDirs) { + + return FS.findAllDesktopFiles(rootDirs) + .then(function(filePaths) { + + var promises = filePaths.map(function(path) { + return FS.loadDesktopFile(path); + }); + + return Promise.all(promises) + .then(function(desktopFiles) { + return desktopFiles.map(function(desktop, i) { + return { + path: filePaths[i], + desktop: desktop + }; + }); + }) + ; + + }) + ; + + }; + + FS.findAllDesktopFiles = function(rootDirs) { + + if(!Array.isArray(rootDirs)) { + rootDirs = [rootDirs]; + } + + var promises = rootDirs.map(function(rootDir) { + + var globPath = path.join(rootDir, '**/*.desktop'); + + return new Promise(function(resolve, reject) { + glob(globPath, function(err, files) { + if(err) return reject(err); + return resolve(files); + }); + }); + + }); + + return Promise.all(promises) + .then(function(apps) { + return uniq(flatten(apps)); + }) + ; + + }; + + FS.loadDesktopFile = function(filePath) { + return new Promise(function(resolve, reject) { + fs.readFile(filePath, 'utf8', function(err, content) { + if(err) return reject(err); + try { + var decoded = ini.decode(content); + return resolve(decoded); + } catch(err) { + return reject(err); + } + }); + }); + }; + + // Array helpers + + function flatten(arr) { + return arr.reduce(function(result, item) { + result = result.concat.apply(result, Array.isArray(item) ? flatten(item) : [item]); + return result; + }, []); + } + + function uniq(arr) { + return arr.reduce(function(result, item) { + if(result.indexOf(item) === -1) { + result.push(item); + } + return result; + }, []); + } + + +}(Pitaya = global.Pitaya || {})); + + +Pitaya.FS.loadAllDesktopFiles(['/usr/share/applications', '/home/william/.local/share/applications']) + .then(function(apps) { + console.log(apps[5]) + }) +; From 1d24cf67798d4a053562e64a2ecfc88996d9eff5 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 27 Aug 2015 18:24:29 +0200 Subject: [PATCH 2/4] Test React --- css/style.css | 5 +++++ index.html | 23 ++++++++++------------- js/app.jsx | 29 +++++++++++++++++++++++++++++ js/components/app-list.jsx | 12 ++++++++++++ js/components/category-header.jsx | 19 +++++++++++++++++++ package.json | 7 ++++++- 6 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 js/app.jsx create mode 100644 js/components/app-list.jsx create mode 100644 js/components/category-header.jsx diff --git a/css/style.css b/css/style.css index 6739667..f9473f9 100644 --- a/css/style.css +++ b/css/style.css @@ -28,6 +28,11 @@ html, body { .launcher .category-header { padding: 40px 50px 0; font-size: 50px; + display: none; +} + +.launcher .category-header.visible { + display: block; } .launcher .category-header a.goback { diff --git a/index.html b/index.html index fc44a91..73e552b 100644 --- a/index.html +++ b/index.html @@ -39,20 +39,17 @@ - - - - - diff --git a/js/app.jsx b/js/app.jsx new file mode 100644 index 0000000..ce24387 --- /dev/null +++ b/js/app.jsx @@ -0,0 +1,29 @@ +var React = require('react'); +var CategoryHeader = require('./components/category-header.jsx'); +var AppList = require('./components/app-list.jsx'); + +var App = React.createClass({ + + getInitialState: function() { + return { + currentItem: null + }; + }, + + componentDidMount: function() { + + }, + + render: function() { + return ( +
+ + +
+ ); + } + +}); + +var rootEl = document.getElementById('pitaya'); +React.render(, rootEl); diff --git a/js/components/app-list.jsx b/js/components/app-list.jsx new file mode 100644 index 0000000..8ddda0f --- /dev/null +++ b/js/components/app-list.jsx @@ -0,0 +1,12 @@ +var React = require('react'); + +module.exports = React.createClass({ + + render: function() { + return ( +
    +
+ ); + } + +}); diff --git a/js/components/category-header.jsx b/js/components/category-header.jsx new file mode 100644 index 0000000..2af7190 --- /dev/null +++ b/js/components/category-header.jsx @@ -0,0 +1,19 @@ +var React = require('react'); + +module.exports = React.createClass({ + + render: function() { + + var classes = 'category-header' + (this.props.currentItem ? 'visible' : ''); + var itemLabel = this.props.currentItem ? this.props.currentItem.label : ''; + + return ( +
+ + {itemLabel} +
+ ); + + } + +}); diff --git a/package.json b/package.json index 4ac1fb5..5f70d4c 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,12 @@ "kiosk": false }, "dependencies": { + "glob": "^5.0.14", "handlebars": "^3.0.3", - "minimist": "^1.1.3" + "ini": "^1.3.4", + "minimist": "^1.1.3", + "node-jsx": "^0.13.3", + "r-dom": "^1.3.0", + "react": "^0.13.3" } } From 7fc7f9d10eacc87d8aa5e0107f529bb177b63ee3 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 27 Aug 2015 22:52:30 +0200 Subject: [PATCH 3/4] Version React iso-fonctionnelle --- css/style.css | 5 - index.html | 32 +--- js/app.js | 242 ------------------------------ js/app.jsx | 116 +++++++++++++- js/components/app-item.jsx | 28 ++++ js/components/app-list.jsx | 23 ++- js/components/category-header.jsx | 23 ++- js/dom.js | 53 ------- js/{anim.js => mixins/animate.js} | 21 ++- js/util/index.js | 1 + js/util/system.js | 31 ++++ package.json | 2 - 12 files changed, 223 insertions(+), 354 deletions(-) delete mode 100644 js/app.js create mode 100644 js/components/app-item.jsx delete mode 100644 js/dom.js rename js/{anim.js => mixins/animate.js} (55%) create mode 100644 js/util/index.js create mode 100644 js/util/system.js diff --git a/css/style.css b/css/style.css index f9473f9..6739667 100644 --- a/css/style.css +++ b/css/style.css @@ -28,11 +28,6 @@ html, body { .launcher .category-header { padding: 40px 50px 0; font-size: 50px; - display: none; -} - -.launcher .category-header.visible { - display: block; } .launcher .category-header a.goback { diff --git a/index.html b/index.html index 73e552b..aad2c75 100644 --- a/index.html +++ b/index.html @@ -7,37 +7,7 @@
- - - - - - - - - +