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.

90 lines
2.3 KiB

  1. package nova.monadic_sfx.ui
  2. import scalafx.application.JFXApp
  3. import nova.monadic_sfx.executors.Schedulers
  4. import monix.execution.Scheduler
  5. import monix.eval.Task
  6. import nova.monadic_sfx.screens.LoginScreen
  7. import nova.monadic_sfx.AppTypes
  8. import scalafx.application.Platform
  9. import scala.concurrent.duration._
  10. import io.odin.Logger
  11. import monix.execution.Callback
  12. import com.softwaremill.macwire._
  13. import nova.monadic_sfx.http.Requesters
  14. import akka.actor._
  15. import akka.actor.typed.Behavior
  16. import akka.actor.typed.scaladsl.adapter._
  17. import akka.actor.typed.scaladsl.Behaviors
  18. import nova.monadic_sfx.actors.Counter
  19. import akka.actor.typed.DispatcherSelector
  20. class MyFxApp(
  21. logger: Logger[Task],
  22. backend: AppTypes.HttpBackend,
  23. actorSystem: akka.actor.ActorSystem,
  24. requesters: Requesters,
  25. schedulers: Schedulers
  26. ) extends JFXApp {
  27. implicit lazy val defaultScheduler: Scheduler = schedulers.fx
  28. lazy val application =
  29. for {
  30. appStage <- Task(
  31. UiModule.makePrimaryStage(backend, actorSystem)
  32. )
  33. // _ <- Task {
  34. // val counterActor = testActor(actorSystem)
  35. // counterActor ! (Counter.Increment)
  36. // }
  37. _ <- Task { stage = appStage }
  38. _ <- Task.sleep(2.seconds)
  39. loginScene <- wire[LoginScreen].render
  40. _ <- Task {
  41. // appStage.maximized = true
  42. appStage.height = 800
  43. appStage.width = 800
  44. appStage
  45. .scene()
  46. .setRoot(
  47. loginScene
  48. )
  49. }
  50. } yield ()
  51. def testActor(
  52. system: ActorSystem
  53. ): akka.actor.typed.ActorRef[Counter.Command] = {
  54. val behaviour: Behavior[Counter.Command] =
  55. Behaviors.setup(context => wire[Counter])
  56. system.spawn(
  57. behaviour,
  58. "CounterActor",
  59. DispatcherSelector.fromConfig("javafx-dispatcher")
  60. )
  61. }
  62. application.timed.runAsync(
  63. new Callback[Throwable, (FiniteDuration, Unit)] {
  64. override def onSuccess(value: (FiniteDuration, Unit)): Unit = {
  65. val (duration, _) = value
  66. println(
  67. s"Application started successfully in ${duration.toSeconds} seconds"
  68. )
  69. }
  70. override def onError(e: Throwable): Unit = {
  71. println("Application start failed. Reason -")
  72. e.printStackTrace()
  73. }
  74. }
  75. )
  76. override def stopApp() = {
  77. Platform.exit()
  78. }
  79. }