Skip to content

Commit 0884093

Browse files
BornToBeRootclaude
andcommitted
Fix: Web Console: Status message after deleting the browsing data
The settings view binds a status message below "Delete browsing data", but the properties never existed in the view model (XAML binding error): no feedback after deleting, and an error (e.g. WebView2 runtime not installed) was not handled. Shows the existing success / error message, errors are logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c9652d1 commit 0884093

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

‎Source/NETworkManager/ViewModels/WebConsoleSettingsViewModel.cs‎

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using MahApps.Metro.SimpleChildWindow;
1+
using log4net;
2+
using MahApps.Metro.SimpleChildWindow;
23
using Microsoft.Web.WebView2.Core;
34
using NETworkManager.Localization.Resources;
45
using NETworkManager.Settings;
56
using NETworkManager.Utilities;
67
using NETworkManager.Views;
8+
using System;
79
using System.Threading.Tasks;
810
using System.Windows;
911
using System.Windows.Input;
@@ -15,8 +17,42 @@ public class WebConsoleSettingsViewModel : ViewModelBase
1517
{
1618
#region Variables
1719

20+
private static readonly ILog Log = LogManager.GetLogger(typeof(WebConsoleSettingsViewModel));
21+
1822
private readonly bool _isLoading;
1923

24+
/// <summary>
25+
/// Gets or sets a value indicating whether the result of deleting the browsing data is displayed.
26+
/// </summary>
27+
public bool IsDeleteBrowsingDataStatusMessageDisplayed
28+
{
29+
get;
30+
set
31+
{
32+
if (value == field)
33+
return;
34+
35+
field = value;
36+
OnPropertyChanged();
37+
}
38+
}
39+
40+
/// <summary>
41+
/// Gets the result of deleting the browsing data.
42+
/// </summary>
43+
public string DeleteBrowsingDataStatusMessage
44+
{
45+
get;
46+
private set
47+
{
48+
if (value == field)
49+
return;
50+
51+
field = value;
52+
OnPropertyChanged();
53+
}
54+
}
55+
2056
public bool ShowAddressBar
2157
{
2258
get;
@@ -111,17 +147,33 @@ private async Task DeleteBrowsingData()
111147
if (!result)
112148
return;
113149

114-
// Create a temporary WebView2 instance to clear browsing data
115-
var webView2Environment =
116-
await CoreWebView2Environment.CreateAsync(null, GlobalStaticConfiguration.WebConsole_Cache);
150+
IsDeleteBrowsingDataStatusMessageDisplayed = false;
117151

118-
var windowHwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
152+
try
153+
{
154+
// Create a temporary WebView2 instance to clear browsing data
155+
var webView2Environment =
156+
await CoreWebView2Environment.CreateAsync(null, GlobalStaticConfiguration.WebConsole_Cache);
157+
158+
var windowHwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
159+
160+
var webView2Controller = await webView2Environment.CreateCoreWebView2ControllerAsync(windowHwnd);
161+
162+
await webView2Controller.CoreWebView2.Profile.ClearBrowsingDataAsync();
119163

120-
var webView2Controller = await webView2Environment.CreateCoreWebView2ControllerAsync(windowHwnd);
164+
webView2Controller.Close();
121165

122-
await webView2Controller.CoreWebView2.Profile.ClearBrowsingDataAsync();
166+
DeleteBrowsingDataStatusMessage = Strings.BrowsingDataSuccessfullyDeletedMessage;
167+
}
168+
catch (Exception ex)
169+
{
170+
// E.g. the WebView2 runtime is not installed
171+
Log.Error("Error while deleting the browsing data of the WebView2 profile.", ex);
172+
173+
DeleteBrowsingDataStatusMessage = Strings.BrowsingDataErrorMessage;
174+
}
123175

124-
webView2Controller.Close();
176+
IsDeleteBrowsingDataStatusMessageDisplayed = true;
125177
}
126178

127179
#endregion

‎Website/docs/changelog/next-release.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ Release date: **xx.xx.2026**
362362

363363
- Fixed columns that couldn't be made wider than the window (by dragging or double-clicking the gripper) in the OUI and port lookup. The grid scrolls horizontally now, the last (or main) column still fills the remaining width. [#3557](https://github.com/BornToBeRoot/NETworkManager/issues/3557)
364364

365+
**Web Console**
366+
367+
- Fixed no message being shown after **Delete browsing data** in the settings (whether the browsing data was deleted or an error occurred), and an error (e.g. the WebView2 runtime is not installed) not being handled.
368+
365369
## Dependencies, Refactoring & Documentation
366370

367371
- Code cleanup & refactoring

0 commit comments

Comments
 (0)