mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[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:
@@ -31,15 +31,7 @@
|
|||||||
TextWrapping="Wrap" />
|
TextWrapping="Wrap" />
|
||||||
</HyperlinkButton>
|
</HyperlinkButton>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
|
<muxc:InfoBar
|
||||||
<Grid Margin="32,24,32,24">
|
|
||||||
<muxc:ProgressRing Grid.Row="1"
|
|
||||||
x:Name="LoadingProgressRing"
|
|
||||||
IsIndeterminate="True"
|
|
||||||
VerticalAlignment="Center"
|
|
||||||
HorizontalAlignment="Center"
|
|
||||||
Visibility="Visible"/>
|
|
||||||
<muxc:InfoBar
|
|
||||||
Severity="Error"
|
Severity="Error"
|
||||||
x:Name="ErrorInfoBar"
|
x:Name="ErrorInfoBar"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
@@ -49,9 +41,26 @@
|
|||||||
IsClosable="False"
|
IsClosable="False"
|
||||||
IsOpen="True"
|
IsOpen="True"
|
||||||
IsTabStop="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"
|
<toolkitcontrols:MarkdownTextBlock x:Name="ReleaseNotesMarkdown"
|
||||||
Visibility="Collapsed"
|
Visibility="Collapsed"
|
||||||
Grid.Row="1"
|
|
||||||
Header1FontSize="20"
|
Header1FontSize="20"
|
||||||
Header2FontSize="17"
|
Header2FontSize="17"
|
||||||
Header2FontWeight="SemiBold"
|
Header2FontWeight="SemiBold"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@@ -18,7 +19,6 @@ using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
|
|||||||
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
|
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Navigation;
|
using Microsoft.UI.Xaml.Navigation;
|
||||||
using Windows.UI.Core;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
|
namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
|
||||||
{
|
{
|
||||||
@@ -55,14 +55,21 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
|
|||||||
private static async Task<string> GetReleaseNotesMarkdown()
|
private static async Task<string> GetReleaseNotesMarkdown()
|
||||||
{
|
{
|
||||||
string releaseNotesJSON = string.Empty;
|
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);
|
IList<PowerToysReleaseInfo> releases = JsonSerializer.Deserialize<IList<PowerToysReleaseInfo>>(releaseNotesJSON);
|
||||||
|
|
||||||
// Get the latest releases
|
// Get the latest releases
|
||||||
@@ -83,23 +90,45 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
|
|||||||
return releaseNotesHtmlBuilder.ToString();
|
return releaseNotesHtmlBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Page_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
private async Task Reload()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string releaseNotesMarkdown = await GetReleaseNotesMarkdown();
|
string releaseNotesMarkdown = await GetReleaseNotesMarkdown();
|
||||||
|
|
||||||
|
ProxyWarningInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
|
||||||
|
ErrorInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
|
||||||
|
|
||||||
ReleaseNotesMarkdown.Text = releaseNotesMarkdown;
|
ReleaseNotesMarkdown.Text = releaseNotesMarkdown;
|
||||||
ReleaseNotesMarkdown.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
|
ReleaseNotesMarkdown.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
|
||||||
LoadingProgressRing.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError("Exception when loading the release notes", ex);
|
Logger.LogError("Exception when loading the release notes", ex);
|
||||||
|
|
||||||
LoadingProgressRing.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
|
|
||||||
ErrorInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
|
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/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -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">
|
<data name="Oobe_WhatsNew_LoadingError.Message" xml:space="preserve">
|
||||||
<value>Please check your internet connection.</value>
|
<value>Please check your internet connection.</value>
|
||||||
</data>
|
</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">
|
<data name="Oobe_WhatsNew_DetailedReleaseNotesLink.Text" xml:space="preserve">
|
||||||
<value>See more detailed release notes on GitHub</value>
|
<value>See more detailed release notes on GitHub</value>
|
||||||
<comment>Don't loc "GitHub", it's the name of a product</comment>
|
<comment>Don't loc "GitHub", it's the name of a product</comment>
|
||||||
|
|||||||
Reference in New Issue
Block a user