Skip to content

Commit cd39587

Browse files
committed
fix: Restore window when opening the same RDP server and the server is opened with minimized, fix #381
1 parent fc1f35f commit cd39587

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

Ui/Service/SessionControlService.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using ProtocolHostStatus = _1RM.View.Host.ProtocolHosts.ProtocolHostStatus;
2323
using _1RM.Service.DataSource;
2424
using System.Collections.Generic;
25+
using Shawn.Utils.WpfResources.Theme.Styles;
2526

2627
namespace _1RM.Service
2728
{
@@ -122,13 +123,16 @@ private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server)
122123
if (server.IsOnlyOneInstance() && _connectionId2Hosts.ContainsKey(serverId))
123124
{
124125
SimpleLogHelper.Debug($"_connectionId2Hosts ContainsKey {serverId}");
125-
if (_connectionId2Hosts[serverId].ParentWindow is TabWindowBase t)
126+
if (_connectionId2Hosts[serverId].ParentWindow is { } win)
126127
{
127-
var s = t.GetViewModel().Items.FirstOrDefault(x => x.Content?.ProtocolServer?.Id == serverId);
128-
if (s != null)
129-
t.GetViewModel().SelectedItem = s;
128+
if (win is TabWindowBase tab)
129+
{
130+
var s = tab.GetViewModel().Items.FirstOrDefault(x => x.Content?.ProtocolServer?.Id == serverId);
131+
if (s != null)
132+
tab.GetViewModel().SelectedItem = s;
133+
}
130134

131-
if (t.IsClosed)
135+
if (win.IsClosed)
132136
{
133137
MarkProtocolHostToClose(new string[] { serverId.ToString() });
134138
CleanupProtocolsAndWindows();
@@ -139,9 +143,16 @@ private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server)
139143
{
140144
Execute.OnUIThreadSync(() =>
141145
{
142-
t.Show();
143-
t.Activate();
146+
if (win.IsClosing == false)
147+
{
148+
win.WindowState = win.WindowState == WindowState.Minimized ? WindowState.Normal : win.WindowState;
149+
win.Show();
150+
win.Activate();
151+
}
144152
});
153+
154+
var vmServer = _appData.GetItemById(server.DataSourceName, server.Id);
155+
vmServer?.UpdateConnectTime();
145156
}
146157
catch (Exception e)
147158
{
@@ -150,6 +161,7 @@ private bool ActivateOrReConnIfServerSessionIsOpened(in ProtocolBase server)
150161
CleanupProtocolsAndWindows();
151162
}
152163
}
164+
153165
if (_connectionId2Hosts[serverId].ParentWindow != null)
154166
{
155167
if (_connectionId2Hosts[serverId].Status != ProtocolHostStatus.Connected)

Ui/Service/SessionControlService_OpenConnection.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,9 @@ private void ConnectWithTab(in ProtocolBase protocol, in Runner runner, string a
138138
Execute.OnUIThreadSync(() =>
139139
{
140140
tab ??= this.GetOrCreateTabWindow(assignTabToken);
141-
if (tab == null)
142-
return;
143-
144-
Execute.OnUIThreadSync(() =>
145-
{
146-
tab.Show();
147-
});
141+
if (tab == null) return;
142+
if (tab.IsClosing) return;
143+
tab.Show();
148144

149145
// get display area size for host
150146
Debug.Assert(!_connectionId2Hosts.ContainsKey(host.ConnectionId));
@@ -153,10 +149,7 @@ private void ConnectWithTab(in ProtocolBase protocol, in Runner runner, string a
153149
tab.GetViewModel().AddItem(new TabItemViewModel(host, displayName));
154150
_connectionId2Hosts.TryAdd(host.ConnectionId, host);
155151
host.Conn();
156-
if (tab.WindowState == WindowState.Minimized)
157-
{
158-
tab.WindowState = WindowState.Normal;
159-
}
152+
tab.WindowState = tab.WindowState == WindowState.Minimized ? WindowState.Normal : tab.WindowState;
160153
tab.Activate();
161154
});
162155
}

0 commit comments

Comments
 (0)