VulpesOS/assets/webapps/system.gaiamobile.org/js/applications.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

5 lines
No EOL
2.9 KiB
JavaScript

;'use strict';(function(exports){function Applications(){}
Applications.prototype={installedApps:{},ready:false,stop:function a_stop(){this.ready=false;this.installedApps={};navigator.mozApps.mgmt.getAll().onsuccess=null;navigator.mozApps.mgmt.oninstall=null;navigator.mozApps.mgmt.onuninstall=null;},waitForReady:function(){return new Promise((resolve)=>{if(this.ready){resolve();}else{this.waitingResolve=resolve;}});},start:function a_start(){var self=this;var apps=navigator.mozApps;var getAllApps=function getAllApps(){navigator.mozApps.mgmt.getAll().onsuccess=function mozAppGotAll(evt){var apps=evt.target.result;apps.forEach(function(app){self.installedApps[app.manifestURL]=app;});self.ready=true;self.fireApplicationReadyEvent();self.waitingResolve&&self.waitingResolve();};};if(window.sessionStorage.getItem('webapps-registry-ready')){getAllApps();}else{window.addEventListener('mozChromeEvent',function mozAppReady(event){if(event.detail.type!='webapps-registry-ready'){return;}
window.sessionStorage.setItem('webapps-registry-ready','yes');window.removeEventListener('mozChromeEvent',mozAppReady);getAllApps();});}
apps.mgmt.oninstall=function a_install(evt){var newapp=evt.application;self.installedApps[newapp.manifestURL]=newapp;self.fireApplicationInstallEvent(newapp);};apps.mgmt.onuninstall=function a_uninstall(evt){var deletedapp=evt.application;delete self.installedApps[deletedapp.manifestURL];self.fireApplicationUninstallEvent(deletedapp);};apps.mgmt.onenabledstatechange=function a_enabledstatechange(evt){var app=evt.application;if(app.enabled){self.fireApplicationEnabledEvent(app);}else{self.fireApplicationDisabledEvent(app);}};},getByManifestURL:function a_getByManifestURL(manifestURL){if(manifestURL in this.installedApps){return this.installedApps[manifestURL];}
return null;},fireApplicationReadyEvent:function a_fireAppReadyEvent(){var evt=new CustomEvent('applicationready',{bubbles:true,cancelable:false,detail:{applications:this.installedApps}});window.dispatchEvent(evt);},fireApplicationInstallEvent:function a_fireApplicationInstallEvent(app){var evt=new CustomEvent('applicationinstall',{bubbles:true,cancelable:false,detail:{application:app}});window.dispatchEvent(evt);},fireApplicationUninstallEvent:function a_fireApplicationUninstallEvent(app){var evt=new CustomEvent('applicationuninstall',{bubbles:true,cancelable:false,detail:{application:app}});window.dispatchEvent(evt);},fireApplicationEnabledEvent:function a_fireApplicationEnabledEvent(app){var evt=new CustomEvent('applicationenabled',{bubbles:true,cancelable:false,detail:{application:app}});window.dispatchEvent(evt);},fireApplicationDisabledEvent:function a_fireApplicationDisabledEvent(app){var evt=new CustomEvent('applicationdisabled',{bubbles:true,cancelable:false,detail:{application:app}});window.dispatchEvent(evt);}};exports.Applications=Applications;}(window));window.applications=new Applications();applications.start();