on master help sign in
Migrate client to Fabulous 3.0: use Cmd.OfAsync APIs instead of manual asyncCmd helper
1f3015eiko
client/App.fs+24−37
@@ -412,14 +412,6 @@ module App =
412
412
413 let private log msg = eprintfn $"[skrepka] {msg}"
413 let private log msg = eprintfn $"[skrepka] {msg}"
414
414
415− let private asyncCmd (op: Async<Msg>) : Cmd<Msg> =
416− Cmd.ofEffect (fun dispatch ->
417− async {
418− let! msg = op
419− dispatch msg
420− }
421− |> Async.Start)
422−
423 let private serializeEnvelope =
415 let private serializeEnvelope =
424 function
416 function
425 | Envelope.TextMessage(id, body) ->
417 | Envelope.TextMessage(id, body) ->
@@ -503,28 +495,20 @@ module App =
503 let mapCmd cmdMsg =
495 let mapCmd cmdMsg =
504 match cmdMsg with
496 match cmdMsg with
505 | CmdConnect(url, identity) ->
497 | CmdConnect(url, identity) ->
506− asyncCmd (
498+ Cmd.OfAsync.either
507− async {
508− try
509− let! token = authenticate url identity
499+ (fun (url, id) -> authenticate url id)
500+ (url, identity)
510− return AuthOk token
501+ AuthOk
511− with ex ->
512− return AuthErr ex.Message
502+ (fun ex -> AuthErr ex.Message)
513− }
514− )
515
503
516 | CmdSend(session, recipientHex, envelope) ->
504 | CmdSend(session, recipientHex, envelope) ->
517− Cmd.ofEffect (fun dispatch ->
505+ Cmd.OfAsync.attempt
518− async {
506+ (fun (s, r, e) -> sendEnvelope s r e)
519− try
520− do! sendEnvelope session recipientHex envelope
507+ (session, recipientHex, envelope)
521− with ex ->
522− dispatch (SendFailed ex.Message)
508+ (fun ex -> SendFailed ex.Message)
523− }
524− |> Async.Start)
525
509
526 | CmdPoll(session, cursor) ->
510 | CmdPoll(session, cursor) ->
527− asyncCmd (
511+ Cmd.ofEffect (fun dispatch ->
528 async {
512 async {
529 log $"poll start cursor={cursor}"
513 log $"poll start cursor={cursor}"
530
514
@@ -597,17 +581,17 @@ module App =
597 | Some e -> $" [{e}]"
581 | Some e -> $" [{e}]"
598 | None -> "")
582 | None -> "")
599
583
600− return PollResult(events, status, response.Cursor)
584+ dispatch (PollResult(events, status, response.Cursor))
601 with
585 with
602 | :? TimeoutException ->
586 | :? TimeoutException ->
603 log "poll timeout"
587 log "poll timeout"
604− return PollResult([], "polling...", cursor)
588+ dispatch (PollResult([], "polling...", cursor))
605 | ex ->
589 | ex ->
606 log $"poll error: {ex.Message}"
590 log $"poll error: {ex.Message}"
607 do! Async.Sleep 3000
591 do! Async.Sleep 3000
608− return PollResult([], $"poll error: {ex.Message}", cursor)
592+ dispatch (PollResult([], $"poll error: {ex.Message}", cursor))
609 }
593 }
610− )
594+ |> Async.Start)
611
595
612 | CmdCopyToClipboard text ->
596 | CmdCopyToClipboard text ->
613 Cmd.ofEffect (fun _ ->
597 Cmd.ofEffect (fun _ ->
@@ -615,13 +599,15 @@ module App =
615 |> ignore)
599 |> ignore)
616
600
617 | CmdLoadState ->
601 | CmdLoadState ->
618− asyncCmd (
602+ Cmd.OfAsync.perform
603+ (fun () ->
619− async {
604+ async {
620− match! Store.loadIdentity () with
605+ match! Store.loadIdentity () with
621− | Some id -> return StateLoaded(Some id, Store.loadData (), Store.loadProfile ())
606+ | Some id -> return (Some id, Store.loadData (), Store.loadProfile ())
622− | None -> return StateLoaded(None, None, None)
607+ | None -> return (None, None, None)
623− }
608+ })
624− )
609+ ()
610+ StateLoaded
625
611
626 | CmdSaveIdentity identity -> Cmd.ofEffect (fun _ -> Store.saveIdentity identity |> Async.Start)
612 | CmdSaveIdentity identity -> Cmd.ofEffect (fun _ -> Store.saveIdentity identity |> Async.Start)
627
613
@@ -669,6 +655,7 @@ module App =
669 Label("End-to-end encrypted messaging").font(size = 16.).centerTextHorizontal ()
655 Label("End-to-end encrypted messaging").font(size = 16.).centerTextHorizontal ()
670
656
671
657
658+ button "Next" GenIdentity
672 Button("Generate Identity", GenIdentity).centerHorizontal ()
659 Button("Generate Identity", GenIdentity).centerHorizontal ()
673 })
660 })
674 .padding(30.)
661 .padding(30.)
client/Buttons.fs+19−2
@@ -7,9 +7,26 @@ open System.Text.Json
7open Fabulous
7open Fabulous
8open Fabulous.Maui
8open Fabulous.Maui
9open Microsoft.Maui.Graphics
9open Microsoft.Maui.Graphics
10+open Fabulous
11+open Fabulous.Maui
12+open Microsoft.Maui
13+open Microsoft.Maui.Graphics
10
14
11open type Fabulous.Maui.View
15open type Fabulous.Maui.View
12
16
13module Buttons =
17module Buttons =
18+ open Microsoft.Maui
19+
14− let button (text: string) (msg: 'msg) : WidgetBuilder<'msg, IFabButton> =
20+ let button (text: string) (msg: 'msg) : WidgetBuilder<'msg, _> =
21+ Component(text) {
22+ Grid() {
23+ Rectangle().margin(Thickness(8., 8., -8., -8.)).background (Colors.Black)
24+
25+ Button(text, msg)
26+ .borderWidth(4)
15− (Button(text, msg).borderWidth(4).background (Constants.accentColor)).borderColor (Colors.Black)
27+ .background(Constants.accentColor)
28+ .borderColor(Colors.Black)
29+ .textColor(Colors.White)
30+ .font (fontFamily = "UnboundedBold", size = 24.)
31+ }
32+ }
client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfo.fs+1−1
@@ -10,7 +10,7 @@ open System.Reflection
10[<assembly: System.Reflection.AssemblyCompanyAttribute("Skrepka")>]
10[<assembly: System.Reflection.AssemblyCompanyAttribute("Skrepka")>]
11[<assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")>]
11[<assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")>]
12[<assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")>]
12[<assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")>]
13−[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0+f1f6e116e2295466bfea4623e453ffed25d32079")>]
13+[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0+c622597942208741d3c804aefd43a0d3c4efc092")>]
14[<assembly: System.Reflection.AssemblyProductAttribute("Skrepka")>]
14[<assembly: System.Reflection.AssemblyProductAttribute("Skrepka")>]
15[<assembly: System.Reflection.AssemblyTitleAttribute("Skrepka")>]
15[<assembly: System.Reflection.AssemblyTitleAttribute("Skrepka")>]
16[<assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")>]
16[<assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")>]
client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfoInputs.cache+1−1
@@ -1 +1 @@
1−e379db3bdff4a4a771cdab0914453c7ee01e98a757a35695e8595a28293a349c
1+cea69c3a0745f404bdbfe2dfe0d3d4978e6dac8ccf2ed5f2edd84f58fc06912a