Skip to content

Commit

Permalink
Drop support for WebView for WPF and Winforms and default to WebView2 (
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck authored Dec 5, 2023
1 parent f487255 commit bb4b1da
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 38 deletions.
4 changes: 2 additions & 2 deletions nuget/Auth0.OidcClient.WPF.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@
<dependencies>
<group targetFramework="net462">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
<dependency id="Microsoft.Toolkit.Wpf.UI.Controls.WebView" version="6.1.1"/>
<dependency id="Microsoft.Web.WebView2" version="1.0.1823.32"/>
</group>
<group targetFramework="netcoreapp3.1">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
<dependency id="Microsoft.Toolkit.Wpf.UI.Controls.WebView" version="6.1.1"/>
<dependency id="Microsoft.Web.WebView2" version="1.0.1823.32"/>
</group>
<group targetFramework="net6.0-windows7.0">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
Expand Down
4 changes: 2 additions & 2 deletions nuget/Auth0.OidcClient.WinForms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
<dependencies>
<group targetFramework="net462">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
<dependency id="Microsoft.Toolkit.Forms.UI.Controls.WebView" version="6.1.1"/>
<dependency id="Microsoft.Web.WebView2" version="1.0.1823.32"/>
</group>
<group targetFramework="netcoreapp3.1">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
<dependency id="Microsoft.Toolkit.Forms.UI.Controls.WebView" version="6.1.1"/>
<dependency id="Microsoft.Web.WebView2" version="1.0.1823.32"/>
</group>
<group targetFramework="net6.0-windows7.0">
<dependency id="Auth0.OidcClient.Core" version="3.4.1" />
Expand Down
4 changes: 1 addition & 3 deletions src/Auth0.OidcClient.WPF/Auth0.OidcClient.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
<When Condition="'$(TargetFramework)'!='net6.0-windows'">
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.Controls.WebView">
<Version>6.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1823.32" />
</ItemGroup>
</When>
<When Condition="'$(TargetFramework)'=='net6.0-windows'">
Expand Down
16 changes: 2 additions & 14 deletions src/Auth0.OidcClient.WPF/WebViewBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using IdentityModel.OidcClient.Browser;
#if NET6_0
using WebViewCompatible = Microsoft.Web.WebView2.Wpf.WebView2;
#else
using Microsoft.Toolkit.Wpf.UI.Controls;
#endif
using Microsoft.Web.WebView2.Wpf;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -54,16 +50,12 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio

var window = _windowFactory();
#pragma warning disable 618
var webView = new WebViewCompatible();
var webView = new WebView2();
window.Content = webView;

webView.NavigationStarting += (sender, e) =>
{
#if NET6_0
if (e.Uri.StartsWith(options.EndUrl))
#else
if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl))
#endif
{
tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.Success, Response = e.Uri.ToString() });
if (_shouldCloseWindow)
Expand All @@ -82,12 +74,8 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio

window.Show();

#if NET6_0
await webView.EnsureCoreWebView2Async();
webView.CoreWebView2.Navigate(options.StartUrl);
#else
webView.Navigate(options.StartUrl);
#endif

return await tcs.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
<When Condition="'$(TargetFramework)'!='net6.0-windows'">
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Toolkit.Forms.UI.Controls.WebView">
<Version>6.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1823.32" />
</ItemGroup>
</When>
<When Condition="'$(TargetFramework)'=='net6.0-windows'">
Expand Down
16 changes: 2 additions & 14 deletions src/Auth0.OidcClient.WinForms/WebViewBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using IdentityModel.OidcClient.Browser;
#if NET6_0
using WebViewCompatible = Microsoft.Web.WebView2.WinForms.WebView2;
#else
using Microsoft.Toolkit.Forms.UI.Controls;
#endif
using Microsoft.Web.WebView2.WinForms;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -52,15 +48,11 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio

var window = _formFactory();
#pragma warning disable 618
var webView = new WebViewCompatible { Dock = DockStyle.Fill };
var webView = new WebView2 { Dock = DockStyle.Fill };

webView.NavigationStarting += (sender, e) =>
{
#if NET6_0
if (e.Uri.StartsWith(options.EndUrl))
#else
if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl))
#endif
{
tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.Success, Response = e.Uri.ToString() });
window.Close();
Expand All @@ -77,12 +69,8 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio

window.Show();

#if NET6_0
await webView.EnsureCoreWebView2Async();
webView.CoreWebView2.Navigate(options.StartUrl);
#else
webView.Navigate(options.StartUrl);
#endif

return await tcs.Task;
}
Expand Down

0 comments on commit bb4b1da

Please sign in to comment.