33using System . Threading . Tasks ;
44using Avalonia ;
55using Avalonia . Controls ;
6- using Avalonia . Controls . ApplicationLifetimes ;
76using Avalonia . Threading ;
87using GitCredentialManager . Interop . Windows . Native ;
98using GitCredentialManager . UI . Controls ;
@@ -15,6 +14,24 @@ namespace GitCredentialManager.UI
1514 public static class AvaloniaUi
1615 {
1716 private static bool _isAppStarted ;
17+ private static bool _win32SoftwareRendering ;
18+
19+ /// <summary>
20+ /// Configure the Avalonia application.
21+ /// </summary>
22+ /// <param name="win32SoftwareRendering">True to enable software rendering on Windows, false otherwise.</param>
23+ /// <remarks>
24+ /// This must be invoked before the Avalonia application loop has started.
25+ /// </remarks>
26+ public static void Initialize ( bool win32SoftwareRendering )
27+ {
28+ if ( _isAppStarted )
29+ {
30+ throw new InvalidOperationException ( "Setup must be called before the Avalonia application is started." ) ;
31+ }
32+
33+ _win32SoftwareRendering = win32SoftwareRendering ;
34+ }
1835
1936 public static Task ShowViewAsync ( Func < Control > viewFunc , WindowViewModel viewModel , IntPtr parentHandle , CancellationToken ct ) =>
2037 ShowWindowAsync ( ( ) => new DialogWindow ( viewFunc ( ) ) , viewModel , parentHandle , ct ) ;
@@ -46,22 +63,25 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
4663 // This action only returns on our dispatcher shutdown.
4764 Dispatcher . MainThread . Post ( appCancelToken =>
4865 {
49- AppBuilder . Configure < AvaloniaApp > ( )
66+ var appBuilder = AppBuilder . Configure < AvaloniaApp > ( ) ;
67+
68+ #if NETFRAMEWORK
69+ // Set custom rendering options and modes if required
70+ if ( PlatformUtils . IsWindows ( ) && _win32SoftwareRendering )
71+ {
72+ appBuilder . With ( new Win32PlatformOptions
73+ { RenderingMode = new [ ] { Win32RenderingMode . Software } } ) ;
74+ }
75+ #endif
76+
77+ appBuilder
5078#if NETFRAMEWORK
5179 . UseWin32 ( )
5280 . UseSkia ( )
5381#else
5482 . UsePlatformDetect ( )
5583#endif
56- . LogToTrace ( )
57- // Workaround https://github.com/AvaloniaUI/Avalonia/issues/10296
58- // by always setting a application lifetime.
59- . SetupWithLifetime (
60- new ClassicDesktopStyleApplicationLifetime
61- {
62- ShutdownMode = ShutdownMode . OnExplicitShutdown
63- }
64- ) ;
84+ . LogToTrace ( ) ;
6585
6686 appInitialized . Set ( ) ;
6787
0 commit comments