Files
SubMiner/src/renderer/controller-status-indicator.ts
T
sudacode 8976d78390 feat(controller): route status messages through notifications
- Send controller connected and disabled messages over a new IPC channel so they follow ankiConnect.behavior.notificationType
- Remove the separate controller status toast from the overlay
- Only announce connected controllers when controller.enabled is on
- Announce a controller again after it reconnects, and update usage docs
2026-11-03 21:55:55 -08:00

32 lines
1.1 KiB
TypeScript

import type { ControllerDeviceInfo } from '../types';
type ControllerSnapshot = {
connectedGamepads: ControllerDeviceInfo[];
activeGamepadId: string | null;
};
function getDeviceLabel(device: ControllerDeviceInfo | undefined): string {
if (!device) return 'Controller';
return device.id || `Gamepad ${device.index}`;
}
/** Watches controller snapshots and calls `notify` when a new device appears. */
export function createControllerStatusIndicator(notify: (message: string) => void) {
let previousConnectedIds = new Set<string>();
function update(snapshot: ControllerSnapshot): void {
const newDevices = snapshot.connectedGamepads.filter(
(device) => !previousConnectedIds.has(device.id),
);
if (newDevices.length > 0) {
const announcedDevice =
newDevices.find((device) => device.id === snapshot.activeGamepadId) ?? newDevices[0];
notify(`Controller connected: ${getDeviceLabel(announcedDevice)}`);
}
previousConnectedIds = new Set(snapshot.connectedGamepads.map((device) => device.id));
}
return { update };
}