This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate apps from the HTML5 repo into the add-on
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong.
ianb
Contributor
|
||
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 | ||
* | ||
|
@@ -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.
Sorry, something went wrong.
ianb
Contributor
|
||
migrateApps(); | ||
|
||
// We don't have an assertion from BrowserID, so let's ask the user to login | ||
setupLogin(service); | ||
|
||
|
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.