param( [switch]$OpenUi, [switch]$Status, [switch]$RestartServices ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $AppDir = Split-Path -Parent (Split-Path -Parent $ScriptDir) if (-not (Test-Path (Join-Path $AppDir "package.json"))) { throw "Cannot locate app root from $ScriptDir" } $Root = $env:VPN_PROXY_WINDOWS_ROOT if ([string]::IsNullOrWhiteSpace($Root)) { if ((Split-Path -Leaf $AppDir) -eq "app") { $Root = Split-Path -Parent $AppDir } else { $Root = $AppDir } } $env:VPN_PROXY_WINDOWS_ROOT = $Root $env:APP_MODE = "windows" $env:DATA_DIR = Join-Path $Root "data" $env:DIST_DIR = Join-Path $AppDir "dist" $env:PROXY_PORT = "1080" $env:PROXY_BIND_IP = "127.0.0.1" $env:SING_BOX_CONFIG = Join-Path $Root "runtime\sing-box\config.json" $env:SING_BOX_CACHE = Join-Path $Root "runtime\sing-box\cache.db" $env:WINDOWS_HELPER = Join-Path $AppDir "scripts\windows\helper.ps1" $env:PATH = "$(Join-Path $Root "runtime\sing-box");$env:PATH" function Get-NodeCommand { $portable = Join-Path $Root "runtime\node\node.exe" if (Test-Path $portable) { return $portable } return "node" } if ($Status) { $inputJson = @{ action = "status.get"; payload = @{} } | ConvertTo-Json -Compress $inputJson | & $env:WINDOWS_HELPER exit $LASTEXITCODE } if ($RestartServices) { $helper = $env:WINDOWS_HELPER (@{ action = "service.control"; payload = @{ service = "proxifyre"; action = "restart" } } | ConvertTo-Json -Compress) | & $helper (@{ action = "service.control"; payload = @{ service = "sing-box"; action = "restart" } } | ConvertTo-Json -Compress) | & $helper exit 0 } if ($OpenUi) { $node = Get-NodeCommand Start-Process "http://127.0.0.1:3456" & $node (Join-Path $AppDir "src\server\index.js") exit $LASTEXITCODE } Write-Host "VPN Proxy Windows" Write-Host " -OpenUi Start local UI" Write-Host " -Status Print JSON status" Write-Host " -RestartServices Restart ProxiFyre and sing-box"