Preserve USB Move identity during Bluetooth pickup

This commit is contained in:
Meta Vens 2026-06-17 11:27:33 +01:00
commit 162c67ad80
2 changed files with 37 additions and 4 deletions

View file

@ -427,10 +427,7 @@ fn publish_bluetooth_move_identity_records(
let Some(move_id) = bluetooth_address_move_id(&device.address) else {
continue;
};
if active.iter().any(|state| {
state.source.move_id.eq_ignore_ascii_case(&move_id)
&& !is_joystick_path(&state.source.hidraw_path)
}) {
if active_usb_move_source_has_move_id(active, &move_id) {
continue;
}
let Some(record) = build_bluetooth_move_identity_record(
@ -679,6 +676,13 @@ fn active_move_source_has_bluetooth_address(
})
}
fn active_usb_move_source_has_move_id(active: &[ActiveMoveStateSource], move_id: &str) -> bool {
active.iter().any(|state| {
state.source.move_id.eq_ignore_ascii_case(move_id)
&& move_identity_source_state_and_detail(&state.source.hidraw_path).0 == "usb-visible"
})
}
fn bluetooth_address_move_id(address: &str) -> Option<String> {
parse_bluetooth_address_little_endian(address)
.ok()
@ -4899,6 +4903,29 @@ MODALIAS=input:b0005v054Cp03D5e0220
);
}
#[test]
fn usb_visible_active_move_blocks_bluetooth_identity_overwrite() {
let active = vec![ActiveMoveStateSource {
source: MoveStateSource {
move_id: "move-000704a39772".to_string(),
hidraw_path: "/dev/input/js0".to_string(),
},
sequence: 0,
joystick_axes: [0; 16],
joystick_buttons: [false; 32],
light_hidraw_path: None,
}];
assert!(active_usb_move_source_has_move_id(
&active,
"move-000704a39772"
));
assert!(!active_usb_move_source_has_move_id(
&active,
"move-000704a800d0"
));
}
#[cfg(windows)]
#[test]
fn windows_ps_move_source_token_preserves_concrete_hid_path() {

View file

@ -62,8 +62,14 @@ $moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpac
if ($moveStateSpecs.Count -eq 0) {
$claimScript = Join-Path $PSScriptRoot "claim-nightwing-usb-moves.ps1"
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $claimScript -SshTarget $SshTarget
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$sourceScript = Join-Path $PSScriptRoot "get-nightwing-move-state-sources.ps1"
$moveStateSpecs = @(& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -SshTarget $SshTarget)
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}
$moveStateSetLines = ($moveStateSpecs | ForEach-Object {