Skip to content

Commit a26ad69

Browse files
authored
Merge pull request #356 from switchifyapp/fix/remove-connect-auto-hide-355
Remove connect-time minimize to tray
2 parents 611da42 + 08c94bb commit a26ad69

7 files changed

Lines changed: 19 additions & 161 deletions

File tree

src/SwitchifyPc.App/App.xaml.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ private async Task HandleBluetoothMessageAsync(BluetoothMessageEvent message)
371371
}
372372
}
373373

374-
if (result.ShouldAutoHideMainWindow)
375-
{
376-
HideMainWindowAfterPreviouslyUsedDeviceControl();
377-
}
378374
}
379375

380376
private static string? AuthFailureMessage(string reason)
@@ -515,21 +511,6 @@ private void UpdateMainWindowState(UpdateState state)
515511
Dispatcher.BeginInvoke(() => mainWindowViewModel.SetUpdateState(state));
516512
}
517513

518-
private void HideMainWindowAfterPreviouslyUsedDeviceControl()
519-
{
520-
if (MainWindow is not { IsVisible: true } window) return;
521-
522-
if (!MainWindowAutoHidePolicy.ShouldHideAfterPreviouslyUsedDeviceControl(
523-
isMainWindowVisible: true,
524-
hasPairingApprovals: mainWindowViewModel.HasPairingApprovals,
525-
isPreviouslyUsedDeviceSession: true))
526-
{
527-
return;
528-
}
529-
530-
window.Hide();
531-
}
532-
533514
private void UpdateBluetoothState(BluetoothStatus status)
534515
{
535516
DesktopUiState desktopState = status.Status switch

src/SwitchifyPc.Core/Bluetooth/BluetoothRemoteFrameProcessor.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ public sealed record BluetoothRemoteFrameResult(
1212
bool MessageComplete,
1313
string? ErrorReason,
1414
IReadOnlyList<BluetoothRemoteFrameOutput> OutgoingMessages,
15-
bool ShouldAutoHideMainWindow = false,
1615
string? AuthenticatedConnectionId = null,
1716
string? AuthenticatedDeviceId = null,
1817
string? AuthFailureReason = null)
1918
{
20-
public static BluetoothRemoteFrameResult Incomplete(string? reason = null) => new(false, reason, [], false);
19+
public static BluetoothRemoteFrameResult Incomplete(string? reason = null) => new(false, reason, []);
2120

2221
public static BluetoothRemoteFrameResult Complete(
2322
IReadOnlyList<BluetoothRemoteFrameOutput> outgoingMessages,
24-
bool shouldAutoHideMainWindow = false,
2523
string? authenticatedConnectionId = null,
2624
string? authenticatedDeviceId = null,
2725
string? authFailureReason = null) =>
28-
new(true, null, outgoingMessages, shouldAutoHideMainWindow, authenticatedConnectionId, authenticatedDeviceId, authFailureReason);
26+
new(true, null, outgoingMessages, authenticatedConnectionId, authenticatedDeviceId, authFailureReason);
2927

30-
public static BluetoothRemoteFrameResult Error(string reason) => new(true, reason, [], false);
28+
public static BluetoothRemoteFrameResult Error(string reason) => new(true, reason, []);
3129
}
3230

3331
public sealed class BluetoothRemoteFrameProcessor
@@ -74,7 +72,6 @@ public async Task<BluetoothRemoteFrameResult> AcceptAsync(
7472
cancellationToken).ConfigureAwait(false);
7573
return BluetoothRemoteFrameResult.Complete(
7674
FrameOutgoingMessages(sessionResult),
77-
sessionResult.ShouldAutoHideMainWindow,
7875
sessionResult.AuthenticatedConnectionId,
7976
sessionResult.AuthenticatedDeviceId,
8077
sessionResult.AuthFailureReason);

src/SwitchifyPc.Core/Control/RemoteControlSession.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ public sealed record RemoteSessionOutgoingMessage(string ConnectionId, string Re
88

99
public sealed record RemoteSessionResult(
1010
IReadOnlyList<RemoteSessionOutgoingMessage> OutgoingMessages,
11-
bool ShouldAutoHideMainWindow = false,
1211
string? AuthenticatedConnectionId = null,
1312
string? AuthenticatedDeviceId = null,
1413
string? AuthFailureReason = null)
1514
{
16-
public static RemoteSessionResult None { get; } = new([], false);
15+
public static RemoteSessionResult None { get; } = new([]);
1716

18-
public static RemoteSessionResult One(RemoteSessionOutgoingMessage message) => new([message], false);
17+
public static RemoteSessionResult One(RemoteSessionOutgoingMessage message) => new([message]);
1918
}
2019

2120
public sealed class RemoteControlSession
@@ -25,7 +24,6 @@ public sealed class RemoteControlSession
2524
private readonly ControlSession commandSession;
2625
private readonly Action? onPendingPairingRequestsChanged;
2726
private readonly Dictionary<string, PendingConnection> pendingConnectionsByRequestId = new(StringComparer.Ordinal);
28-
private readonly Dictionary<string, bool> autoHideEligibleByConnectionId = new(StringComparer.Ordinal);
2927

3028
public RemoteControlSession(
3129
PairingManager pairingManager,
@@ -67,12 +65,10 @@ public async Task<RemoteSessionResult> ProcessMessageAsync(
6765
}
6866

6967
ControlSessionResult commandResult = await commandSession.ProcessMessageAsync(rawMessage, cancellationToken).ConfigureAwait(false);
70-
bool shouldAutoHide = ShouldAutoHideForCommandResult(connectionId, commandResult);
7168
return new RemoteSessionResult(
7269
commandResult.HasResponse
7370
? [new RemoteSessionOutgoingMessage(connectionId, commandResult.ResponseJson!)]
7471
: [],
75-
shouldAutoHide,
7672
commandResult.HasAuthenticatedDevice ? connectionId : null,
7773
commandResult.AuthenticatedDeviceId,
7874
commandResult.AuthFailureReason);
@@ -138,7 +134,6 @@ public RemoteSessionResult ExpirePendingPairingRequests()
138134
public void RemoveConnection(string connectionId)
139135
{
140136
_ = commandSession.StopAllRepeatsAsync();
141-
autoHideEligibleByConnectionId.Remove(connectionId);
142137
string[] requestIds = pendingConnectionsByRequestId
143138
.Where(entry => entry.Value.ConnectionId == connectionId)
144139
.Select(entry => entry.Key)
@@ -207,22 +202,6 @@ private async Task<RemoteSessionResult> HandlePairingRequestAsync(
207202
return pendingConnection;
208203
}
209204

210-
private bool ShouldAutoHideForCommandResult(string connectionId, ControlSessionResult commandResult)
211-
{
212-
if (!commandResult.HasAuthenticatedDevice)
213-
{
214-
return false;
215-
}
216-
217-
if (!autoHideEligibleByConnectionId.TryGetValue(connectionId, out bool eligible))
218-
{
219-
eligible = commandResult.AuthenticatedDeviceWasPreviouslyUsed;
220-
autoHideEligibleByConnectionId[connectionId] = eligible;
221-
}
222-
223-
return eligible;
224-
}
225-
226205
private static JsonDocument? TryParse(string rawMessage, out string? errorResponse)
227206
{
228207
try

src/SwitchifyPc.Core/Ui/MainWindowAutoHidePolicy.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/SwitchifyPc.Tests/BluetoothRemoteFrameProcessorTests.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public async Task ReassemblesCommandAndFramesAckToSameConnection()
3131
}
3232

3333
Assert.True(result.MessageComplete);
34-
Assert.False(result.ShouldAutoHideMainWindow);
34+
Assert.Equal("ble-1", result.AuthenticatedConnectionId);
35+
Assert.Equal(DeviceId, result.AuthenticatedDeviceId);
3536
BluetoothRemoteFrameOutput output = Assert.Single(result.OutgoingMessages);
3637
Assert.Equal("ble-1", output.ConnectionId);
3738
Assert.False(output.CloseConnection);
@@ -53,7 +54,6 @@ public async Task PairingRequestCompletesWithoutImmediateResponseAndAcceptFrames
5354
}
5455

5556
Assert.True(result.MessageComplete);
56-
Assert.False(result.ShouldAutoHideMainWindow);
5757
Assert.Empty(result.OutgoingMessages);
5858
Assert.Equal("192.168.1.50", Assert.Single(context.ApprovalManager.ListPendingRequestViews()).RemoteAddress);
5959

@@ -68,7 +68,7 @@ public async Task PairingRequestCompletesWithoutImmediateResponseAndAcceptFrames
6868
}
6969

7070
[Fact]
71-
public async Task ReassembledCommandFromPreviouslyUsedDeviceRequestsAutoHide()
71+
public async Task ReassembledCommandFromPreviouslyUsedDevicePropagatesAuthenticatedConnection()
7272
{
7373
TestContext context = CreateContext(lastSeenAt: Now - 500);
7474
BluetoothRemoteFrameProcessor processor = new(context.Session, maxResponseFramePayloadBytes: 20);
@@ -84,11 +84,15 @@ public async Task ReassembledCommandFromPreviouslyUsedDeviceRequestsAutoHide()
8484
}
8585

8686
Assert.True(result.MessageComplete);
87-
Assert.True(result.ShouldAutoHideMainWindow);
87+
Assert.Equal("ble-1", result.AuthenticatedConnectionId);
88+
Assert.Equal(DeviceId, result.AuthenticatedDeviceId);
89+
BluetoothRemoteFrameOutput output = Assert.Single(result.OutgoingMessages);
90+
Assert.Equal("ble-1", output.ConnectionId);
91+
AssertResponseType(output.ResponseFrames, "ack");
8892
}
8993

9094
[Fact]
91-
public async Task NewPairedDeviceDoesNotRequestAutoHideForRepeatedMessagesOnSameConnection()
95+
public async Task NewPairedDeviceRepeatedMessagesCompleteOnSameConnection()
9296
{
9397
TestContext context = CreateContext();
9498
BluetoothRemoteFrameProcessor processor = new(context.Session);
@@ -104,8 +108,8 @@ public async Task NewPairedDeviceDoesNotRequestAutoHideForRepeatedMessagesOnSame
104108

105109
Assert.True(first.MessageComplete);
106110
Assert.True(second.MessageComplete);
107-
Assert.False(first.ShouldAutoHideMainWindow);
108-
Assert.False(second.ShouldAutoHideMainWindow);
111+
Assert.Equal("ble-1", first.AuthenticatedConnectionId);
112+
Assert.Equal("ble-1", second.AuthenticatedConnectionId);
109113
}
110114

111115
[Fact]

src/SwitchifyPc.Tests/MainWindowAutoHidePolicyTests.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/SwitchifyPc.Tests/RemoteControlSessionTests.cs

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public async Task PairingRequestCreatesPendingApprovalWithoutImmediateResponse()
2424
remoteAddress: "192.168.1.50");
2525

