Skip to content

Commit 4f81927

Browse files
committed
Fix: Don't allow reconnect while connecting
1 parent f4d2b81 commit 4f81927

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
using System;
1+
using Dragablz;
2+
using MahApps.Metro.Controls.Dialogs;
3+
using NETworkManager.Localization;
4+
using NETworkManager.Localization.Resources;
5+
using NETworkManager.Models;
6+
using NETworkManager.Models.RemoteDesktop;
7+
using NETworkManager.Settings;
8+
using NETworkManager.Utilities;
9+
using System;
210
using System.Collections.Generic;
311
using System.ComponentModel;
412
using System.Diagnostics;
@@ -9,15 +17,6 @@
917
using System.Windows.Forms;
1018
using System.Windows.Input;
1119
using System.Windows.Interop;
12-
using Dragablz;
13-
using MahApps.Metro.Controls.Dialogs;
14-
using NETworkManager.Localization;
15-
using NETworkManager.Localization.Resources;
16-
using NETworkManager.Models;
17-
using NETworkManager.Models.RemoteDesktop;
18-
using NETworkManager.Settings;
19-
using NETworkManager.Utilities;
20-
using Application = System.Windows.Application;
2120

2221
namespace NETworkManager.Controls;
2322

@@ -71,7 +70,7 @@ private async void FocusEmbeddedWindow()
7170

7271
// Focus embedded window in the selected tab
7372
(((DragablzTabItem)tabablzControl.SelectedItem)?.View as IEmbeddedWindow)?.FocusEmbeddedWindow();
74-
73+
7574
break;
7675
}
7776
}
@@ -169,7 +168,7 @@ private bool RemoteDesktop_IsConnected_CanExecute(object view)
169168
private bool RemoteDesktop_IsDisconnected_CanExecute(object view)
170169
{
171170
if (view is RemoteDesktopControl control)
172-
return !control.IsConnected;
171+
return !control.IsConnected && !control.IsConnecting;
173172

174173
return false;
175174
}
@@ -376,8 +375,8 @@ private void DragablzTabHostWindow_OnClosing(object sender, CancelEventArgs e)
376375
{
377376
// Find all TabablzControl in the active window
378377
foreach (var tabablzControl in VisualTreeHelper.FindVisualChildren<TabablzControl>(this))
379-
foreach (var tabItem in tabablzControl.Items.OfType<DragablzTabItem>())
380-
((IDragablzTabItem)tabItem.View).CloseTab();
378+
foreach (var tabItem in tabablzControl.Items.OfType<DragablzTabItem>())
379+
((IDragablzTabItem)tabItem.View).CloseTab();
381380

382381
// Reset the dragging state
383382
switch (ApplicationName)
@@ -481,14 +480,14 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref
481480
}
482481

483482
private void UpdateOnWindowResize()
484-
{
483+
{
485484
// Find all TabablzControl
486485
foreach (var tabablzControl in VisualTreeHelper.FindVisualChildren<TabablzControl>(this))
487486
{
488487
// Skip if no items
489488
if (tabablzControl.Items.Count == 0)
490489
continue;
491-
490+
492491
foreach (var item in tabablzControl.Items.OfType<DragablzTabItem>())
493492
{
494493
if (item.View is RemoteDesktopControl control)

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NETworkManager.Settings;
99
using NETworkManager.Utilities;
1010
using System;
11+
using System.Diagnostics;
1112
using System.Threading.Tasks;
1213
using System.Windows;
1314
using System.Windows.Input;
@@ -65,6 +66,8 @@ public bool IsConnected
6566
if (value == _isConnected)
6667
return;
6768

69+
Debug.WriteLine("IsConnected: " + value);
70+
6871
_isConnected = value;
6972
OnPropertyChanged();
7073
}
@@ -80,6 +83,8 @@ public bool IsConnecting
8083
if (value == _isConnecting)
8184
return;
8285

86+
Debug.WriteLine("IsConnecting: " + value);
87+
8388
_isConnecting = value;
8489
OnPropertyChanged();
8590
}
@@ -327,6 +332,9 @@ private void Connect()
327332

328333
private void Reconnect()
329334
{
335+
if (IsConnecting)
336+
return;
337+
330338
if (IsConnected)
331339
return;
332340

Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private bool IsConnected_CanExecute(object view)
245245
private bool IsDisconnected_CanExecute(object view)
246246
{
247247
if (view is RemoteDesktopControl control)
248-
return !control.IsConnected;
248+
return !control.IsConnected && !control.IsConnecting;
249249

250250
return false;
251251
}
@@ -281,7 +281,7 @@ private void FullscreenAction(object view)
281281
private void AdjustScreenAction(object view)
282282
{
283283
if (view is RemoteDesktopControl control)
284-
control.AdjustScreen(force:true);
284+
control.AdjustScreen(force: true);
285285
}
286286

287287
public ICommand SendCtrlAltDelCommand => new RelayCommand(SendCtrlAltDelAction, IsConnected_CanExecute);

0 commit comments

Comments
 (0)