This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.fs
59 lines (47 loc) · 2.07 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace NetworkDetection
open Elmish
open Avalonia
open Avalonia.Controls.ApplicationLifetimes
open Avalonia.FuncUI
open Avalonia.FuncUI.Elmish
open Avalonia.FuncUI.Components.Hosts
open System.Net.NetworkInformation
open Avalonia.Threading
open Avalonia.Controls.Notifications
type MainWindow() as this =
inherit HostWindow()
do
base.Title <- "NetworkDetection"
base.Width <- 600.0
base.Height <- 400.0
//this.VisualRoot.VisualRoot.Renderer.DrawFps <- true
//this.VisualRoot.VisualRoot.Renderer.DrawDirtyRects <- true
let networkStatus (initial: Counter.State) =
let sub dispatch =
NetworkChange.NetworkAvailabilityChanged.Subscribe
(fun args -> dispatch (Counter.Msg.NetworkChanged args.IsAvailable)) |> ignore
Cmd.ofSub sub
let syncDispatch (dispatch: Dispatch<'msg>): Dispatch<'msg> =
match Dispatcher.UIThread.CheckAccess() with
| true -> fun msg -> Dispatcher.UIThread.Post(fun () -> dispatch msg)
| false -> fun msg -> dispatch msg
let notificationManager = WindowNotificationManager(this)
Elmish.Program.mkSimple (fun () -> (Counter.init notificationManager)) Counter.update Counter.view
|> Program.withHost this
|> Program.withSyncDispatch syncDispatch
|> Program.withSubscription networkStatus
|> Program.withConsoleTrace
|> Program.run
type App() =
inherit Application()
override this.Initialize() =
this.Styles.Load "avares://Avalonia.Themes.Default/DefaultTheme.xaml"
this.Styles.Load "avares://Avalonia.Themes.Default/Accents/BaseDark.xaml"
override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktopLifetime -> desktopLifetime.MainWindow <- MainWindow()
| _ -> ()
module Program =
[<EntryPoint>]
let main (args: string []) =
AppBuilder.Configure<App>().UsePlatformDetect().UseSkia().StartWithClassicDesktopLifetime(args)