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

package nova.monadic_sfx.ui
import scalafx.application.JFXApp
import nova.monadic_sfx.executors.Schedulers
import monix.execution.Scheduler
import monix.eval.Task
import nova.monadic_sfx.screens.LoginScreen
import nova.monadic_sfx.AppTypes
import scalafx.application.Platform
import scala.concurrent.duration._
import io.odin.Logger
import monix.execution.Callback
import com.softwaremill.macwire._
import nova.monadic_sfx.http.Requesters
import akka.actor._
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.adapter._
import akka.actor.typed.scaladsl.Behaviors
import nova.monadic_sfx.actors.Counter
import akka.actor.typed.DispatcherSelector
class MyFxApp(
logger: Logger[Task],
backend: AppTypes.HttpBackend,
actorSystem: akka.actor.ActorSystem,
requesters: Requesters,
schedulers: Schedulers
) extends JFXApp {
implicit lazy val defaultScheduler: Scheduler = schedulers.fx
lazy val application =
for {
appStage <- Task(
UiModule.makePrimaryStage(backend, actorSystem)
)
// _ <- Task {
// val counterActor = testActor(actorSystem)
// counterActor ! (Counter.Increment)
// }
_ <- Task { stage = appStage }
_ <- Task.sleep(2.seconds)
loginScene <- wire[LoginScreen].render
_ <- Task {
// appStage.maximized = true
appStage.height = 800
appStage.width = 800
appStage
.scene()
.setRoot(
loginScene
)
}
} yield ()
def testActor(
system: ActorSystem
): akka.actor.typed.ActorRef[Counter.Command] = {
val behaviour: Behavior[Counter.Command] =
Behaviors.setup(context => wire[Counter])
system.spawn(
behaviour,
"CounterActor",
DispatcherSelector.fromConfig("javafx-dispatcher")
)
}
application.timed.runAsync(
new Callback[Throwable, (FiniteDuration, Unit)] {
override def onSuccess(value: (FiniteDuration, Unit)): Unit = {
val (duration, _) = value
println(
s"Application started successfully in ${duration.toSeconds} seconds"
)
}
override def onError(e: Throwable): Unit = {
println("Application start failed. Reason -")
e.printStackTrace()
}
}
)
override def stopApp() = {
Platform.exit()
}
}