Preserve USB Move identity during Bluetooth pickup
This commit is contained in:
parent
4b55f2d660
commit
beed394f45
4 changed files with 58 additions and 11 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -7,17 +7,24 @@ $ErrorActionPreference = "Stop"
|
|||
|
||||
$scriptPath = Join-Path $PSScriptRoot "nightwing-claim-usb-moves.sh"
|
||||
$sshExe = Join-Path $env:SystemRoot "System32\OpenSSH\ssh.exe"
|
||||
|
||||
function Quote-ShSingle([string] $Value) {
|
||||
return "'" + ($Value -replace "'", "'\''") + "'"
|
||||
}
|
||||
|
||||
$scriptContent = [System.IO.File]::ReadAllText($scriptPath) -replace "`r?`n", "`n"
|
||||
$script64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($scriptContent))
|
||||
$remoteArgs = ""
|
||||
if (-not [string]::IsNullOrWhiteSpace($HostAddress)) {
|
||||
$remoteArgs = " " + ($HostAddress -replace "'", "'\''")
|
||||
$remoteArgs = " " + (Quote-ShSingle $HostAddress)
|
||||
}
|
||||
|
||||
$command = '"' + $sshExe + '" -o BatchMode=yes -o ConnectTimeout=5 ' +
|
||||
$SshTarget +
|
||||
' "sh -s' +
|
||||
' "printf %s ' +
|
||||
(Quote-ShSingle $script64) +
|
||||
' | base64 -d | sh -s --' +
|
||||
$remoteArgs +
|
||||
'" < "' +
|
||||
$scriptPath +
|
||||
'"'
|
||||
|
||||
cmd.exe /c $command
|
||||
|
|
|
|||
|
|
@ -6,10 +6,17 @@ $ErrorActionPreference = "Stop"
|
|||
|
||||
$scriptPath = Join-Path $PSScriptRoot "nightwing-move-state-sources.sh"
|
||||
$sshExe = Join-Path $env:SystemRoot "System32\OpenSSH\ssh.exe"
|
||||
|
||||
function Quote-ShSingle([string] $Value) {
|
||||
return "'" + ($Value -replace "'", "'\''") + "'"
|
||||
}
|
||||
|
||||
$scriptContent = [System.IO.File]::ReadAllText($scriptPath) -replace "`r?`n", "`n"
|
||||
$script64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($scriptContent))
|
||||
$command = '"' + $sshExe + '" -o BatchMode=yes -o ConnectTimeout=5 ' +
|
||||
$SshTarget +
|
||||
' "sh -s" < "' +
|
||||
$scriptPath +
|
||||
'"'
|
||||
' "printf %s ' +
|
||||
(Quote-ShSingle $script64) +
|
||||
' | base64 -d | sh -s"'
|
||||
& cmd.exe /d /c $command
|
||||
exit $LASTEXITCODE
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue