77using System . Windows ;
88using System . Windows . Threading ;
99using BlazorDesktop . Wpf ;
10- using WebView2 . Runtime . AutoInstaller ;
1110
1211namespace BlazorDesktop . Services ;
1312
@@ -16,29 +15,10 @@ namespace BlazorDesktop.Services;
1615/// </summary>
1716public partial class BlazorDesktopService : IHostedService , IDisposable
1817{
19- /// <summary>
20- /// The cancellation token registration.
21- /// </summary>
2218 private CancellationTokenRegistration _applicationStoppingRegistration ;
23-
24- /// <summary>
25- /// The application lifetime.
26- /// </summary>
2719 private readonly IHostApplicationLifetime _lifetime ;
28-
29- /// <summary>
30- /// The services.
31- /// </summary>
3220 private readonly IServiceProvider _services ;
33-
34- /// <summary>
35- /// The <see cref="ILogger{TCategoryName}"/>.
36- /// </summary>
3721 private readonly ILogger < BlazorDesktopService > _logger ;
38-
39- /// <summary>
40- /// The web view installer.
41- /// </summary>
4222 private readonly WebViewInstaller _webViewInstaller ;
4323
4424 /// <summary>
@@ -66,10 +46,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
6646 {
6747 _applicationStoppingRegistration = _lifetime . ApplicationStopping . Register ( OnApplicationStopping ) ;
6848
69- if ( _webViewInstaller . Enabled )
70- {
71- await WebView2AutoInstaller . CheckAndInstallAsync ( silentInstall : _webViewInstaller . SilentInstall , cancellationToken : cancellationToken ) ;
72- }
49+ await _webViewInstaller . EnsureInstalledAsync ( cancellationToken ) ;
7350
7451 var thread = new Thread ( ApplicationThread ) ;
7552 thread . SetApartmentState ( ApartmentState . STA ) ;
@@ -86,18 +63,9 @@ public Task StopAsync(CancellationToken cancellationToken)
8663 return Task . CompletedTask ;
8764 }
8865
89- /// <summary>
90- /// Logs an unhanded component exception,
91- /// </summary>
92- /// <param name="logger">The <see cref="ILogger"/>.</param>
93- /// <param name="message">The message.</param>
94- /// <param name="exception">The <see cref="Exception"/>.</param>
9566 [ LoggerMessage ( 0 , LogLevel . Critical , "Unhandled exception rendering component: {Message}" , EventName = "ExceptionRenderingComponent" ) ]
9667 private static partial void LogUnhandledExceptionRenderingComponent ( ILogger logger , string message , Exception exception ) ;
9768
98- /// <summary>
99- /// The application thread.
100- /// </summary>
10169 private void ApplicationThread ( )
10270 {
10371 var app = _services . GetRequiredService < Application > ( ) ;
@@ -116,11 +84,6 @@ private void ApplicationThread()
11684 app . Startup -= OnApplicationStartup ;
11785 }
11886
119- /// <summary>
120- /// Occurs when the application is starting up.
121- /// </summary>
122- /// <param name="sender">The sending object.</param>
123- /// <param name="e">The arguments.</param>
12487 private void OnApplicationStartup ( object sender , StartupEventArgs e )
12588 {
12689 var app = _services . GetRequiredService < Application > ( ) ;
@@ -130,21 +93,11 @@ private void OnApplicationStartup(object sender, StartupEventArgs e)
13093 app . MainWindow . Show ( ) ;
13194 }
13295
133- /// <summary>
134- /// Occurs when the application exits.
135- /// </summary>
136- /// <param name="sender">The sending object.</param>
137- /// <param name="e">The arguments.</param>
13896 private void OnApplicationExit ( object ? sender , ExitEventArgs e )
13997 {
14098 _lifetime . StopApplication ( ) ;
14199 }
142100
143- /// <summary>
144- /// Occurs when the application throws an exception.
145- /// </summary>
146- /// <param name="sender">The sending object.</param>
147- /// <param name="e">The arguments.</param>
148101 private void OnApplicationException ( object sender , DispatcherUnhandledExceptionEventArgs e )
149102 {
150103 if ( e . Exception is TargetInvocationException && e . Exception . InnerException is not null )
@@ -159,9 +112,6 @@ private void OnApplicationException(object sender, DispatcherUnhandledExceptionE
159112 e . Handled = true ;
160113 }
161114
162- /// <summary>
163- /// Occurs when the application is stopping.
164- /// </summary>
165115 private void OnApplicationStopping ( )
166116 {
167117 var app = _services . GetRequiredService < Application > ( ) ;
0 commit comments