diff --git a/Program.fs b/Program.fs index cea4a80..7e32652 100644 --- a/Program.fs +++ b/Program.fs @@ -56,6 +56,7 @@ type MsgPackResolver() = s_resolver.GetFormatter<'a>() let startMainWindow app serveropts = + let app = app() Model.Start serveropts let cfg = config.load() @@ -81,6 +82,7 @@ let startMainWindow app serveropts = 0 let startCrashReportWindow app ex = + let app = app() FVim.log.trace "main" "displaying crash dialog" FVim.log.trace "main" "exception: %O" ex let code, msgs = States.get_crash_info() @@ -115,18 +117,19 @@ let main(args: string[]) = ) System.Console.OutputEncoding <- System.Text.Encoding.Unicode - // Avalonia initialization let builder = lazy buildAvaloniaApp() let lifetime = lazy new ClassicDesktopStyleApplicationLifetime() - let app = + let app () = + // Avalonia initialization + let lifetime = lifetime.Value + if not builder.IsValueCreated then + let _ = builder.Value.SetupWithLifetime(lifetime) + () + // Avalonia is initialized. SynchronizationContext-reliant code should be working by now; (fun (win: Avalonia.Controls.Window) -> - let lifetime = lifetime.Value - let builder = builder.Value - let _ = builder.SetupWithLifetime(lifetime) lifetime.ShutdownMode <- Controls.ShutdownMode.OnMainWindowClose lifetime.MainWindow <- win lifetime.Start(args) |> ignore) - // Avalonia is initialized. SynchronizationContext-reliant code should be working by now; try let opts = parseOptions args diff --git a/states.fs b/states.fs index 28bd47c..3953948 100644 --- a/states.fs +++ b/states.fs @@ -34,7 +34,7 @@ type Event = | Exit let private _stateChangeEvent = Event() -let private _appLifetime = Avalonia.Application.Current.ApplicationLifetime :?> Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime +let private _appLifetime = lazy(Avalonia.Application.Current.ApplicationLifetime :?> Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime) let mutable private _crashcode = 0 let private _errormsgs = ResizeArray() @@ -245,7 +245,7 @@ let backgroundCompositionToString = | Acrylic -> "acrylic" | Transparent -> "transparent" -let Shutdown code = _appLifetime.Shutdown code +let Shutdown code = _appLifetime.Value.Shutdown code let get_crash_info() = _crashcode, _errormsgs @@ -273,7 +273,7 @@ let msg_dispatch = _errormsgs.Add err | Exit -> trace "rpc" "shutting down application lifetime" - _appLifetime.Shutdown() + _appLifetime.Value.Shutdown() | Crash code -> trace "rpc" "neovim crashed with code %d" code _crashcode <- code