Skip to content

Commit 10e6d91

Browse files
chore: opinionated webview install
1 parent dcb8d9c commit 10e6d91

10 files changed

+78
-224
lines changed

src/BlazorDesktop/BlazorDesktop.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="8.0.61" />
14-
<PackageReference Include="WebView2.Runtime.AutoInstaller" Version="1.0.0" />
1514
</ItemGroup>
1615

1716
</Project>

src/BlazorDesktop/Hosting/BlazorDesktopHost.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@ public sealed class BlazorDesktopHost : IHost, IAsyncDisposable
2020
/// </summary>
2121
public IServiceProvider Services => _host.Services;
2222

23-
/// <summary>
24-
/// The host.
25-
/// </summary>
2623
private readonly IHost _host;
2724

28-
/// <summary>
29-
/// Creates an instance of <see cref="BlazorDesktopHost"/> with a specified <see cref="IHost"/>.
30-
/// </summary>
31-
/// <param name="host">The <see cref="IHost"/> instance.</param>
3225
internal BlazorDesktopHost(IHost host)
3326
{
3427
_host = host;

src/BlazorDesktop/Hosting/BlazorDesktopHostBuilder.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,8 @@ public sealed class BlazorDesktopHostBuilder
4444
/// </summary>
4545
public ConfigureWindowBuilder Window { get; }
4646

47-
/// <summary>
48-
/// The host application builder.
49-
/// </summary>
5047
private readonly HostApplicationBuilder _hostApplicationBuilder;
5148

52-
/// <summary>
53-
/// Creates an instance of <see cref="BlazorDesktopHostBuilder"/> with the minimal configuration.
54-
/// </summary>
55-
/// <param name="args">The arguments passed to the application's main method.</param>
5649
private BlazorDesktopHostBuilder(string[]? args)
5750
{
5851
_hostApplicationBuilder = InitializeHostApplicationBuilder(args);
@@ -111,11 +104,6 @@ public BlazorDesktopHost Build()
111104
return new(_hostApplicationBuilder.Build());
112105
}
113106

114-
/// <summary>
115-
/// Initializes the host application builder.
116-
/// </summary>
117-
/// <param name="args">The arguments passed to the application's main method.</param>
118-
/// <returns>A <see cref="HostApplicationBuilder"/>.</returns>
119107
private static HostApplicationBuilder InitializeHostApplicationBuilder(string[]? args)
120108
{
121109
var configuration = new ConfigurationManager();
@@ -129,22 +117,16 @@ private static HostApplicationBuilder InitializeHostApplicationBuilder(string[]?
129117
});
130118
}
131119

132-
/// <summary>
133-
/// Initializes the default services.
134-
/// </summary>
135120
private void InitializeDefaultServices()
136121
{
122+
Services.AddHttpClient();
137123
Services.AddWpfBlazorWebView();
138124
Services.AddSingleton<WebViewInstaller>();
139125
Services.AddSingleton<Application>();
140126
Services.AddSingleton<Window, BlazorDesktopWindow>();
141127
Services.AddHostedService<BlazorDesktopService>();
142128
}
143129

144-
/// <summary>
145-
/// Initializes the root components.
146-
/// </summary>
147-
/// <returns>A <see cref="RootComponentMappingCollection"/>.</returns>
148130
private RootComponentMappingCollection InitializeRootComponents()
149131
{
150132
var rootComponents = new RootComponentMappingCollection();
@@ -154,10 +136,6 @@ private RootComponentMappingCollection InitializeRootComponents()
154136
return rootComponents;
155137
}
156138

157-
/// <summary>
158-
/// Initializes the environment.
159-
/// </summary>
160-
/// <returns>A <see cref="BlazorDesktopHostEnvironment"/>.</returns>
161139
private BlazorDesktopHostEnvironment InitializeEnvironment()
162140
{
163141
var hostEnvironment = new BlazorDesktopHostEnvironment(_hostApplicationBuilder.Environment, Configuration);
@@ -167,10 +145,6 @@ private BlazorDesktopHostEnvironment InitializeEnvironment()
167145
return hostEnvironment;
168146
}
169147

