Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Migrate apps from the HTML5 repo into the add-on
Browse files Browse the repository at this point in the history
  • Loading branch information
anantn committed Dec 7, 2011
1 parent 492c4bd commit 28c2ae3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions addons/jetpack/lib/main.js
Expand Up @@ -351,6 +351,53 @@ function setupLogin(service) {
panel.show(button);
}

/**
* migrateApps
*
* We *move* (not copy), apps that were previously installed using the HTML5 shim
* library, hosted at https://myapps.mozillalabs.com/
*/
function migrateApps() {
var pageWorkers = require("page-worker");

try {
console.log("Creating page worker");
var worker = pageWorkers.Page({

This comment has been minimized.

Copy link
@ianb

ianb Dec 7, 2011

Contributor

Does this load this actual page? Maybe we should put up a blank page if that is the case, to give the most minimal overhead.

contentURL: "https://myapps.mozillalabs.com",
contentScript: "var apps = [];" +
"for (var i = 0; i < localStorage.length; i++) {" +
" var key = localStorage.key(i);" +
" if (key.slice(0, 4) == 'app#') {" +
" apps.push(localStorage.getItem(key));" +
" }" +
// Once we have the apps we want, just clean up everything
// This clears dashbaord state too.
"}" +
"localStorage.clear();" +
"self.port.emit('gotApps', JSON.stringify(apps));",
contentScriptWhen: "end"
});

worker.port.on("gotApps", function(apps) {
// Put these apps into extension's storage
var gotApps = JSON.parse(apps);
for (var i = 0; i < gotApps.length; i++) {

This comment has been minimized.

Copy link
@ianb

ianb Dec 7, 2011

Contributor

We should probably run a validator at this point, as this seems like an easy way for corrupt entries to get moved into the browser.

var appRec = JSON.parse(gotApps[i]);
console.log("Migrating app " + appRec.origin);

let repo = require("./api").FFRepoImplService;
repo.addApplication(appRec.origin, appRec, function(done) {
if (!done) {
console.log("Error while migrating app " + appRec.origin);
}
});
}
});
} catch (e) {
console.log("Error in migrateApps " + e);
}
}

/**
* startup
*
Expand Down Expand Up @@ -465,6 +512,9 @@ function startup(getUrlCB) { /* Initialize simple storage */
console.log("Error syncing: " + JSON.stringify(error));
};

// Migrate apps, if neccessary, from HTML5 installs

This comment has been minimized.

Copy link
@ianb

ianb Dec 7, 2011

Contributor

I'm not entirely clear... does this get run every time on startup? Can it just be run at install time?

migrateApps();

// We don't have an assertion from BrowserID, so let's ask the user to login
setupLogin(service);

Expand Down

0 comments on commit 28c2ae3

Please sign in to comment.