You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. package nova.monadic_sfx.ui
  2. import scala.concurrent.duration._
  3. import io.odin.Logger
  4. import monix.bio.Task
  5. import nova.monadic_sfx.executors.Schedulers
  6. import nova.monadic_sfx.ui.DefaultUI
  7. import scalafx.application.JFXApp
  8. import scalafx.application.JFXApp.PrimaryStage
  9. class MyFxApp(val schedulers: Schedulers)(implicit logger: Logger[Task]) {
  10. private lazy val internal = new JFXApp {
  11. stage = new PrimaryStage {
  12. scene = DefaultUI.scene
  13. }
  14. }
  15. // def stage = Task(internal.stage)
  16. // def stage_=(stage: PrimaryStage) = Task(internal.stage = stage)
  17. // def useInternal[T](f: JFXApp => Task[T]): Task[T] =
  18. // for {
  19. // _ <- logger.debug("Request for using internal value")
  20. // res <- f(internal).executeOn(schedulers.fx)
  21. // _ <- logger.debug(s"Result was ${res.toString()}")
  22. // } yield (res)
  23. def init(stage: => PrimaryStage, delay: FiniteDuration = 200.millis) =
  24. for {
  25. _ <- logger.info("Starting FX App")
  26. fib <- Task(internal.main(Array.empty)).start
  27. _ <- Task.sleep(200.millis)
  28. _ <- Task(internal.stage = stage)
  29. .executeOn(schedulers.fx)
  30. .delayExecution(delay)
  31. } yield (this, fib)
  32. }