import'./root/root-legacy.js';import*as RootModule from'./root/root.js';self.Runtime=self.Runtime||{};Runtime=Runtime||{};self.Runtime.cachedResources={__proto__:null};self.Root=self.Root||{};Root=Root||{};Root.allDescriptors=Root.allDescriptors||[];Root.applicationDescriptor=Root.applicationDescriptor||undefined;let appStartedPromiseCallback;Runtime.appStarted=new Promise(fulfil=>appStartedPromiseCallback=fulfil);export async function startApplication(appName){console.timeStamp('Root.Runtime.startApplication');const allDescriptorsByName={};for(let i=0;i<Root.allDescriptors.length;++i){const d=Root.allDescriptors[i];allDescriptorsByName[d['name']]=d;}
if(!Root.applicationDescriptor){let data=await RootModule.Runtime.loadResourcePromise(appName+'.json');Root.applicationDescriptor=JSON.parse(data);let descriptor=Root.applicationDescriptor;while(descriptor.extends){data=await RootModule.Runtime.loadResourcePromise(descriptor.extends+'.json');descriptor=JSON.parse(data);Root.applicationDescriptor.modules=descriptor.modules.concat(Root.applicationDescriptor.modules);}}
const configuration=Root.applicationDescriptor.modules;const moduleJSONPromises=[];const coreModuleNames=[];for(let i=0;i<configuration.length;++i){const descriptor=configuration[i];const name=descriptor['name'];const moduleJSON=allDescriptorsByName[name];if(moduleJSON){moduleJSONPromises.push(Promise.resolve(moduleJSON));}else{moduleJSONPromises.push(RootModule.Runtime.loadResourcePromise(name+'/module.json').then(JSON.parse.bind(JSON)));}
if(descriptor['type']==='autostart'){coreModuleNames.push(name);}}
const moduleDescriptors=await Promise.all(moduleJSONPromises);for(let i=0;i<moduleDescriptors.length;++i){moduleDescriptors[i].name=configuration[i]['name'];moduleDescriptors[i].condition=configuration[i]['condition'];moduleDescriptors[i].remote=configuration[i]['type']==='remote';}
self.runtime=RootModule.Runtime.Runtime.instance({forceNew:true,moduleDescriptors});if(coreModuleNames){await self.runtime.loadAutoStartModules(coreModuleNames);}
appStartedPromiseCallback();}
export async function startWorker(appName){return startApplication(appName).then(sendWorkerReady);function sendWorkerReady(){self.postMessage('workerReady');}}