# PhoneRC web installer — generated from phone-rc/shortcut-launcher. # Do not edit here; edit the source in the phone-rc repository. $ErrorActionPreference = "Stop" $BaseUrl = "https://stoicsoft.net/phonerc/downloads" $InstallDir = if ($env:PHONERC_COMPANION_HOME) { $env:PHONERC_COMPANION_HOME } else { Join-Path $env:LOCALAPPDATA "PhoneRC Companion" } # PhoneRC offers two ways to receive shortcuts on Windows: # * AutoHotkey - global hotkeys only (app-launch shortcuts). No Python needed. # * Python listener - hotkeys PLUS the Bluetooth Unicode text companion. # Users who already have AutoHotkey and don't want to run Python get the # AutoHotkey path; everyone else gets the Python listener. Override with # PHONERC_COMPANION_MODE = "autohotkey" or "python". # End-to-end pipeline test: this comment should propagate to inc-site. $Mode = if ($env:PHONERC_COMPANION_MODE) { $env:PHONERC_COMPANION_MODE.Trim().ToLower() } else { "" } $StartupDir = [Environment]::GetFolderPath("Startup") $PythonLauncher = Join-Path $StartupDir "PhoneRC Companion.cmd" $AhkLauncher = Join-Path $StartupDir "PhoneRC Shortcuts.cmd" $AhkLauncherLnk = Join-Path $StartupDir "PhoneRC Shortcuts.lnk" function Find-AutoHotkey { $candidates = @( (Join-Path $env:ProgramFiles "AutoHotkey\v2\AutoHotkey.exe"), (Join-Path $env:ProgramFiles "AutoHotkey\v2\AutoHotkey64.exe"), (Join-Path ${env:ProgramFiles(x86)} "AutoHotkey\v2\AutoHotkey.exe"), (Join-Path $env:ProgramFiles "AutoHotkey\AutoHotkey.exe") ) foreach ($c in $candidates) { if ($c -and (Test-Path $c)) { return $c } } $cmd = Get-Command AutoHotkey.exe -ErrorAction SilentlyContinue if ($cmd) { return $cmd.Source } return $null } # Decide which mechanism to install. $Ahk = Find-AutoHotkey if ($Mode -eq "python") { $UseAhk = $false } elseif ($Mode -eq "autohotkey") { if (-not $Ahk) { throw "PHONERC_COMPANION_MODE=autohotkey, but AutoHotkey v2 was not found. Install it from https://www.autohotkey.com, then re-run." } $UseAhk = $true } else { $UseAhk = [bool]$Ahk } # The Python path needs Python 3.8+ and git (for the Bluetooth dependency). # The AutoHotkey path needs neither, so only check when we'll use Python. if (-not $UseAhk) { if (Get-Command py -ErrorAction SilentlyContinue) { $PythonExe = "py"; $PythonPrefix = @("-3") } elseif (Get-Command python -ErrorAction SilentlyContinue) { $PythonExe = "python"; $PythonPrefix = @() } else { throw "Python 3.8 or newer is required for the Python listener. Install Python (or AutoHotkey v2), then try again." } & $PythonExe @PythonPrefix -c "import sys; raise SystemExit(sys.version_info < (3, 8))" if ($LASTEXITCODE -ne 0) { throw "Python 3.8 or newer is required." } if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw "Git is required to install the Windows Bluetooth dependency." } } $TempDir = Join-Path ([IO.Path]::GetTempPath()) ("phonerc-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $TempDir | Out-Null try { $OuterZip = Join-Path $TempDir "companion.zip" $OuterDir = Join-Path $TempDir "outer" Write-Host "Downloading PhoneRC Companion for Windows..." Invoke-WebRequest "$BaseUrl/phonerc-companion-windows.zip" -OutFile $OuterZip Expand-Archive $OuterZip -DestinationPath $OuterDir $InnerZip = Get-ChildItem $OuterDir -Filter *.zip -Recurse | Select-Object -First 1 if ($InnerZip) { $PackageDir = Join-Path $TempDir "package" Expand-Archive $InnerZip.FullName -DestinationPath $PackageDir $SourceDir = Join-Path $PackageDir "shortcut-launcher" } else { $SourceDir = Join-Path $OuterDir "shortcut-launcher" } if (-not (Test-Path (Join-Path $SourceDir "shortcut_launcher.py"))) { throw "Invalid download." } New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null $ExistingConfig = Join-Path $InstallDir "config.json" $SavedConfig = Join-Path $TempDir "config.json" if (Test-Path $ExistingConfig) { Copy-Item $ExistingConfig $SavedConfig } Copy-Item (Join-Path $SourceDir "*") $InstallDir -Recurse -Force if (Test-Path $SavedConfig) { Copy-Item $SavedConfig $ExistingConfig -Force } if ($UseAhk) { # --- AutoHotkey path: global hotkeys only, no Python listener. --- $AhkScript = Join-Path $InstallDir "phonerc_shortcuts.ahk" if (-not (Test-Path $AhkScript)) { throw "AutoHotkey script missing from the download." } # Remove any Python-listener autostart so the two don't collide. if (Test-Path $PythonLauncher) { Remove-Item $PythonLauncher -Force } Set-Content $AhkLauncher "@start `"PhoneRC Shortcuts`" `"$Ahk`" `"$AhkScript`"" -Encoding ASCII Start-Process $Ahk -ArgumentList "`"$AhkScript`"" Write-Host "PhoneRC shortcuts installed via AutoHotkey; running now and will start with Windows." Write-Host "Using AutoHotkey: $Ahk" Write-Host "Installed at: $InstallDir" Write-Host "Note: Unicode text entry needs the Python listener. To use it instead," Write-Host " re-run with `$env:PHONERC_COMPANION_MODE = 'python'." } else { # --- Python listener path: hotkeys plus the Unicode companion. --- # Remove any AutoHotkey autostart so the two don't collide. if (Test-Path $AhkLauncher) { Remove-Item $AhkLauncher -Force } if (Test-Path $AhkLauncherLnk) { Remove-Item $AhkLauncherLnk -Force } $VenvDir = Join-Path $InstallDir ".venv" & $PythonExe @PythonPrefix -m venv $VenvDir $VenvPython = Join-Path $VenvDir "Scripts\python.exe" & $VenvPython -m pip install --disable-pip-version-check -r (Join-Path $InstallDir "requirements.txt") $SelfTest = (& $VenvPython (Join-Path $InstallDir "shortcut_launcher.py") --self-test | Out-String) Write-Host $SelfTest if ($SelfTest -notmatch '(?m)^companion supported: yes\r?$') { throw "PhoneRC Companion prerequisites are incomplete; automatic startup was not configured." } $Pythonw = Join-Path $VenvDir "Scripts\pythonw.exe" Set-Content $PythonLauncher "@start `"PhoneRC Companion`" /min `"$Pythonw`" `"$InstallDir\shortcut_launcher.py`" --both" -Encoding ASCII $LauncherScript = Join-Path $InstallDir "shortcut_launcher.py" Start-Process $Pythonw -ArgumentList @("`"$LauncherScript`"", "--both") -WorkingDirectory $InstallDir Write-Host "PhoneRC Companion (Python listener) is installed, running, and will start with Windows." Write-Host "Installed at: $InstallDir" Write-Host "Tip: If you prefer AutoHotkey-only shortcuts, install AutoHotkey v2 and re-run this installer." } } finally { Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue }