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

Commit

Permalink
Merge pull request #2 from punamdahiya/Bug1167377
Browse files Browse the repository at this point in the history
Bug 1167377 - [Customizer Launcher] Auto-enable the Customizer add-on
  • Loading branch information
punamdahiya committed May 29, 2015
2 parents 8ff817c + 5e03b0c commit f659dcd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
24 changes: 19 additions & 5 deletions app/js/controller/list_controller.js
Expand Up @@ -11,16 +11,30 @@ export default class ListController extends Controller {
this.webServer = new WebServer();
}

main() {
this.createList();
main() {
this.model.getAllApps().then((allApps) => {
this.enableCustomizerAddOn(allApps).then(() =>
this.createList(allApps));
});
}

enableCustomizerAddOn(allApps) {
return new Promise((resolve, reject) => {
this.model.getCustomizerAddOn(allApps).then((addon) => {
if (addon && !addon.enabled) {
navigator.mozApps.mgmt.setEnabled(addon, true);
}
resolve();
});
});
}

createList() {
createList(allApps) {
this.listView.render();
document.body.appendChild(this.listView.el);

this.model.getAppList().then(allApps => {
this.listView.update(allApps);
this.model.getAppList(allApps).then((appsList) => {
this.listView.update(appsList);
this.listView.setOpenHandler(this.handleOpen.bind(this));
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/js/lib/web_server.js
Expand Up @@ -26,6 +26,8 @@ export default class WebServer {
return;
}
}
// Default response for all other requests
response.send(null, 404);
});
}

Expand Down
52 changes: 32 additions & 20 deletions app/js/model/list_model.js
Expand Up @@ -2,14 +2,39 @@ import { Model } from 'components/fxos-mvc/dist/mvc';
import { AppsHelper, IconHelper } from 'js/lib/helpers';

export default class ListModel extends Model {
getAllApps() {
return new Promise((resolve, reject) => {
AppsHelper.getAllApps().then(allApps => {
resolve(allApps);
});
});
}

filterCustomizerAddon(apps) {
return apps.filter(app =>
app.manifestURL == 'app://customizer.gaiamobile.org/manifest.webapp');
}

getCustomizerAddOn(allApps) {
return new Promise((resolve, reject) => {
var addOnList = this.filterCustomizerAddon(allApps);
if (addOnList && addOnList.length == 1) {
resolve(addOnList[0]);
} else {
reject(new Error('Cannot fetch customizer add on'));
}
});
}

filterApps(apps) {
var excludedApps = ['Built-in Keyboard', 'Settings'];
var excludedApps = ['app://keyboard.gaiamobile.org/manifest.webapp',
'app://customizer-launcher.gaiamobile.org/manifest.webapp'];

return apps.filter(app =>
app.manifest.role !== 'addon' &&
app.manifest.role !== 'theme' &&
app.manifest.role !== 'system' &&
excludedApps.indexOf(app.manifest.name) === -1);
excludedApps.indexOf(app.manifestURL) === -1);
}

fillAppDetails(app) {
Expand All @@ -23,27 +48,14 @@ export default class ListModel extends Model {
return detail;
}

getAppList() {
getAppList(allApps) {
return new Promise((resolve, reject) => {
var installedApps = Object.create(null);
AppsHelper.getAllApps().then(allApps => {
var filterList = this.filterApps(allApps);
filterList.forEach(app => {
installedApps[app.manifestURL] = this.fillAppDetails(app);
});

this.logObject(installedApps);
resolve(installedApps);
});
var filterList = this.filterApps(allApps);
filterList.forEach(app =>
installedApps[app.manifestURL] = this.fillAppDetails(app));
resolve(installedApps);
});
}

logObject(app) {
for (let i in app)
{
console.log('property & values: ', i + ' : & : ');
console.log(app[i]);
}
}
}

0 comments on commit f659dcd

Please sign in to comment.