Files
dotfiles/chezmoi/.chezmoiscripts/run_30-create-codex-proxy-shortcut.ps1
T
Dmitry Dementiev 42375c2672 feat(codex): добавлен proxy launcher для GUI
- Зачем:
  - нужен удобный запуск Codex GUI с proxy-окружением Windows и WSL.
- Что:
  - добавлен PowerShell launcher, выставляющий proxy-переменные и WSLENV.
  - добавлен chezmoi-скрипт для Start Menu ярлыка Codex Proxy.
  - обновлена документация по использованию Codex GUI через прокси.
- Проверка:
  - git diff --cached --check.
  - запуск launcher и повторный запуск shortcut-скрипта.
2026-05-10 12:12:27 +03:00

91 lines
2.6 KiB
PowerShell

$ErrorActionPreference = 'Stop'
if (-not ($IsWindows -or $PSVersionTable.PSEdition -eq 'Desktop')) {
return
}
$LauncherPath = Join-Path $HOME '.local\bin\start-codex-proxy.ps1'
$ProgramsPath = [Environment]::GetFolderPath('Programs')
if ([string]::IsNullOrWhiteSpace($ProgramsPath)) {
Write-Warning 'Start Menu Programs folder was not found.'
return
}
$ShortcutPath = Join-Path $ProgramsPath 'Codex Proxy.lnk'
$PwshCommand = Get-Command pwsh -ErrorAction SilentlyContinue
if ($null -ne $PwshCommand) {
$TargetPath = $PwshCommand.Source
} else {
$TargetPath = 'pwsh.exe'
}
$Arguments = "-NoLogo -NoProfile -ExecutionPolicy Bypass -File `"$LauncherPath`""
$WorkingDirectory = $env:USERPROFILE
$IconLocation = "$TargetPath,0"
function Get-CodexExecutable {
$Package = Get-AppxPackage -Name 'OpenAI.Codex' -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($null -eq $Package) {
return $null
}
try {
$Manifest = Get-AppxPackageManifest $Package
$Application = @($Manifest.Package.Applications.Application) | Select-Object -First 1
if ($null -eq $Application -or [string]::IsNullOrWhiteSpace($Application.Executable)) {
return $null
}
$Executable = Join-Path $Package.InstallLocation ([string]$Application.Executable)
if (Test-Path -LiteralPath $Executable) {
return $Executable
}
}
catch {
return $null
}
return $null
}
$CodexExecutable = Get-CodexExecutable
if ($null -ne $CodexExecutable) {
$IconLocation = "$CodexExecutable,0"
}
New-Item -ItemType Directory -Path (Split-Path -Parent $ShortcutPath) -Force | Out-Null
$Shell = New-Object -ComObject WScript.Shell
$Shortcut = $Shell.CreateShortcut($ShortcutPath)
$Changed = $false
if ($Shortcut.TargetPath -ne $TargetPath) {
$Shortcut.TargetPath = $TargetPath
$Changed = $true
}
if ($Shortcut.Arguments -ne $Arguments) {
$Shortcut.Arguments = $Arguments
$Changed = $true
}
if ($Shortcut.WorkingDirectory -ne $WorkingDirectory) {
$Shortcut.WorkingDirectory = $WorkingDirectory
$Changed = $true
}
if ($Shortcut.IconLocation -ne $IconLocation) {
$Shortcut.IconLocation = $IconLocation
$Changed = $true
}
if ($Shortcut.Description -ne 'Launch Codex with hproxy.local proxy environment') {
$Shortcut.Description = 'Launch Codex with hproxy.local proxy environment'
$Changed = $true
}
if ($Changed -or -not (Test-Path -LiteralPath $ShortcutPath)) {
$Shortcut.Save()
Write-Host "Codex Proxy shortcut: updated $ShortcutPath"
} else {
Write-Host 'Codex Proxy shortcut: already up to date.'
}