Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2698cfc

Browse files
committed
Creating a separate Window for release notes
1 parent 673cd5a commit 2698cfc

File tree

12 files changed

+624
-106
lines changed

12 files changed

+624
-106
lines changed

src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ private void OnLaunchedFromRunner(string[] cmdArgs)
272272
else if (ShowScoobe)
273273
{
274274
PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
275-
OobeWindow scoobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.WhatsNew);
276-
scoobeWindow.Activate();
277-
scoobeWindow.ExtendsContentIntoTitleBar = true;
275+
ScoobeWindow newScoobeWindow = new ScoobeWindow();
276+
newScoobeWindow.Activate();
277+
newScoobeWindow.ExtendsContentIntoTitleBar = true;
278278
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(settingsWindow));
279-
SetOobeWindow(scoobeWindow);
279+
SetScoobeWindow(newScoobeWindow);
280280
}
281281
else if (ShowFlyout)
282282
{
@@ -364,6 +364,7 @@ public static int UpdateUIThemeMethod(string themeName)
364364

365365
private static MainWindow settingsWindow;
366366
private static OobeWindow oobeWindow;
367+
private static ScoobeWindow scoobeWindow;
367368
private static FlyoutWindow flyoutWindow;
368369

369370
public static void ClearSettingsWindow()
@@ -401,6 +402,21 @@ public static void ClearOobeWindow()
401402
oobeWindow = null;
402403
}
403404

405+
public static ScoobeWindow GetScoobeWindow()
406+
{
407+
return scoobeWindow;
408+
}
409+
410+
public static void SetScoobeWindow(ScoobeWindow window)
411+
{
412+
scoobeWindow = window;
413+
}
414+
415+
public static void ClearScoobeWindow()
416+
{
417+
scoobeWindow = null;
418+
}
419+
404420
public static void ClearFlyoutWindow()
405421
{
406422
flyoutWindow = null;

src/settings-ui/Settings.UI/SettingsXAML/MainWindow.xaml.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,12 @@ public MainWindow(bool createHidden = false)
113113
// open whats new window
114114
ShellPage.SetOpenWhatIsNewCallback(() =>
115115
{
116-
if (App.GetOobeWindow() == null)
117-
{
118-
App.SetOobeWindow(new OobeWindow(OOBE.Enums.PowerToysModules.WhatsNew));
119-
}
120-
else
116+
if (App.GetScoobeWindow() == null)
121117
{
122-
App.GetOobeWindow().SetAppWindow(OOBE.Enums.PowerToysModules.WhatsNew);
118+
App.SetScoobeWindow(new ScoobeWindow());
123119
}
124120

125-
App.GetOobeWindow().Activate();
121+
App.GetScoobeWindow().Activate();
126122
});
127123

128124
// open flyout
@@ -213,7 +209,7 @@ private void Window_Closed(object sender, WindowEventArgs args)
213209
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
214210
WindowHelper.SerializePlacement(hWnd);
215211

216-
if (App.GetOobeWindow() == null)
212+
if (App.GetOobeWindow() == null && App.GetScoobeWindow() == null)
217213
{
218214
App.ClearSettingsWindow();
219215
}

src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeShellPage.xaml.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public OobeShellPage()
202202
IsNew = true,
203203
});
204204

205+
// WhatsNew is handled by ScoobeWindow, but we need a placeholder to maintain index consistency
205206
Modules.Insert((int)PowerToysModules.WhatsNew, new OobePowerToysModule()
206207
{
207208
ModuleName = "WhatsNew",
@@ -240,14 +241,25 @@ public void NavigateToModule(PowerToysModules selectedModule)
240241
{
241242
if (selectedModule == PowerToysModules.WhatsNew)
242243
{
243-
navigationView.SelectedItem = navigationView.FooterMenuItems[0];
244+
// Open ScoobeWindow for What's new instead of navigating within OobeWindow
245+
OpenScoobeWindow();
244246
}
245247
else
246248
{
247249
navigationView.SelectedItem = navigationView.MenuItems[(int)selectedModule];
248250
}
249251
}
250252

253+
private static void OpenScoobeWindow()
254+
{
255+
if (App.GetScoobeWindow() == null)
256+
{
257+
App.SetScoobeWindow(new ScoobeWindow());
258+
}
259+
260+
App.GetScoobeWindow().Activate();
261+
}
262+
251263
private void NavigationView_SelectionChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs args)
252264
{
253265
Microsoft.UI.Xaml.Controls.NavigationViewItem selectedItem = args.SelectedItem as Microsoft.UI.Xaml.Controls.NavigationViewItem;
@@ -278,7 +290,9 @@ private void NavigationView_SelectionChanged(Microsoft.UI.Xaml.Controls.Navigati
278290
break;
279291
}
280292
*/
281-
case "WhatsNew": NavigationFrame.Navigate(typeof(OobeWhatsNew)); break;
293+
case "WhatsNew":
294+
OpenScoobeWindow();
295+
return; // Don't change selection, just open ScoobeWindow
282296
case "AdvancedPaste": NavigationFrame.Navigate(typeof(OobeAdvancedPaste)); break;
283297
case "AlwaysOnTop": NavigationFrame.Navigate(typeof(OobeAlwaysOnTop)); break;
284298
case "Awake": NavigationFrame.Navigate(typeof(OobeAwake)); break;

src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml renamed to src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<Page
2-
x:Class="Microsoft.PowerToys.Settings.UI.OOBE.Views.OobeWhatsNew"
1+
<Page
2+
x:Class="Microsoft.PowerToys.Settings.UI.OOBE.Views.ScoobeReleaseNotesPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
@@ -188,4 +188,4 @@
188188
</ScrollViewer>
189189
</Grid>
190190
</Grid>
191-
</Page>
191+
</Page>

src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml.cs renamed to src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml.cs

Lines changed: 38 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
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

55
using System;
66
using System.Collections.Generic;
77
using System.ComponentModel;
8-
using System.Linq;
9-
using System.Net;
10-
using System.Net.Http;
118
using System.Text;
12-
using System.Text.Json;
139
using System.Text.RegularExpressions;
14-
using System.Threading.Tasks;
15-
using CommunityToolkit.WinUI.Controls;
10+
1611
using global::PowerToys.GPOWrapper;
1712
using ManagedCommon;
1813
using Microsoft.PowerToys.Settings.UI.Helpers;
1914
using Microsoft.PowerToys.Settings.UI.Library;
2015
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
21-
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
22-
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
2316
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
24-
using Microsoft.PowerToys.Settings.UI.SerializationContext;
2517
using Microsoft.PowerToys.Settings.UI.Services;
2618
using Microsoft.PowerToys.Settings.UI.Views;
2719
using Microsoft.PowerToys.Telemetry;
28-
using Microsoft.UI.Text;
2920
using Microsoft.UI.Xaml;
3021
using Microsoft.UI.Xaml.Controls;
31-
using Microsoft.UI.Xaml.Media;
3222
using Microsoft.UI.Xaml.Navigation;
3323

3424
namespace 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

Comments
 (0)