Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

added ui cleanup

AnoF-Cyberfd94e282c809
diff --git a/Windows/gui/ViewModels/ProxyRulesViewModel.cs b/Windows/gui/ViewModels/ProxyRulesViewModel.cs
index 4292725..59dff75 100644
--- a/Windows/gui/ViewModels/ProxyRulesViewModel.cs
+++ b/Windows/gui/ViewModels/ProxyRulesViewModel.cs
@@ -97,6 +97,13 @@ public class ProxyRulesViewModel : ViewModelBase
public void SetWindow(Window window)
{
_window = window;
+ window.Closed += (_, _) => Cleanup();
+ }
+
+ public void Cleanup()
+ {
+ foreach (var rule in ProxyRules)
+ rule.PropertyChanged -= Rule_PropertyChanged;
}
public bool MoveRuleToPosition(uint ruleId, uint newPosition)
diff --git a/Windows/gui/Views/ProxyRulesWindow.axaml.cs b/Windows/gui/Views/ProxyRulesWindow.axaml.cs
index b841222..d8e15df 100644
--- a/Windows/gui/Views/ProxyRulesWindow.axaml.cs
+++ b/Windows/gui/Views/ProxyRulesWindow.axaml.cs
@@ -57,13 +57,19 @@ public partial class ProxyRulesWindow : Window
}
}
+ private ProxyRulesViewModel? _boundViewModel;
+
private void ProxyRulesWindow_DataContextChanged(object? sender, EventArgs e)
{
- if (DataContext is ProxyRulesViewModel vm)
- {
- vm.PropertyChanged += ViewModel_PropertyChanged;
+ if (_boundViewModel != null)
+ _boundViewModel.PropertyChanged -= ViewModel_PropertyChanged;
- UpdateComboBoxSelections(vm);
+ _boundViewModel = DataContext as ProxyRulesViewModel;
+
+ if (_boundViewModel != null)
+ {
+ _boundViewModel.PropertyChanged += ViewModel_PropertyChanged;
+ UpdateComboBoxSelections(_boundViewModel);
}
}
diff --git a/Windows/gui/Views/ProxySettingsWindow.axaml.cs b/Windows/gui/Views/ProxySettingsWindow.axaml.cs
index a2e6d12..d941e8a 100644
--- a/Windows/gui/Views/ProxySettingsWindow.axaml.cs
+++ b/Windows/gui/Views/ProxySettingsWindow.axaml.cs
@@ -8,12 +8,18 @@ namespace ProxyBridge.GUI.Views;
public partial class ProxySettingsWindow : Window
{
private bool _isUpdatingFromViewModel = false;
+ private ProxySettingsViewModel? _boundViewModel;
public ProxySettingsWindow()
{
InitializeComponent();
this.DataContextChanged += OnDataContextChanged;
+ this.Closed += (_, _) =>
+ {
+ if (_boundViewModel != null)
+ _boundViewModel.PropertyChanged -= ViewModel_PropertyChanged;
+ };
this.Opened += (s, e) =>
{
@@ -24,9 +30,14 @@ public partial class ProxySettingsWindow : Window
private void OnDataContextChanged(object? sender, System.EventArgs e)
{
- if (DataContext is ProxySettingsViewModel vm)
+ if (_boundViewModel != null)
+ _boundViewModel.PropertyChanged -= ViewModel_PropertyChanged;
+
+ _boundViewModel = DataContext as ProxySettingsViewModel;
+
+ if (_boundViewModel != null)
{
- vm.PropertyChanged += ViewModel_PropertyChanged;
+ _boundViewModel.PropertyChanged += ViewModel_PropertyChanged;
var editComboBox = this.FindControl<ComboBox>("EditTypeComboBox");
if (editComboBox != null)