Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/SwitchifyPc.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public partial class App : System.Windows.Application
private BluetoothRemoteFrameProcessor? bluetoothFrameProcessor;
private DesktopCommandExecutor? commandExecutor;
private JsonSwitchControlProfileStore? switchControlProfileStore;
private SwitchControlSessionManager? switchControlSessionManager;
private MouseRepeatController? mouseRepeatController;
private WindowsCursorOverlayNotifier? cursorOverlay;
private WindowsModifierKeyOverlayNotifier? modifierOverlay;
Expand Down Expand Up @@ -143,6 +144,7 @@ protected override void OnExit(ExitEventArgs e)
mouseRepeatController = null;
try
{
switchControlSessionManager?.StopAllAsync().GetAwaiter().GetResult();
commandExecutor?.ReleaseHeldInputsAsync().GetAwaiter().GetResult();
}
catch
Expand All @@ -157,6 +159,7 @@ protected override void OnExit(ExitEventArgs e)
themeManager?.Dispose();
themeManager = null;
commandExecutor = null;
switchControlSessionManager = null;
switchControlProfileStore = null;
bluetoothFrameProcessor = null;
bluetoothStatusTracker = null;
Expand Down Expand Up @@ -297,7 +300,7 @@ private void ShowSwitchControlProfiles()
{
switchControlProfileWindow = new SwitchControlProfileWindow(
switchControlProfileStore,
() => null);
() => switchControlSessionManager?.ActiveProfileId);
switchControlProfileWindow.Closed += (_, _) => switchControlProfileWindow = null;
}
switchControlProfileWindow.Owner = settingsWindow;
Expand Down Expand Up @@ -384,6 +387,9 @@ private async Task StartBluetoothAsync()
JsonCursorOverlaySettingsStore cursorOverlaySettingsStore = new(Path.Combine(userDataDirectory, "cursor-overlay-settings.json"));
SendInputWindowsNativeInput nativeInput = new();
WindowsDesktopInputAdapter inputAdapter = new(nativeInput, pointerSettingsStore.Load());
WindowsGridSwitchBroadcaster gridSwitchBroadcaster = new();
switchControlProfileStore = new JsonSwitchControlProfileStore(
Path.Combine(userDataDirectory, "switch-control-profiles.json"));
cursorOverlay = new WindowsCursorOverlayNotifier(
nativeInput,
cursorOverlaySettingsStore,
Expand All @@ -397,7 +403,12 @@ private async Task StartBluetoothAsync()
inputAdapter,
cursorOverlay,
modifierOverlay: modifierOverlay,
gridSwitchBroadcaster: new WindowsGridSwitchBroadcaster());
gridSwitchBroadcaster: gridSwitchBroadcaster);
switchControlSessionManager = new SwitchControlSessionManager(
switchControlProfileStore,
new SwitchOutputSessionFactory(inputAdapter, gridSwitchBroadcaster));
switchControlSessionManager.ActiveProfileChanged += profileName =>
Dispatcher.BeginInvoke(() => mainWindowViewModel.SetActiveSwitchControlProfile(profileName));
mouseRepeatController = new MouseRepeatController(
commandExecutor,
mouseRepeatSettingsStore,
Expand All @@ -408,7 +419,8 @@ private async Task StartBluetoothAsync()
commandExecutor,
new WindowsPointerProfileProvider(nativeInput, pointerSettingsStore, mouseRepeatSettingsStore),
mouseRepeatController,
pointerSpeedController);
pointerSpeedController,
switchControlSessionManager);

pairingApprovalManager ??= new PairingApprovalManager(pairingStore);
RemoteControlSession remoteSession = new(
Expand Down Expand Up @@ -465,6 +477,11 @@ private void HandleBluetoothEvent(BluetoothHelperEvent helperEvent)
bluetoothFrameProcessor?.RemoveConnection(disconnected.ConnectionId);
if (status.ConnectedClientCount == 0)
{
if (switchControlSessionManager is not null)
{
await switchControlSessionManager.StopAllAsync();
}

if (mouseRepeatController is not null)
{
await mouseRepeatController.StopAllAsync();
Expand Down
6 changes: 6 additions & 0 deletions src/SwitchifyPc.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
FontWeight="Bold" />
</StackPanel>
</Border>
<TextBlock Margin="0,12,0,0"
HorizontalAlignment="Center"
Text="{Binding ActiveSwitchControlProfile}"
FontWeight="SemiBold"
AutomationProperties.LiveSetting="Polite"
Visibility="{Binding HasActiveSwitchControlProfile, Converter={StaticResource BooleanToVisibilityConverter}}" />

<Border Margin="0,14,0,0"
Background="{DynamicResource AccentContainer}"
Expand Down
Loading