1- // Copyright (c) Microsoft Corporation
1+ // Copyright (c) Microsoft Corporation
22// The Microsoft Corporation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
55using System ;
66using System . Collections . Generic ;
77using System . ComponentModel ;
8- using System . Linq ;
9- using System . Net ;
10- using System . Net . Http ;
118using System . Text ;
12- using System . Text . Json ;
139using System . Text . RegularExpressions ;
14- using System . Threading . Tasks ;
15- using CommunityToolkit . WinUI . Controls ;
10+
1611using global ::PowerToys . GPOWrapper ;
1712using ManagedCommon ;
1813using Microsoft . PowerToys . Settings . UI . Helpers ;
1914using Microsoft . PowerToys . Settings . UI . Library ;
2015using Microsoft . PowerToys . Settings . UI . Library . HotkeyConflicts ;
21- using Microsoft . PowerToys . Settings . UI . Library . Interfaces ;
22- using Microsoft . PowerToys . Settings . UI . OOBE . Enums ;
2316using Microsoft . PowerToys . Settings . UI . OOBE . ViewModel ;
24- using Microsoft . PowerToys . Settings . UI . SerializationContext ;
2517using Microsoft . PowerToys . Settings . UI . Services ;
2618using Microsoft . PowerToys . Settings . UI . Views ;
2719using Microsoft . PowerToys . Telemetry ;
28- using Microsoft . UI . Text ;
2920using Microsoft . UI . Xaml ;
3021using Microsoft . UI . Xaml . Controls ;
31- using Microsoft . UI . Xaml . Media ;
3222using Microsoft . UI . Xaml . Navigation ;
3323
3424namespace Microsoft . PowerToys . Settings . UI . OOBE . Views
3525{
36- public sealed partial class OobeWhatsNew : Page , INotifyPropertyChanged
26+ public sealed partial class ScoobeReleaseNotesPage : Page , INotifyPropertyChanged
3727 {
3828 public OobePowerToysModule ViewModel { get ; set ; }
3929
@@ -43,6 +33,8 @@ public sealed partial class OobeWhatsNew : Page, INotifyPropertyChanged
4333
4434 private int _conflictCount ;
4535
36+ private IList < PowerToysReleaseInfo > _currentReleases ;
37+
4638 public AllHotkeyConflictsData AllHotkeyConflictsData
4739 {
4840 get => _allHotkeyConflictsData ;
@@ -98,13 +90,11 @@ private void UpdateConflictCount()
9890 public event PropertyChangedEventHandler PropertyChanged ;
9991
10092 /// <summary>
101- /// Initializes a new instance of the <see cref="OobeWhatsNew "/> class.
93+ /// Initializes a new instance of the <see cref="ScoobeReleaseNotesPage "/> class.
10294 /// </summary>
103- public OobeWhatsNew ( )
95+ public ScoobeReleaseNotesPage ( )
10496 {
10597 this . InitializeComponent ( ) ;
106- ViewModel = new OobePowerToysModule ( OobeShellPage . OobeShellHandler . Modules [ ( int ) PowerToysModules . WhatsNew ] ) ;
107- DataContext = this ;
10898
10999 // Subscribe to hotkey conflict updates
110100 if ( GlobalHotkeyConflictManager . Instance != null )
@@ -160,7 +150,7 @@ private bool GetShowDataDiagnosticsInfoBar()
160150
161151 bool registryValue = DataDiagnosticsSettings . GetEnabledValue ( ) ;
162152
163- bool isFirstRunAfterUpdate = ( App . Current as Microsoft . PowerToys . Settings . UI . App ) . ShowScoobe ;
153+ bool isFirstRunAfterUpdate = ( App . Current as App ) . ShowScoobe ;
164154 if ( isFirstRunAfterUpdate && registryValue == false )
165155 {
166156 return true ;
@@ -175,30 +165,13 @@ private bool GetShowDataDiagnosticsInfoBar()
175165 private const string RemoveInstallerHashesRegex = @"(\r\n)+## Installer Hashes(\r\n.*)+## Highlights" ;
176166 private const string RemoveHotFixInstallerHashesRegex = @"(\r\n)+## Installer Hashes(\r\n.*)+$" ;
177167 private const RegexOptions RemoveInstallerHashesRegexOptions = RegexOptions . Compiled | RegexOptions . IgnoreCase | RegexOptions . CultureInvariant ;
178- private bool _loadingReleaseNotes ;
179168
180- private static async Task < string > GetReleaseNotesMarkdown ( )
169+ private static string GetReleaseNotesMarkdown ( IList < PowerToysReleaseInfo > releases )
181170 {
182- string releaseNotesJSON = string . Empty ;
183-
184- // Let's use system proxy
185- using var proxyClientHandler = new HttpClientHandler
171+ if ( releases == null || releases . Count == 0 )
186172 {
187- DefaultProxyCredentials = CredentialCache . DefaultCredentials ,
188- Proxy = WebRequest . GetSystemWebProxy ( ) ,
189- PreAuthenticate = true ,
190- } ;
191-
192- using var getReleaseInfoClient = new HttpClient ( proxyClientHandler ) ;
193-
194- // GitHub APIs require sending an user agent
195- // https://docs.github.com/rest/overview/resources-in-the-rest-api#user-agent-required
196- getReleaseInfoClient . DefaultRequestHeaders . TryAddWithoutValidation ( "User-Agent" , "PowerToys" ) ;
197- releaseNotesJSON = await getReleaseInfoClient . GetStringAsync ( "https://api.github.com/repos/microsoft/PowerToys/releases" ) ;
198- IList < PowerToysReleaseInfo > releases = JsonSerializer . Deserialize < IList < PowerToysReleaseInfo > > ( releaseNotesJSON , SourceGenerationContextContext . Default . IListPowerToysReleaseInfo ) ;
199-
200- // Get the latest releases
201- var latestReleases = releases . OrderByDescending ( release => release . PublishedDate ) . Take ( 5 ) ;
173+ return string . Empty ;
174+ }
202175
203176 StringBuilder releaseNotesHtmlBuilder = new StringBuilder ( string . Empty ) ;
204177
@@ -207,14 +180,12 @@ private static async Task<string> GetReleaseNotesMarkdown()
207180
208181 // Regex to remove installer hash sections from the release notes, since there'll be no Highlights section for hotfix releases.
209182 Regex removeHotfixHashRegex = new Regex ( RemoveHotFixInstallerHashesRegex , RemoveInstallerHashesRegexOptions ) ;
183+
210184 int counter = 0 ;
211- foreach ( var release in latestReleases )
185+ foreach ( var release in releases )
212186 {
213187 releaseNotesHtmlBuilder . AppendLine ( "# " + release . Name ) ;
214188 var notes = removeHashRegex . Replace ( release . ReleaseNotes , "\r \n ### Highlights" ) ;
215-
216- // Add a unique counter to [github-current-release-work] to distinguish each release,
217- // since this variable is used for all latest releases when they are merged.
218189 notes = notes . Replace ( "[github-current-release-work]" , $ "[github-current-release-work{ ++ counter } ]") ;
219190 notes = removeHotfixHashRegex . Replace ( notes , string . Empty ) ;
220191 releaseNotesHtmlBuilder . AppendLine ( notes ) ;
@@ -224,58 +195,45 @@ private static async Task<string> GetReleaseNotesMarkdown()
224195 return releaseNotesHtmlBuilder . ToString ( ) ;
225196 }
226197
227- private async Task Reload ( )
198+ private void DisplayReleaseNotes ( )
228199 {
229- if ( _loadingReleaseNotes )
200+ if ( _currentReleases == null || _currentReleases . Count == 0 )
230201 {
202+ ReleaseNotesMarkdown . Visibility = Visibility . Collapsed ;
203+ ErrorInfoBar . IsOpen = true ;
231204 return ;
232205 }
233206
234207 try
235208 {
236- _loadingReleaseNotes = true ;
237- ReleaseNotesMarkdown . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
238- LoadingProgressRing . Visibility = Microsoft . UI . Xaml . Visibility . Visible ;
239- string releaseNotesMarkdown = await GetReleaseNotesMarkdown ( ) ;
209+ LoadingProgressRing . Visibility = Visibility . Collapsed ;
240210 ProxyWarningInfoBar . IsOpen = false ;
241211 ErrorInfoBar . IsOpen = false ;
242212
213+ string releaseNotesMarkdown = GetReleaseNotesMarkdown ( _currentReleases ) ;
243214 ReleaseNotesMarkdown . Text = releaseNotesMarkdown ;
244- ReleaseNotesMarkdown . Visibility = Microsoft . UI . Xaml . Visibility . Visible ;
245- LoadingProgressRing . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
246- }
247- catch ( HttpRequestException httpEx )
248- {
249- Logger . LogError ( "Exception when loading the release notes" , httpEx ) ;
250- if ( httpEx . Message . Contains ( "407" , StringComparison . CurrentCulture ) )
251- {
252- ProxyWarningInfoBar . IsOpen = true ;
253- }
254- else
255- {
256- ErrorInfoBar . IsOpen = true ;
257- }
215+ ReleaseNotesMarkdown . Visibility = Visibility . Visible ;
258216 }
259217 catch ( Exception ex )
260218 {
261- Logger . LogError ( "Exception when loading the release notes" , ex ) ;
219+ Logger . LogError ( "Exception when displaying the release notes" , ex ) ;
262220 ErrorInfoBar . IsOpen = true ;
263221 }
264- finally
265- {
266- LoadingProgressRing . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
267- _loadingReleaseNotes = false ;
268- }
269222 }
270223
271- private async void Page_Loaded ( object sender , Microsoft . UI . Xaml . RoutedEventArgs e )
224+ private void Page_Loaded ( object sender , RoutedEventArgs e )
272225 {
273- await Reload ( ) ;
226+ DisplayReleaseNotes ( ) ;
274227 }
275228
276229 /// <inheritdoc/>
277230 protected override void OnNavigatedTo ( NavigationEventArgs e )
278231 {
232+ if ( e . Parameter is IList < PowerToysReleaseInfo > releases )
233+ {
234+ _currentReleases = releases ;
235+ }
236+
279237 ViewModel . LogOpeningModuleEvent ( ) ;
280238 }
281239
@@ -291,7 +249,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
291249 }
292250 }
293251
294- private void DataDiagnostics_InfoBar_YesNo_Click ( object sender , Microsoft . UI . Xaml . RoutedEventArgs e )
252+ private void DataDiagnostics_InfoBar_YesNo_Click ( object sender , RoutedEventArgs e )
295253 {
296254 string commandArg = string . Empty ;
297255 if ( sender is Button senderBtn )
@@ -318,10 +276,10 @@ private void DataDiagnostics_InfoBar_YesNo_Click(object sender, Microsoft.UI.Xam
318276 WhatsNewDataDiagnosticsInfoBar . Header = ResourceLoaderInstance . ResourceLoader . GetString ( "Oobe_WhatsNew_DataDiagnostics_No_Click_InfoBar_Title" ) ;
319277 }
320278
321- WhatsNewDataDiagnosticsInfoBarDescText . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
322- WhatsNewDataDiagnosticsInfoBarDescTextYesClicked . Visibility = Microsoft . UI . Xaml . Visibility . Visible ;
323- DataDiagnosticsButtonYes . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
324- DataDiagnosticsButtonNo . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
279+ WhatsNewDataDiagnosticsInfoBarDescText . Visibility = Visibility . Collapsed ;
280+ WhatsNewDataDiagnosticsInfoBarDescTextYesClicked . Visibility = Visibility . Visible ;
281+ DataDiagnosticsButtonYes . Visibility = Visibility . Collapsed ;
282+ DataDiagnosticsButtonNo . Visibility = Visibility . Collapsed ;
325283
326284 // Set Data Diagnostics registry values
327285 if ( commandArg == "Yes" )
@@ -341,19 +299,19 @@ private void DataDiagnostics_InfoBar_YesNo_Click(object sender, Microsoft.UI.Xam
341299 } ) ;
342300 }
343301
344- private void DataDiagnostics_InfoBar_Close_Click ( object sender , Microsoft . UI . Xaml . RoutedEventArgs e )
302+ private void DataDiagnostics_InfoBar_Close_Click ( object sender , RoutedEventArgs e )
345303 {
346- WhatsNewDataDiagnosticsInfoBar . Visibility = Microsoft . UI . Xaml . Visibility . Collapsed ;
304+ WhatsNewDataDiagnosticsInfoBar . Visibility = Visibility . Collapsed ;
347305 }
348306
349307 private void DataDiagnostics_OpenSettings_Click ( Microsoft . UI . Xaml . Documents . Hyperlink sender , Microsoft . UI . Xaml . Documents . HyperlinkClickEventArgs args )
350308 {
351309 Common . UI . SettingsDeepLink . OpenSettings ( Common . UI . SettingsDeepLink . SettingsWindow . Overview ) ;
352310 }
353311
354- private async void LoadReleaseNotes_Click ( object sender , Microsoft . UI . Xaml . RoutedEventArgs e )
312+ private void LoadReleaseNotes_Click ( object sender , RoutedEventArgs e )
355313 {
356- await Reload ( ) ;
314+ DisplayReleaseNotes ( ) ;
357315 }
358316 }
359317}
0 commit comments