Skip to content

Commit e44932a

Browse files
committed
Feature: Reset browsing data
1 parent b0e91f0 commit e44932a

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,4 +3956,10 @@ Right-click for more options.</value>
39563956
<data name="BrowsingData" xml:space="preserve">
39573957
<value>Browsing Data</value>
39583958
</data>
3959+
<data name="BrowsingDataSuccessfullyDeletedMessage" xml:space="preserve">
3960+
<value>Browsing data successfully deleted!</value>
3961+
</data>
3962+
<data name="BrowsingDataErrorMessage" xml:space="preserve">
3963+
<value>An error occurred while deleting browsing data. Feel free to report this issue on GitHub.</value>
3964+
</data>
39593965
</root>

Source/NETworkManager/Controls/WebConsoleControl.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace NETworkManager.Controls;
1212
public partial class WebConsoleControl : UserControlBase, IDragablzTabItem
1313
{
1414
#region Variables
15+
1516
private static readonly ILog Log = LogManager.GetLogger(typeof(WebConsoleControl));
1617

1718
private bool _initialized;
@@ -110,7 +111,8 @@ private async void UserControl_Loaded(object sender, RoutedEventArgs e)
110111

111112
// Set the default settings
112113
Browser.CoreWebView2.Settings.IsStatusBarEnabled = SettingsManager.Current.WebConsole_IsStatusBarEnabled;
113-
Browser.CoreWebView2.Settings.IsPasswordAutosaveEnabled = SettingsManager.Current.WebConsole_IsPasswordSaveEnabled;
114+
Browser.CoreWebView2.Settings.IsPasswordAutosaveEnabled =
115+
SettingsManager.Current.WebConsole_IsPasswordSaveEnabled;
114116

115117
Navigate(_sessionInfo.Url);
116118

@@ -193,8 +195,6 @@ private void Navigate(string url)
193195
private void Stop()
194196
{
195197
Browser.Stop();
196-
197-
198198
}
199199

200200
public void CloseTab()

Source/NETworkManager/ViewModels/WebConsoleSettingsViewModel.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using MahApps.Metro.SimpleChildWindow;
1+
using System;
2+
using MahApps.Metro.SimpleChildWindow;
23
using NETworkManager.Localization.Resources;
34
using NETworkManager.Settings;
45
using NETworkManager.Utilities;
56
using NETworkManager.Views;
67
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Input;
10+
using Microsoft.Web.WebView2.Core;
11+
using Microsoft.Web.WebView2.Wpf;
912

1013
namespace NETworkManager.ViewModels;
1114

@@ -99,24 +102,33 @@ private void DeleteBrowsingDataAction()
99102
{
100103
DeleteBrowsingData().ConfigureAwait(false);
101104
}
105+
102106
#endregion
103107

104108
#region Methods
109+
105110
private Task DeleteBrowsingData()
106111
{
107112
var childWindow = new OKCancelInfoMessageChildWindow();
108113

109-
var childWindowViewModel = new OKCancelInfoMessageViewModel(_ =>
110-
{
111-
childWindow.IsOpen = false;
112-
ConfigurationManager.Current.IsChildWindowOpen = false;
114+
var childWindowViewModel = new OKCancelInfoMessageViewModel(async _ =>
115+
{
116+
childWindow.IsOpen = false;
117+
ConfigurationManager.Current.IsChildWindowOpen = false;
113118

114-
//SettingsManager.Current.AWSSessionManager_AWSProfiles.Remove(SelectedAWSProfile);
115-
}, _ =>
116-
{
117-
childWindow.IsOpen = false;
118-
ConfigurationManager.Current.IsChildWindowOpen = false;
119-
},
119+
// Create a temporary WebView2 instance to clear browsing data
120+
var webView2Environment =
121+
await CoreWebView2Environment.CreateAsync(null, GlobalStaticConfiguration.WebConsole_Cache);
122+
var webView2Controller = await webView2Environment.CreateCoreWebView2ControllerAsync(IntPtr.Zero);
123+
124+
await webView2Controller.CoreWebView2.Profile.ClearBrowsingDataAsync();
125+
126+
webView2Controller.Close();
127+
}, _ =>
128+
{
129+
childWindow.IsOpen = false;
130+
ConfigurationManager.Current.IsChildWindowOpen = false;
131+
},
120132
Strings.DeleteBrowsingDataMessage,
121133
Strings.Delete
122134
);
@@ -129,5 +141,6 @@ private Task DeleteBrowsingData()
129141

130142
return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
131143
}
144+
132145
#endregion
133-
}
146+
}

Source/NETworkManager/Views/WebConsoleSettingsView.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
77
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
8+
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
89
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
910
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:WebConsoleSettingsViewModel}">
11+
<UserControl.Resources>
12+
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
13+
</UserControl.Resources>
1014
<StackPanel>
1115
<TextBlock Text="{x:Static localization:Strings.WebConsole}" Style="{StaticResource HeaderTextBlock}" />
1216
<mah:ToggleSwitch Header="{x:Static localization:Strings.ShowAddressBar}"
@@ -38,7 +42,10 @@
3842
Style="{StaticResource DefaultTextBlock}"
3943
Margin="0,0,0,10" />
4044
<Button Content="{x:Static localization:Strings.DeleteBrowsingData}" Command="{Binding Path=DeleteBrowsingDataCommand}"
41-
Style="{StaticResource DefaultButton}" HorizontalAlignment="Left"
42-
Margin="0,0,0,10" />
45+
Style="{StaticResource DefaultButton}" HorizontalAlignment="Left" />
46+
<TextBlock Text="{Binding DeleteBrowsingDataStatusMessage}"
47+
Visibility="{Binding IsDeleteBrowsingDataStatusMessageDisplayed, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
48+
Margin="0,10,0,0"
49+
Style="{StaticResource StatusMessageTextBlock}" />
4350
</StackPanel>
4451
</UserControl>

0 commit comments

Comments
 (0)