From 0eb593a24d99a29d1c0779772df67613b934fdbe Mon Sep 17 00:00:00 2001 From: Meisterlala <6453306+Meisterlala@users.noreply.github.com> Date: Tue, 23 Dec 2025 21:17:21 +0100 Subject: [PATCH] update scrcpy --- dot_config/powershell/Async/scrcpy.ps1 | 79 ++++++++++++------- dot_config/waybar/executable_scrcpy-active.sh | 4 + 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/dot_config/powershell/Async/scrcpy.ps1 b/dot_config/powershell/Async/scrcpy.ps1 index 4ea2057..32e8e4f 100644 --- a/dot_config/powershell/Async/scrcpy.ps1 +++ b/dot_config/powershell/Async/scrcpy.ps1 @@ -18,37 +18,44 @@ function Link-ScrcpyToVirtualMic } } until ($appExists -and $sinkExists) -# Get all nodes -$Nodes = pw-cli ls Node - -# Function to extract node id by matching a line -function Get-NodeId($Nodes, $MatchText) { - $NodeId = 0 - $CurrentId = 0 - foreach ($Line in $Nodes) { - if ($Line -match 'id (\d+),') { - $CurrentId = $matches[1] - } - if ($Line -match [regex]::Escape($MatchText)) { - $NodeId = $CurrentId - break + # Get all nodes + $Nodes = pw-cli ls Node + + # Function to extract node id by matching a line + function Get-NodeId($Nodes, $MatchText) + { + $NodeId = 0 + $CurrentId = 0 + foreach ($Line in $Nodes) + { + if ($Line -match 'id (\d+),') + { + $CurrentId = $matches[1] + } + if ($Line -match [regex]::Escape($MatchText)) + { + $NodeId = $CurrentId + break + } } + return $NodeId } - return $NodeId -} -# Get app node id -$AppId = Get-NodeId $Nodes "application.name = `"$App`"" + # Get app node id + $AppId = Get-NodeId $Nodes "application.name = `"$App`"" -# Get sink node id -$SinkId = Get-NodeId $Nodes "node.name = `"$Sink`"" + # Get sink node id + $SinkId = Get-NodeId $Nodes "node.name = `"$Sink`"" $linkList = pw-link -lI - foreach ($link in $linkList) { - if ($link -match "\b$AppId\b") { + foreach ($link in $linkList) + { + if ($link -match "\b$AppId\b") + { # unlink the old link - if ($link -match '(\d+):') { + if ($link -match '(\d+):') + { $linkId = $matches[1] Write‑Host "Removing old link id $linkId" pw‑link ‑d $linkId @@ -103,7 +110,7 @@ function Start-OBS $cmd = "$OBSPath $($args -join ' ') > /dev/null 2>&1 &" # Start OBS completely detached - Start-Process -FilePath "bash" -ArgumentList "-c `"$cmd`"" -NoNewWindow + Start-Process -FilePath "bash" -ArgumentList "-c `"$cmd`"" } function Start-Scrcpy @@ -125,6 +132,9 @@ function Start-Scrcpy [string]$Resolution = "1920x1080" ) + $lock = "$env:TEMP\scrcpy.lock" + Remove-Item $lock -ErrorAction SilentlyContinue + $scrcpyArgs = @( "--video-codec=h264", "--video-bit-rate=12M", @@ -179,13 +189,26 @@ function Start-Scrcpy $exit = $proc.ExitCode # If scrcpy was killed by a command, break the loop; otherwise continue (e.g., on crash) - if ($global:os -eq 'linux') { + if ($global:os -eq 'linux') + { # Common Linux signal-derived exit codes: 130 (SIGINT), 143 (SIGTERM), 137 (SIGKILL) - if ($exit -in 130, 143, 137) { break } - } else { + if ($exit -in 130, 143, 137) + { break + } + } else + { # On Windows, a normal close typically returns 0, while crashes are non-zero - if ($exit -eq 0) { break } + if ($exit -eq 0) + { break + } } + + # Check for lock file to determine whether to continue looping + if (-Not (Test-Path $lock)) + { + break + } + } while ($Loop) } diff --git a/dot_config/waybar/executable_scrcpy-active.sh b/dot_config/waybar/executable_scrcpy-active.sh index ffaf74d..e307da7 100644 --- a/dot_config/waybar/executable_scrcpy-active.sh +++ b/dot_config/waybar/executable_scrcpy-active.sh @@ -10,6 +10,10 @@ if [ -n "$pid" ]; then # Kill it! if [ "${1-}" = "--kill" ]; then kill "$pid" + + $lock = "$env:TEMP\scrcpy.lock" + Remove-Item $lock -ErrorAction SilentlyContinue + notify-send --icon=video-display "Killed scrcpy process" "Process ID $pid was terminated." echo "" exit 0 -- 2.51.2