File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ private void HandleBluetoothEvent(BluetoothHelperEvent helperEvent)
293293 break ;
294294 case BluetoothConnectedEvent connected :
295295 bluetoothStatusTracker . AddConnection ( connected . ConnectionId ) ;
296+ HideMainWindowAfterDeviceConnected ( ) ;
296297 break ;
297298 case BluetoothDisconnectedEvent disconnected :
298299 BluetoothStatus status = bluetoothStatusTracker . RemoveConnection ( disconnected . ConnectionId , disconnected . Reason ) ;
@@ -429,6 +430,20 @@ private void UpdateMainWindowState(UpdateState state)
429430 Dispatcher . BeginInvoke ( ( ) => mainWindowViewModel . SetUpdateState ( state ) ) ;
430431 }
431432
433+ private void HideMainWindowAfterDeviceConnected ( )
434+ {
435+ if ( MainWindow is not { IsVisible : true } window ) return ;
436+
437+ if ( ! MainWindowAutoHidePolicy . ShouldHideAfterDeviceConnected (
438+ isMainWindowVisible : true ,
439+ hasPairingApprovals : mainWindowViewModel . HasPairingApprovals ) )
440+ {
441+ return ;
442+ }
443+
444+ window . Hide ( ) ;
445+ }
446+
432447 private void UpdateBluetoothState ( BluetoothStatus status )
433448 {
434449 DesktopUiState desktopState = status . Status switch
Original file line number Diff line number Diff line change 1+ namespace SwitchifyPc . Core . Ui ;
2+
3+ public static class MainWindowAutoHidePolicy
4+ {
5+ public static bool ShouldHideAfterDeviceConnected (
6+ bool isMainWindowVisible ,
7+ bool hasPairingApprovals )
8+ {
9+ return isMainWindowVisible && ! hasPairingApprovals ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ using SwitchifyPc . Core . Ui ;
2+
3+ namespace SwitchifyPc . Tests ;
4+
5+ public sealed class MainWindowAutoHidePolicyTests
6+ {
7+ [ Fact ]
8+ public void HidesVisibleMainWindowWhenDeviceConnects ( )
9+ {
10+ Assert . True ( MainWindowAutoHidePolicy . ShouldHideAfterDeviceConnected (
11+ isMainWindowVisible : true ,
12+ hasPairingApprovals : false ) ) ;
13+ }
14+
15+ [ Fact ]
16+ public void DoesNotHideWhenMainWindowIsAlreadyHidden ( )
17+ {
18+ Assert . False ( MainWindowAutoHidePolicy . ShouldHideAfterDeviceConnected (
19+ isMainWindowVisible : false ,
20+ hasPairingApprovals : false ) ) ;
21+ }
22+
23+ [ Fact ]
24+ public void DoesNotHideWhenPairingApprovalIsVisible ( )
25+ {
26+ Assert . False ( MainWindowAutoHidePolicy . ShouldHideAfterDeviceConnected (
27+ isMainWindowVisible : true ,
28+ hasPairingApprovals : true ) ) ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments