mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 04:40:45 +08:00
Fix WhatsApp Admin QR bind and show the scan prompt only after Bind.
Use a current WA protocol version, start the sidecar via local tsx with inherited proxy, and stop auto-opening the QR UI on unbound connecting. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
5c6833612f
commit
9cf026f605
12 changed files with 593 additions and 101 deletions
52
runtime/operations/scripts/lib/ResolveWhatsAppProxy.ps1
Normal file
52
runtime/operations/scripts/lib/ResolveWhatsAppProxy.ps1
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# Resolve a proxy URL for the WhatsApp sidecar without hardcoding a port.
|
||||
# Order: process env -> state\proxy.url -> Windows user Internet Settings.
|
||||
function Get-OclawWhatsAppProxyUrl {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$StateDir,
|
||||
[switch]$Persist
|
||||
)
|
||||
$found = ""
|
||||
foreach ($name in @("AIA_WHATSAPP_PROXY_URL", "HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy")) {
|
||||
$val = [Environment]::GetEnvironmentVariable($name, "Process")
|
||||
if ($val -and $val.Trim()) {
|
||||
$found = $val.Trim()
|
||||
break
|
||||
}
|
||||
}
|
||||
if (-not $found) {
|
||||
$proxyFile = Join-Path $StateDir "proxy.url"
|
||||
if (Test-Path $proxyFile) {
|
||||
$line = @(Get-Content -Path $proxyFile -ErrorAction SilentlyContinue) | Select-Object -First 1
|
||||
if ($line -and $line.Trim()) { $found = $line.Trim() }
|
||||
}
|
||||
}
|
||||
if (-not $found) {
|
||||
try {
|
||||
$reg = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -ErrorAction Stop
|
||||
$raw = [string]$reg.ProxyServer
|
||||
# Clash TUN often sets ProxyEnable=0 but leaves the last mixed-port address.
|
||||
if ($raw -and (($reg.ProxyEnable -eq 1) -or ($raw -match '(?i)127\.0\.0\.1|localhost|::1'))) {
|
||||
$hostport = ""
|
||||
if ($raw -match '(?i)https?=([^;]+)') {
|
||||
$hostport = $Matches[1].Trim()
|
||||
} elseif ($raw -match '^[^\s;]+$') {
|
||||
$hostport = $raw.Trim()
|
||||
}
|
||||
if ($hostport) {
|
||||
if ($hostport -notmatch '^[a-zA-Z][a-zA-Z0-9+.-]*://') {
|
||||
$hostport = "http://$hostport"
|
||||
}
|
||||
$found = $hostport
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
if ($found -and $found.StartsWith('"') -and $found.EndsWith('"')) {
|
||||
$found = $found.Substring(1, $found.Length - 2)
|
||||
}
|
||||
if ($Persist -and $found) {
|
||||
New-Item -ItemType Directory -Force -Path $StateDir | Out-Null
|
||||
Set-Content -Path (Join-Path $StateDir "proxy.url") -Value $found -Encoding ascii
|
||||
}
|
||||
return $found
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue