Skip to content

Commit

Permalink
draft:RemoteDemo(動作しない)
Browse files Browse the repository at this point in the history
- そのうち続きやるかも
  • Loading branch information
SilkyFowl committed Apr 30, 2022
1 parent 87e54b9 commit 97a114f
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions src/Samples/Program.fs
Expand Up @@ -11,7 +11,7 @@ type App() =
inherit Application()

override this.Initialize() =
this.Styles.Add (FluentTheme(baseUri = null, Mode = FluentThemeMode.Dark))
this.Styles.Add(FluentTheme(baseUri = null, Mode = FluentThemeMode.Dark))
this.Styles.Load "avares://Samples/Styles.xaml"

override this.OnFrameworkInitializationCompleted() =
Expand All @@ -20,11 +20,61 @@ type App() =
desktopLifetime.MainWindow <- Shell.MainWindow()
| _ -> ()

module Program =

module Remote =
open System.Net
open System.Net.Sockets
open Avalonia.Controls
open Avalonia.Controls.Remote
open Avalonia.Remote.Protocol
open Avalonia.Threading

/// 参考:https://github.com/AvaloniaUI/Avalonia/blob/cba80543048c9f566a17f657d93a5bf22b4006fa/samples/RemoteDemo/Program.cs
/// 画面は出るがまともに動作しない……
/// とりあえず書き置き
let remote (args: string []) =
let _ =
AppBuilder
.Configure<App>()
.UsePlatformDetect()
.SetupWithoutStarting()

let l = TcpListener(IPAddress.Loopback, 0)
l.Start()
let port = (l.LocalEndpoint :?> IPEndPoint).Port
l.Stop()
let transport = new BsonTcpTransport()

let _ =
transport.Listen(
IPAddress.Loopback,
port,
fun sc ->
fun _ -> (RemoteServer sc).Content <- Shell.view
|> Dispatcher.UIThread.Post
)

let cts = new System.Threading.CancellationTokenSource()

let _ =
task {
let! t = transport.Connect(IPAddress.Loopback, port)

fun _ ->
let window = Window(Content = RemoteWidget t)
window.Closed |> Event.add (fun _ -> cts.Cancel())
window.Show()
|> Dispatcher.UIThread.Post
}

Dispatcher.UIThread.MainLoop cts.Token
0

module Program =
[<EntryPoint>]
let main (args: string []) =
AppBuilder.Configure<App>()
AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseSkia()
.StartWithClassicDesktopLifetime(args)
.StartWithClassicDesktopLifetime(args)

0 comments on commit 97a114f

Please sign in to comment.