Permalink
Browse files

Additional page / screen load logging and added ScreenManager.waitFor…

…WindowLoad to allow not waiting for the window to completely load before continuing with application startup (defaults to true)
  • Loading branch information...
darkfrog26 committed Feb 7, 2019
1 parent bf69e86 commit b0194e04289823a892e5fa98851fb3d0fc88aceb
@@ -29,11 +29,14 @@ trait ContentScreen extends Screen with PathActivation {
.copy(path = path, parameters = Parameters.empty)
.withParam("part", "true")
.withParam("selector", "screen")
scribe.info(s"Loading content $url...")
StreamURL.stream(url).map { htmlString =>
scribe.info(s"Content loaded successfully (${htmlString.length} characters)")
val screen = dom.fromString[html.Element](htmlString).headOption.getOrElse(throw new RuntimeException(s"No content found in: [$htmlString] for URL: $url"))
loadScreen(screen)
}
} else { // Content has already been loaded either by page load or by previous load
scribe.info("Content is already loaded!")
Future.successful(())
}
}
@@ -19,12 +19,26 @@ trait ScreenManager {
val active: Var[Screen] = Var(EmptyScreen)
val loaded: Val[Boolean] = Var(false)

protected def waitForWindowLoad: Boolean = true

scribe.info("Initializing application...")
init().foreach { _ =>
window.addEventListener("load", (_: Event) => {
if (waitForWindowLoad) {
scribe.info("Application initialized. Waiting for window load to complete...")
window.addEventListener("load", (_: Event) => {
scribe.info("Window loading complete. Loading application...")
load().foreach { _ =>
scribe.info("Application loaded.")
loaded.asInstanceOf[Var[Boolean]] := true
}
})
} else {
scribe.info("Application initialized. Loading application...")
load().foreach { _ =>
scribe.info("Application loaded.")
loaded.asInstanceOf[Var[Boolean]] := true
}
})
}
}

active.changes {

0 comments on commit b0194e0

Please sign in to comment.