[OOBE] Get "What's New" behind authenticated proxy and strict firewall. (#18695)

* Attempt to get username and password for proxy authentication. We should not use it.

* Using default credentials for system proxy authentication.
This commit is contained in:
lncubus
2022-06-14 12:44:07 +02:00
committed by GitHub
parent b5531a1f6b
commit e8bb2de8b6
3 changed files with 65 additions and 21 deletions

View File

@@ -31,15 +31,7 @@
TextWrapping="Wrap" />
</HyperlinkButton>
</StackPanel>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<Grid Margin="32,24,32,24">
<muxc:ProgressRing Grid.Row="1"
x:Name="LoadingProgressRing"
IsIndeterminate="True"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Visibility="Visible"/>
<muxc:InfoBar
<muxc:InfoBar
Severity="Error"
x:Name="ErrorInfoBar"
Grid.Row="1"
@@ -49,9 +41,26 @@
IsClosable="False"
IsOpen="True"
IsTabStop="True" />
<muxc:InfoBar
x:Name="ProxyWarningInfoBar"
Severity="Warning"
Grid.Row="1"
Visibility="Collapsed"
x:Uid="Oobe_WhatsNew_ProxyAuthenticationWarning"
VerticalAlignment="Top"
IsClosable="False"
IsOpen="True"
IsTabStop="True" />
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<Grid Margin="32,24,32,24">
<muxc:ProgressRing
x:Name="LoadingProgressRing"
IsIndeterminate="True"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Visibility="Visible"/>
<toolkitcontrols:MarkdownTextBlock x:Name="ReleaseNotesMarkdown"
Visibility="Collapsed"
Grid.Row="1"
Header1FontSize="20"
Header2FontSize="17"
Header2FontWeight="SemiBold"

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.Json;
@@ -18,7 +19,6 @@ using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Windows.UI.Core;
namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
{
@@ -55,14 +55,21 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
private static async Task<string> GetReleaseNotesMarkdown()
{
string releaseNotesJSON = string.Empty;
using (HttpClient getReleaseInfoClient = new HttpClient())
{
// GitHub APIs require sending an user agent
// https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required
getReleaseInfoClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "PowerToys");
releaseNotesJSON = await getReleaseInfoClient.GetStringAsync("https://api.github.com/repos/microsoft/PowerToys/releases");
}
// Let's use system proxy
using var proxyClientHandler = new HttpClientHandler
{
DefaultProxyCredentials = CredentialCache.DefaultCredentials,
Proxy = WebRequest.GetSystemWebProxy(),
PreAuthenticate = true,
};
using var getReleaseInfoClient = new HttpClient(proxyClientHandler);
// GitHub APIs require sending an user agent
// https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required
getReleaseInfoClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "PowerToys");
releaseNotesJSON = await getReleaseInfoClient.GetStringAsync("https://api.github.com/repos/microsoft/PowerToys/releases");
IList<PowerToysReleaseInfo> releases = JsonSerializer.Deserialize<IList<PowerToysReleaseInfo>>(releaseNotesJSON);
// Get the latest releases
@@ -83,23 +90,45 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
return releaseNotesHtmlBuilder.ToString();
}
private async void Page_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
private async Task Reload()
{
try
{
string releaseNotesMarkdown = await GetReleaseNotesMarkdown();
ProxyWarningInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
ErrorInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
ReleaseNotesMarkdown.Text = releaseNotesMarkdown;
ReleaseNotesMarkdown.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
LoadingProgressRing.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
}
catch (HttpRequestException httpEx)
{
Logger.LogError("Exception when loading the release notes", httpEx);
if (httpEx.Message.Contains("407", StringComparison.CurrentCulture))
{
ProxyWarningInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
}
else
{
ErrorInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
}
}
catch (Exception ex)
{
Logger.LogError("Exception when loading the release notes", ex);
LoadingProgressRing.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
ErrorInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
}
finally
{
LoadingProgressRing.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
}
}
private async void Page_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
await Reload();
}
/// <inheritdoc/>

View File

@@ -1488,6 +1488,12 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="Oobe_WhatsNew_LoadingError.Message" xml:space="preserve">
<value>Please check your internet connection.</value>
</data>
<data name="Oobe_WhatsNew_ProxyAuthenticationWarning.Title" xml:space="preserve">
<value>Couldn't load the release notes.</value>
</data>
<data name="Oobe_WhatsNew_ProxyAuthenticationWarning.Message" xml:space="preserve">
<value>Your proxy server requires authentication.</value>
</data>
<data name="Oobe_WhatsNew_DetailedReleaseNotesLink.Text" xml:space="preserve">
<value>See more detailed release notes on GitHub</value>
<comment>Don't loc "GitHub", it's the name of a product</comment>