170-
/// <summary>
171-
/// Initializes the window builder.
172-
/// </summary>
173-
/// <returns>A <see cref="ConfigureWindowBuilder"/>.</returns>
174148
private ConfigureWindowBuilder InitializeWindowBuilder()
175149
{
176150
return new ConfigureWindowBuilder(Configuration);

src/BlazorDesktop/Hosting/BlazorDesktopHostBuilderExtensions.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,13 @@
22
// The Blazor Desktop Contributors licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using BlazorDesktop.Wpf;
6-
75
namespace BlazorDesktop.Hosting;
86

97
/// <summary>
108
/// Extension methods for configuring the <see cref="BlazorDesktopHostBuilder" />.
119
/// </summary>
1210
public static class BlazorDesktopHostBuilderExtensions
1311
{
14-
/// <summary>
15-
/// Installs a web view on the machine.
16-
/// </summary>
17-
/// <param name="builder">The <see cref="BlazorDesktopHostBuilder"/>.</param>
18-
/// <param name="useInstaller">If the installer should be used.</param>
19-
/// <param name="silentInstall">If the installer should be silent.</param>
20-
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
21-
public static BlazorDesktopHostBuilder UseWebViewInstaller(this BlazorDesktopHostBuilder builder, bool useInstaller = true, bool silentInstall = false)
22-
{
23-
builder.Services.AddSingleton(new WebViewInstaller { Enabled = useInstaller, SilentInstall = silentInstall });
24-
25-
return builder;
26-
}
27-
2812
/// <summary>
2913
/// Adds chromium dev tools to the application.
3014
/// </summary>

src/BlazorDesktop/Hosting/BlazorDesktopHostEnvironment.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ public IFileProvider ContentRootFileProvider
5858
/// </summary>
5959
public IFileProvider WebRootFileProvider { get; set; }
6060

61-
/// <summary>
62-
/// The host environment.
63-
/// </summary>
6461
private readonly IHostEnvironment _hostEnvironment;
6562

6663
/// <summary>

src/BlazorDesktop/Hosting/ConfigureWindowBuilder.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ namespace BlazorDesktop.Hosting;
99
/// </summary>
1010
public class ConfigureWindowBuilder
1111
{
12-
/// <summary>
13-
/// The configuration.
14-
/// </summary>
1512
private readonly IConfiguration _configuration;
1613

17-
/// <summary>
18-
/// Creates a instance of <see cref="ConfigureWindowBuilder"/>.
19-
/// </summary>
20-
/// <param name="configuration">The configuration.</param>
2114
internal ConfigureWindowBuilder(IConfiguration configuration)
2215
{
2316
_configuration = configuration;

src/BlazorDesktop/Services/BlazorDesktopService.cs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Windows;
88
using System.Windows.Threading;
99
using BlazorDesktop.Wpf;
10-
using WebView2.Runtime.AutoInstaller;
1110

1211
namespace BlazorDesktop.Services;
1312

@@ -16,29 +15,10 @@ namespace BlazorDesktop.Services;
1615
/// </summary>
1716
public 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>();

src/BlazorDesktop/Wpf/BlazorDesktopEventForwarder.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@ namespace BlazorDesktop.Wpf;
1111
/// </summary>
1212
public partial class BlazorDesktopEventForwarder
1313
{
14-
/// <summary>
15-
/// Posted when the user presses the left mouse button while the cursor is
16-
/// within the nonclient area of a window.
17-
/// </summary>
1814
private const int WM_NCLBUTTONDOWN = 0x00A1;
19-
20-
/// <summary>
21-
/// In a title bar.
22-
/// </summary>
2315
private const int HTCAPTION = 2;
2416

25-
/// <summary>
26-
/// The target
27-
/// </summary>
2817
private readonly IntPtr _target;
2918

3019
/// <summary>
@@ -45,21 +34,9 @@ public void MouseDownDrag()
4534
SendMessage(_target, WM_NCLBUTTONDOWN, HTCAPTION, 0);
4635
}
4736

48-
/// <summary>
49-
/// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
50-
/// </summary>
51-
/// <param name="hWnd">A handle to the window whose window procedure will receive the message.</param>
52-
/// <param name="msg">The message to be sent.</param>
53-
/// <param name="wParam">Additional message-specific information.</param>
54-
/// <param name="lParam">Additional message-specific information.</param>
55-
/// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
5637
[LibraryImport("User32", EntryPoint = "SendMessageW", SetLastError = true)]
5738
internal static partial nint SendMessage(IntPtr hWnd, uint msg, uint wParam, nint lParam);
5839

59-
/// <summary>
60-
/// Releases the mouse capture from a window in the current thread and restores normal mouse input processing.
61-
/// </summary>
62-
/// <returns>If the function succeeds, the return value is true. If the function fails, the return value is false.</returns>
6340
[LibraryImport("User32", SetLastError = true)]
6441
[return: MarshalAs(UnmanagedType.Bool)]
6542
internal static partial bool ReleaseCapture();

0 commit comments

Comments
 (0)