2626
Assert.Empty(result.OutgoingMessages);
27-
Assert.False(result.ShouldAutoHideMainWindow);
2827
Assert.Null(result.AuthenticatedConnectionId);
2928
Assert.Null(result.AuthenticatedDeviceId);
3029
Assert.Null(result.AuthFailureReason);
@@ -142,7 +141,6 @@ public async Task DelegatesAuthenticatedCommandsToCommandSession()
142141
"ble-1",
143142
SignedCommand("keyboard.key", new { key = "Meta" }));
144143

145-
Assert.False(result.ShouldAutoHideMainWindow);
146144
Assert.Equal("ble-1", result.AuthenticatedConnectionId);
147145
Assert.Equal(DeviceId, result.AuthenticatedDeviceId);
148146
Assert.Null(result.AuthFailureReason);
@@ -171,63 +169,18 @@ public async Task UnknownAuthenticatedCommandReportsAuthFailureWithoutMarkingCon
171169
}
172170

173171
[Fact]
174-
public async Task PreviouslyUsedDeviceCommandRequestsAutoHide()
175-
{
176-
TestContext context = CreateContext(lastSeenAt: Now - 500);
177-
178-
RemoteSessionResult result = await context.Session.ProcessMessageAsync(
179-
"ble-1",
180-
SignedCommand("keyboard.key", new { key = "Meta" }));
181-
182-
Assert.True(result.ShouldAutoHideMainWindow);
183-
}
184-
185-
[Fact]
186-
public async Task NewlyPairedDeviceConnectionDoesNotAutoHideDuringFirstSession()
172+
public async Task AuthenticatedCommandsUpdateLastSeenAt()
187173
{
188174
TestContext context = CreateContext();
189175

190-
RemoteSessionResult first = await context.Session.ProcessMessageAsync(
176+
await context.Session.ProcessMessageAsync(
191177
"ble-1",
192178
SignedCommand("keyboard.key", new { key = "Meta" }, id: "command-1"));
193-
RemoteSessionResult second = await context.Session.ProcessMessageAsync(
194-
"ble-1",
195-
SignedCommand("connection.ping", new { }, id: "command-2"));
196-
197-
Assert.False(first.ShouldAutoHideMainWindow);
198-
Assert.False(second.ShouldAutoHideMainWindow);
199-
Assert.Equal(Now, (await context.Store.LoadAsync()).PairedDevices[0].LastSeenAt);
200-
}
201-
202-
[Fact]
203-
public async Task PreviouslyUsedDeviceReconnectCanAutoHide()
204-
{
205-
TestContext context = CreateContext();
206179
await context.Session.ProcessMessageAsync(
207180
"ble-1",
208-
SignedCommand("keyboard.key", new { key = "Meta" }, id: "command-1"));
209-
context.Session.RemoveConnection("ble-1");
210-
211-
RemoteSessionResult result = await context.Session.ProcessMessageAsync(
212-
"ble-2",
213181
SignedCommand("connection.ping", new { }, id: "command-2"));
214182

215-
Assert.True(result.ShouldAutoHideMainWindow);
216-
}
217-
218-
[Fact]
219-
public async Task RemoveConnectionClearsAutoHideEligibility()
220-
{
221-
TestContext context = CreateContext(lastSeenAt: Now - 500);
222-
Assert.True((await context.Session.ProcessMessageAsync(
223-
"ble-1",
224-
SignedCommand("keyboard.key", new { key = "Meta" }, id: "command-1"))).ShouldAutoHideMainWindow);
225-
226-
context.Session.RemoveConnection("ble-1");
227-
228-
Assert.True((await context.Session.ProcessMessageAsync(
229-
"ble-1",
230-
SignedCommand("connection.ping", new { }, id: "command-2"))).ShouldAutoHideMainWindow);
183+
Assert.Equal(Now, (await context.Store.LoadAsync()).PairedDevices[0].LastSeenAt);
231184
}
232185

233186
[Fact]

0 commit comments

Comments
 (0)