Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#12530 from EverythingMe/911568-nativeinfo
Browse files Browse the repository at this point in the history
Bug 911568 - [e.me][bug] Pre-installed apps don't show in relevant colle...
  • Loading branch information
amirnissim committed Oct 1, 2013
2 parents 4110b1c + 8251405 commit d9f9000
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 113 deletions.
4 changes: 2 additions & 2 deletions apps/homescreen/everything.me/js/Brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,10 @@ this.InstalledAppsService = new function InstalledAppsService() {

Evme.CollectionsSuggest.Loading.show();

Evme.CollectionStorage.getAllCollections(function onCollections(collections) {
EvmeManager.getCollections(function onCollections(collections) {
var existingCollectionsQueries = [];
for (var i = 0, collection; collection = collections[i++];) {
existingCollectionsQueries.push(collection.query);
existingCollectionsQueries.push(collection.manifest.name);
}

// load suggested shortcuts from API
Expand Down
1 change: 1 addition & 0 deletions apps/homescreen/everything.me/js/api/DoATAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ Evme.DoATAPI = new function Evme_DoATAPI() {
"methodNamespace": methodNamespace,
"methodName": methodName,
"params": params,
"originalOptions": options,
"callback": callback,
"requestTimeout": MAX_REQUEST_TIME,
"retries": NUMBER_OF_RETRIES,
Expand Down
122 changes: 18 additions & 104 deletions apps/homescreen/everything.me/modules/Collection/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void function() {

Evme.CollectionSettings.update(collectionSettings, data, function onUpdate(updatedSettings){
// collection is open and apps changed
if (currentSettings && 'apps' in data) {
if (currentSettings && currentSettings.id === collectionSettings.id && 'apps' in data) {
resultsManager.renderStaticApps(updatedSettings.apps);
}

Expand All @@ -119,7 +119,7 @@ void function() {

// first 3 apps changed
if (!shouldUpdateIcon && 'apps' in data) {
shouldUpdateIcon = !Evme.Utils.arraysEqual(originalAppIds,
shouldUpdateIcon = !Evme.Utils.arraysEqual(originalAppIds,
pluck(updatedSettings.apps, 'id'), numIcons);
}

Expand All @@ -128,7 +128,7 @@ void function() {
var numApps = ('apps' in data) ? data.apps.length : originalAppIds.length;;

if (numApps < numIcons){
shouldUpdateIcon = !Evme.Utils.arraysEqual(originalIcons,
shouldUpdateIcon = !Evme.Utils.arraysEqual(originalIcons,
pluck(updatedSettings.extraIconsData, 'icon'), numIcons);
}
}
Expand Down Expand Up @@ -192,9 +192,10 @@ void function() {
};

this.onQueryIndexUpdated = function onQueryIndexUpdated() {
// TODO
Evme.CollectionSettings.updateAll();
// move update homescreen here
var gridCollections = EvmeManager.getCollections();
gridCollections.forEach(function populate(gridCollection) {
Evme.CollectionStorage.get(gridCollection.id, populateCollection);
});
};

this.show = function show(e) {
Expand Down Expand Up @@ -457,17 +458,6 @@ void function() {
}
};

Evme.CollectionSettings.updateAll = function updateAll() {
// TODO
// see if this method required any changes
// get collection by EvmeManager.getCollections?
var ids = Evme.CollectionStorage.getAllIds();

for (var i = 0, id; id = ids[i++];) {
Evme.CollectionStorage.get(id, populateCollection);
}
};

// save collection settings in storage and run callback async.
function saveSettings(settings, cb) {
Evme.CollectionStorage.add(settings, function onStored() {
Expand All @@ -479,7 +469,7 @@ void function() {
var existingIds = Evme.Utils.pluck(settings.apps, 'id');

var newApps = Evme.InstalledAppsService.getMatchingApps({
'query': settings.query
'experienceId': settings.experienceId
});

newApps = newApps.filter(function isNew(app) {
Expand Down Expand Up @@ -518,39 +508,27 @@ void function() {

/**
* CollectionStorage
* Persists settings to local storage
* Persists collection settings to local storage
*
* TODO encapsulate - don't expose as Evme.CollectionStorage
*/
Evme.CollectionStorage = new function Evme_CollectionStorage() {
var NAME = 'CollectionStorage',
IDS_STORAGE_KEY = 'evmeCollection',
PREFIX = 'collectionsettings_',
self = this,
ids = null,
ID_LOCK_RETRY_TIME = 100,
locked = false; // locks the ids list
self = this;

this.init = function init() {
Evme.Storage.get(IDS_STORAGE_KEY, function onGet(storedIds) {
ids = storedIds || [];
});

window.addEventListener('collectionUninstalled', onCollectionUninstalled);
};

this.remove = function remove(collectionId) {
removeId(collectionId);
Evme.Storage.remove(PREFIX + collectionId);
};

this.add = function add(settings, cb) {
this.add = function add(settings, cb=Evme.Utils.NOOP) {
if (!settings.id) return;

Evme.Storage.set(PREFIX + settings.id, settings, function onSet() {
addId(settings.id);
if (cb instanceof Function) {
cb(settings);
}
cb(settings);
});
};

Expand All @@ -561,82 +539,18 @@ void function() {
self.add(settings, cb);
};

this.get = function get(settingsId, cb) {
this.get = function get(settingsId, cb=Evme.Utils.NOOP) {
Evme.Storage.get(PREFIX + settingsId, function onGet(storedSettings) {
if (cb && storedSettings !== null) {
if (storedSettings !== null) {
var settings = new Evme.CollectionSettings(storedSettings);
if (cb instanceof Function) {
cb(settings);
}
cb(settings);
}
});
};

this.getAllIds = function getAllIds() {
return ids;
};

this.getAllCollections = function getAllCollections(callback) {
var ids = self.getAllIds(),
collections = [];

for (var i = 0, id; id = ids[i++];) {
self.get(id, onGotCollectionSettings);
}

function onGotCollectionSettings(settings) {
collections.push(settings);
if (collections.length === ids.length) {
callback(collections);
}
}
};

function onCollectionUninstalled(e) {
removeId(e.detail.collection.id);
}

function addId(id) {
if (ids && ids.indexOf(id) > -1) return;

if (ids === null || locked) {
setTimeout(function retry() {addId(id); }, ID_LOCK_RETRY_TIME);
return;
}

try {
lock();
ids.push(id);
Evme.Storage.set(IDS_STORAGE_KEY, ids, unlock);
} catch (ex) {
unlock();
}
}

function removeId(id) {
if (ids === null || locked) {
setTimeout(function retry() {removeId(id); }, ID_LOCK_RETRY_TIME);
return;
}

try {
lock();
ids = ids.filter(function neqId(storedId) {return storedId !== id });
Evme.CollectionStorage.set(IDS_STORAGE_KEY, ids, function onRemoved() {
unlock();
Evme.Storage.remove(PREFIX + collectionId);
});
} catch (ex) {
unlock();
}
}

function lock() {
locked = true;
}

function unlock() {
locked = false;
var collectionId = e.detail.collection.id;
self.remove(collectionId);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ Evme.InstalledAppsService = new function Evme_InstalledAppsService() {
}

this.requestAppsInfo = function requestAppsInfo() {
var gridApps = EvmeManager.getGridApps(),
guids = gridApps.map(function getId(gridApp){
return gridApp.manifestURL || gridApp.bookmarkURL;
var gridApps = EvmeManager.getGridApps();

var guids = gridApps.map(function getId(gridApp){
return gridApp.app.manifestURL || gridApp.app.bookmarkURL;
});

Evme.EventHandler.trigger(NAME, "requestAppsInfo", guids);
Expand Down Expand Up @@ -154,12 +155,20 @@ Evme.InstalledAppsService = new function Evme_InstalledAppsService() {
};

this.getMatchingApps = function getMatchingApps(data) {
if (!data || !data.query) {
return [];
var matchingApps = [],
query;

if (data.query) {
query = data.query;
} else if (data.experienceId) {
query = Evme.Utils.shortcutIdToKey(data.experienceId);
}

var matchingApps = [],
query = normalizeQuery(data.query);
if (!query) {
return matchingApps;
}

query = normalizeQuery(query);

// search appIndex
// search query within first letters of app name words
Expand Down

0 comments on commit d9f9000

Please sign in to comment.