sourceafQuickFlux::Main.fan

using flux
using fwt
using afIoc
using concurrent

class Main {
    static const AtomicRef moduleType   := AtomicRef()
    
    static Void go(Type module, Type[] sideBars, Uri? startUri := null) {

        // a quick fix for quick flux!
        moduleType.val = module
        
        registry := IocService().addModules([module]).addModulesFromPod(module.pod.name).start.registry
        try {
        
            f := FluxFrame()
            (registry.serviceById("frameInjector") as FrameInjector).setFrame(f.frame)
            
            f.loadState

            // counter wot happens in loadState
            f.hideNavBar
            sideBars.each { f.sideBar(it).show }
            
            if (startUri != null)
                f.load(startUri)

            f.onOpen.add { 
                eventHub := registry.dependencyByType(EventHub#) as EventHub
                eventHub.fireEvent(Events.appStart)
            }
            f.open
        
        } finally {         
            echo("DONE")
            Service.find(IocService#).uninstall
        }       
        
    }
    
}