#!/usr/bin/env bash # # Copy the cross-compiled exe to a real Windows path and (re)start it. # # Run this on the WSL host, NOT inside the devcontainer: the container has no Windows # interop, so it can build the binary but cannot launch it. Copying to %LOCALAPPDATA% # rather than launching over \\wsl.localhost avoids zone-of-origin and file-locking # quirks on the WSL share. set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" exe="$repo/target/x86_64-pc-windows-gnu/release/audioswitch.exe" if [ ! -f "$exe" ]; then echo "No binary. Build it first: cargo build --release" >&2 exit 1 fi dest_win="$(cmd.exe /c 'echo %LOCALAPPDATA%' 2>/dev/null | tr -d '\r')\\AudioSwitch" dest="$(wslpath -u "$dest_win")" mkdir -p "$dest" # Stop whatever is running, or the copy fails with the file locked. if [ -f "$dest/audioswitch.exe" ]; then "$dest/audioswitch.exe" --quit >/dev/null 2>&1 || true sleep 0.5 fi cp "$exe" "$dest/audioswitch.exe" # `cmd.exe /c start` hangs forever under WSL interop here, so launch through PowerShell, # which detaches cleanly. The cd avoids cmd/powershell complaining about a UNC cwd. (cd /mnt/c && powershell.exe -NoProfile -Command \ "Start-Process -FilePath '${dest_win}\\audioswitch.exe'") /dev/null 2>&1 echo "Deployed and started: ${dest_win}\\audioswitch.exe"