VulpesOS/assets/webapps/verticalhome.gaiamobile.org/js/sources/application.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

17 lines
No EOL
4.7 KiB
JavaScript

;'use strict';(function(exports){var appMgr=navigator.mozApps.mgmt;var apps=null;window.performance.mark('homescreenStart@system.gaiamobile.org');appMgr.getAll().onsuccess=function onsuccess(event){apps=event.target.result;window.dispatchEvent(new CustomEvent('navigator-mozapps-ready'));};function ApplicationSource(store){this.store=store;this.entries=[];this.entriesByManifestUrl={};this.svPreviouslyInstalledApps=[];var pendingInstallRequests=[];function addSVEventListener(){window.addEventListener('singlevariant-ready',function svFileReady(ev){window.removeEventListener('singlevariant-ready',svFileReady);for(var i=0;i<pendingInstallRequests;i++){pendingInstallRequests[i]();}});}
addSVEventListener();var self=this;function addIcons(){window.removeEventListener('navigator-mozapps-ready',addIcons);for(var i=0,iLen=apps.length;i<iLen;i++){self.makeIcons(apps[i]);}
apps=null;}
apps?addIcons():window.addEventListener('navigator-mozapps-ready',addIcons);function install(application){var manifest=application.manifest||application.updateManifest;if(manifest.role&&app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}
this.addIconToGrid(application);var svApp=configurator.getSingleVariantApp(application.manifestURL);var lastElem=app.grid.getIndexLastIcon();if(configurator.isSimPresentOnFirstBoot&&svApp&&svApp.location<lastElem&&!this.isPreviouslyInstalled(application.manifestURL)){app.grid.popDivider();app.grid.removeNonVisualElements();lastElem=app.grid.getIndexLastIcon();app.grid.moveTo(lastElem,svApp.location);_moveAhead(svApp.location+1);this.addPreviouslyInstalledSvApp(application.manifestURL);app.itemStore.savePrevInstalledSvApp(this.svPreviouslyInstalledApps);}
app.grid.render();app.itemStore.deferredSave(app.grid.getItems());}
function _moveAhead(startPos){var elems=app.grid.getItems();for(var i=startPos,iLen=elems.length;i<iLen;i++){var item=elems[i];if(item instanceof GaiaGrid.Mozapp){var svApp=configurator.getSingleVariantApp(elems[i].identifier);if(svApp&&i>svApp.location){app.grid.moveTo(i,i-1);}}}}
appMgr.oninstall=function oninstall(event){if(configurator.isSingleVariantReady){install.bind(this)(event.application);}else{pendingInstallRequests.push(install.bind(this,event.application));}}.bind(this);appMgr.onuninstall=function onuninstall(event){var application=event.application;var manifest=application.updateManifest||application.manifest;this.removeIconFromGrid(application.manifestURL);app.itemStore.deferredSave(app.grid.getItems());if(app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}}.bind(this);}
ApplicationSource.prototype={synchronize:function(){var storeItems=this.store._allItems;var toAdd=[];var appIconsByManifestUrl={};for(var i=0,iLen=storeItems.length;i<iLen;i++){var item=storeItems[i];if(!(item instanceof GaiaGrid.Mozapp)){continue;}
appIconsByManifestUrl[item.detail.manifestURL]=item;}
for(i=0,iLen=this.entries.length;i<iLen;i++){var entry=this.entries[i];var manifest=entry.app.updateManifest||entry.app.manifest;if(!appIconsByManifestUrl[entry.detail.manifestURL]&&!manifest.entry_points){toAdd.push(entry);}else{delete appIconsByManifestUrl[entry.detail.manifestURL];}}
for(i in appIconsByManifestUrl){this.removeIconFromGrid(i);}
toAdd.forEach(function _toAdd(newApp){this.addIconToGrid(newApp.app);},this);app.itemStore.deferredSave(app.grid.getItems());},addIconToGrid:function(application){this.makeIcons(application);var appObject=this.mapToApp({manifestURL:application.manifestURL});app.grid.appendItemToExpandedGroup(appObject);app.grid.render();},removeIconFromGrid:function(manifestURL){var icons=app.grid.getIcons();var appObject=icons[manifestURL];if(appObject){appObject.removeFromGrid();}},populate:function(success){success(this.entries);},makeIcons:function(eachApp){var manifest=eachApp.manifest||eachApp.updateManifest;if(app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}
function eachIcon(icon){if(!icon.icon){return;}
icon.setPosition(this.store.getNextPosition());this.entries.push(icon);}
this.entriesByManifestUrl[eachApp.manifestURL]=eachApp;if(manifest.entry_points){for(var i in manifest.entry_points){eachIcon.call(this,new GaiaGrid.Mozapp(eachApp,i));}}else{eachIcon.call(this,new GaiaGrid.Mozapp(eachApp));}},mapToApp:function(entry){var app=this.entriesByManifestUrl[entry.manifestURL];app=app||{manifestURL:entry.manifestURL,manifest:{name:'',icons:[]}};return new GaiaGrid.Mozapp(app,entry.entryPoint,{decoratedIconBlob:entry.decoratedIconBlob});},addPreviouslyInstalledSvApp:function(manifest){this.svPreviouslyInstalledApps.push({manifestURL:manifest});},isPreviouslyInstalled:function(manifest){for(var i=0,elemNum=this.svPreviouslyInstalledApps.length;i<elemNum;i++){if(this.svPreviouslyInstalledApps[i].manifestURL===manifest){return true;}}
return false;}};exports.ApplicationSource=ApplicationSource;}(window));