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.

54 lines
1.6 KiB

4 years ago
3 years ago
4 years ago
  1. package nova.monadic_sfx
  2. import cats.effect.ExitCode
  3. import cats.effect.Resource
  4. import monix.bio.BIOApp
  5. import monix.bio.Task
  6. import monix.bio.UIO
  7. import monix.execution.Scheduler
  8. import nova.monadic_sfx.concurrent._
  9. import nova.monadic_sfx.util.MediaPlayerResource
  10. import nova.monadic_sfx.ui.FX
  11. // import nova.monadic_sfx.util.IOUtils._
  12. // import sttp.client.httpclient.monix.HttpClientMonixBackend
  13. object Main extends BIOApp {
  14. val schedulers = Schedulers.default
  15. override def scheduler: Scheduler = schedulers.async.value
  16. val appResource = for {
  17. startTime <- Resource.eval(Task(System.currentTimeMillis()))
  18. logger <- Loggers.makeLogger
  19. // backend and actorsystem are for future use
  20. // backend <- Resource.make(
  21. // toIO(HttpClientMonixBackend()(schedulers.async))
  22. // )(c => toIO(c.close()))
  23. // actorSystem <- actorSystemResource(logger)
  24. fx <- FX.resource(schedulers, App.stage)(logger)
  25. mediaPlayerResource <- MediaPlayerResource()
  26. rootComponent = new App(fx, schedulers, startTime, mediaPlayerResource)(
  27. logger
  28. ).init
  29. _ <- Resource.eval(
  30. rootComponent
  31. .evalMap(c =>
  32. for {
  33. _ <- Task.unit
  34. _ <- fx.addToScene(UIO.pure(c.node))
  35. _ <- fx.await
  36. } yield ()
  37. )
  38. .use(_ => Task.unit)
  39. .executeOn(schedulers.fx.value)
  40. )
  41. // _ <- Resource.eval(f)
  42. // _ <- Resource.eval(fx.await)
  43. } yield ()
  44. override def run(args: List[String]): UIO[ExitCode] =
  45. appResource
  46. .use(_ => Task.unit)
  47. .onErrorHandleWith(ex => UIO(ex.printStackTrace()))
  48. .as(ExitCode.Success)
  49. }