3
3
using System . Threading . Tasks ;
4
4
using Avalonia ;
5
5
using Avalonia . Controls ;
6
- using Avalonia . Controls . ApplicationLifetimes ;
7
6
using Avalonia . Threading ;
8
7
using GitCredentialManager . Interop . Windows . Native ;
9
8
using GitCredentialManager . UI . Controls ;
@@ -15,6 +14,24 @@ namespace GitCredentialManager.UI
15
14
public static class AvaloniaUi
16
15
{
17
16
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
+ }
18
35
19
36
public static Task ShowViewAsync ( Func < Control > viewFunc , WindowViewModel viewModel , IntPtr parentHandle , CancellationToken ct ) =>
20
37
ShowWindowAsync ( ( ) => new DialogWindow ( viewFunc ( ) ) , viewModel , parentHandle , ct ) ;
@@ -46,22 +63,25 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
46
63
// This action only returns on our dispatcher shutdown.
47
64
Dispatcher . MainThread . Post ( appCancelToken =>
48
65
{
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
50
78
#if NETFRAMEWORK
51
79
. UseWin32 ( )
52
80
. UseSkia ( )
53
81
#else
54
82
. UsePlatformDetect ( )
55
83
#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 ( ) ;
65
85
66
86
appInitialized . Set ( ) ;
67
87
0 commit comments