Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
autonome committed Apr 13, 2012
0 parents commit 076db37
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
@@ -0,0 +1,5 @@
This is the quickfire2 add-on. It contains:

* A program (lib/main.js).
* A few tests.
* Some meager documentation.
2 changes: 2 additions & 0 deletions doc/main.md
@@ -0,0 +1,2 @@
The main module is a program that creates a widget. When a user clicks on
the widget, the program loads the mozilla.org website in a new tab.
61 changes: 61 additions & 0 deletions lib/apps.js
@@ -0,0 +1,61 @@
const { Cc, Ci, Cm, Cu, Cr, components } = require("chrome");

let apps = [];

function getAppsFromDirectory(aDir) {
var dirs = [aDir];
while (dirs.length) {
var dir = dirs.shift();
var entries = dir.directoryEntries;
while (entries.hasMoreElements()) {
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
if (/\.app$/.test(entry.path))
yield entry;
else if (entry.isDirectory())
dirs.push(entry)
}
}
}

function getAppList(callback) {
let apps = [];
["LocApp", "UsrApp"].forEach(function(aDir) {
var dirFile = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).get(aDir, Ci.nsIFile);

var appGetter = getAppsFromDirectory(dirFile);

for (var app in appGetter) {
if (/\.app$/.test(app.path))
apps.push(app);
}
});
callback(apps);
}


getAppList(function(theApps) {
apps = theApps;
});

exports.search = function(searchString, callback) {
apps.forEach(function(app) {
if (app.path.toLowerCase().indexOf(searchString.toLowerCase()) != -1)
callback({
leafName: app.leafName,
path: app.path
});
});
};


function launchApp(aPath) {
if (!apps.some(function(app) app.path == aPath))
return;
var binFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
binFile.initWithPath(aPath);
binFile.launch();
}

exports.launch = launchApp;

0 comments on commit 076db37

Please sign in to comment.