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.
129 lines
3.6 KiB
129 lines
3.6 KiB
package nova.monadic_sfx.ui
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
import akka.actor.typed._
|
|
import akka.util.Timeout
|
|
import com.softwaremill.macwire._
|
|
import io.odin.Logger
|
|
import monix.eval.Task
|
|
import monix.execution.Callback
|
|
import monix.execution.Scheduler
|
|
import nova.monadic_sfx.AppTypes
|
|
import nova.monadic_sfx.actors.Counter
|
|
import nova.monadic_sfx.executors.Schedulers
|
|
import nova.monadic_sfx.http.Requesters
|
|
import scalafx.application.JFXApp
|
|
|
|
class MyFxAppOld(
|
|
logger: Logger[Task],
|
|
backend: AppTypes.HttpBackend,
|
|
actorSystem: ActorSystem[SpawnProtocol.Command],
|
|
requesters: Requesters,
|
|
schedulers: Schedulers
|
|
) extends JFXApp {
|
|
|
|
implicit lazy val defaultScheduler: Scheduler = schedulers.fx
|
|
|
|
// lazy val fxActor: Task[ActorRef[Counter.Command]] = wireWith(
|
|
// MyFxApp.makeCounterActor _
|
|
// )
|
|
|
|
lazy val application =
|
|
for {
|
|
appStage <- Task(wireWith(UiModule.makePrimaryStage _))
|
|
|
|
// _ <- Task {
|
|
// val counterActor = testActor(actorSystem)
|
|
// counterActor ! (Counter.Increment)
|
|
// }
|
|
// ta <- testActor2(actorSystem)
|
|
// actor <-
|
|
// actorTask.bracket(actor => Task(actor ! (Counter.Increment)))(actor =>
|
|
// Task(actor ! (Counter.Stop))
|
|
// )
|
|
// actor <- actorTask
|
|
// actor <- fxActor
|
|
// _ <- Task(actor ! 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() = {
|
|
// val stop = for {
|
|
// actor <- fxActor
|
|
// _ <- logger.info("Stopping actor counter")
|
|
// // _ <- Task.fromFuture { actor.ask[Counter.Value](Counter.GetValue) }
|
|
// t <- Task(actor ! Counter.Stop)
|
|
// // _ <- Task.sleep(1.second)
|
|
// _ <- logger.info("Counter actor stopped")
|
|
// } yield ()
|
|
// stop.runAsyncAndForget
|
|
// // Platform.exit()
|
|
}
|
|
}
|
|
|
|
object MyFxAppOld {
|
|
def makeCounterActor(
|
|
system: ActorSystem[SpawnProtocol.Command],
|
|
logger: Logger[Task]
|
|
): Task[ActorRef[Counter.Command]] = {
|
|
import akka.actor.typed.scaladsl.AskPattern._
|
|
import scala.concurrent.ExecutionContext
|
|
|
|
implicit val timeout: Timeout = Timeout(3.seconds)
|
|
implicit val ec: ExecutionContext = system.executionContext
|
|
implicit val scheduler = system.scheduler
|
|
Task.fromFuture {
|
|
system.ask(
|
|
SpawnProtocol.Spawn(
|
|
behavior = wireWith(Counter.apply _),
|
|
name = "counterActor",
|
|
DispatcherSelector.fromConfig("javafx-dispatcher"),
|
|
_
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|