- Зачем: - Claude Proxy не запускался при установке Claude из Microsoft Store. - Что: - сохранён прежний запуск обычного claude.exe. - добавлена активация пакетного приложения по AUMID с параметрами прокси. - генератор ярлыка получил поддержку значка из пакета Claude. - Проверка: - обе ветки запуска завершились с кодом 0. - сетевой процесс Claude подключился к 127.0.0.1:12334.
174 lines
5.1 KiB
PowerShell
174 lines
5.1 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
|
|
$ProxyHostName = 'hproxy.local'
|
|
$ProxyPort = 12334
|
|
$HttpProxy = "http://${ProxyHostName}:${ProxyPort}"
|
|
$SocksProxy = "socks5://${ProxyHostName}:${ProxyPort}"
|
|
$NoProxy = "${ProxyHostName},localhost,127.0.0.1,::1,[::1],.concept-software.ru"
|
|
$ProxyBypassList = "${ProxyHostName};localhost;127.0.0.1;[::1];*.concept-software.ru"
|
|
|
|
function Set-ProxyEnvironment {
|
|
$env:HTTP_PROXY = $HttpProxy
|
|
$env:HTTPS_PROXY = $HttpProxy
|
|
$env:ALL_PROXY = $SocksProxy
|
|
$env:NO_PROXY = $NoProxy
|
|
|
|
$env:http_proxy = $HttpProxy
|
|
$env:https_proxy = $HttpProxy
|
|
$env:all_proxy = $SocksProxy
|
|
$env:no_proxy = $NoProxy
|
|
}
|
|
|
|
function Add-WslEnvEntries {
|
|
$RequiredEntries = @(
|
|
'HTTP_PROXY/u',
|
|
'HTTPS_PROXY/u',
|
|
'ALL_PROXY/u',
|
|
'NO_PROXY/u',
|
|
'http_proxy/u',
|
|
'https_proxy/u',
|
|
'all_proxy/u',
|
|
'no_proxy/u'
|
|
)
|
|
|
|
$Entries = New-Object System.Collections.Generic.List[string]
|
|
if (-not [string]::IsNullOrWhiteSpace($env:WSLENV)) {
|
|
foreach ($Entry in ($env:WSLENV -split ':')) {
|
|
if (-not [string]::IsNullOrWhiteSpace($Entry) -and -not $Entries.Contains($Entry)) {
|
|
[void]$Entries.Add($Entry)
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($Entry in $RequiredEntries) {
|
|
if (-not $Entries.Contains($Entry)) {
|
|
[void]$Entries.Add($Entry)
|
|
}
|
|
}
|
|
|
|
$env:WSLENV = [string]::Join(':', $Entries)
|
|
}
|
|
|
|
function Get-ClaudeApplication {
|
|
$LegacyExecutable = Join-Path $env:LOCALAPPDATA 'AnthropicClaude\claude.exe'
|
|
if (Test-Path -LiteralPath $LegacyExecutable) {
|
|
return [PSCustomObject]@{
|
|
Mode = 'Legacy'
|
|
Executable = $LegacyExecutable
|
|
AppUserModelId = $null
|
|
}
|
|
}
|
|
|
|
$Package = Get-AppxPackage -Name 'Claude' -ErrorAction SilentlyContinue |
|
|
Select-Object -First 1
|
|
|
|
if ($null -eq $Package) {
|
|
throw "Claude Desktop не найден: проверены файл '$LegacyExecutable' и пакет 'Claude'."
|
|
}
|
|
|
|
$Manifest = Get-AppxPackageManifest $Package
|
|
$Application = @($Manifest.Package.Applications.Application) | Select-Object -First 1
|
|
if ($null -eq $Application -or [string]::IsNullOrWhiteSpace($Application.Executable)) {
|
|
throw "Манифест пакета Claude не содержит исполняемого файла."
|
|
}
|
|
|
|
$Executable = Join-Path $Package.InstallLocation ([string]$Application.Executable)
|
|
if (-not (Test-Path -LiteralPath $Executable)) {
|
|
throw "Исполняемый файл пакета Claude не найден: $Executable"
|
|
}
|
|
|
|
return [PSCustomObject]@{
|
|
Mode = 'Packaged'
|
|
Executable = $Executable
|
|
AppUserModelId = "$($Package.PackageFamilyName)!$([string]$Application.Id)"
|
|
}
|
|
}
|
|
|
|
function Start-ClaudePackagedApplication {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$AppUserModelId,
|
|
|
|
[Parameter(Mandatory)]
|
|
[string]$Arguments
|
|
)
|
|
|
|
if (-not ('ClaudeProxyLauncher.ApplicationActivationManager' -as [type])) {
|
|
Add-Type -TypeDefinition @'
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace ClaudeProxyLauncher
|
|
{
|
|
[Flags]
|
|
public enum ActivateOptions : uint
|
|
{
|
|
None = 0
|
|
}
|
|
|
|
[ComImport]
|
|
[Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
public interface IApplicationActivationManager
|
|
{
|
|
[PreserveSig]
|
|
int ActivateApplication(
|
|
[MarshalAs(UnmanagedType.LPWStr)] string appUserModelId,
|
|
[MarshalAs(UnmanagedType.LPWStr)] string arguments,
|
|
ActivateOptions options,
|
|
out uint processId);
|
|
}
|
|
|
|
[ComImport]
|
|
[Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
|
|
public class ApplicationActivationManager
|
|
{
|
|
}
|
|
|
|
public static class ApplicationActivator
|
|
{
|
|
public static uint Activate(string appUserModelId, string arguments)
|
|
{
|
|
IApplicationActivationManager manager =
|
|
(IApplicationActivationManager)new ApplicationActivationManager();
|
|
|
|
uint processId;
|
|
int hResult = manager.ActivateApplication(
|
|
appUserModelId,
|
|
arguments,
|
|
ActivateOptions.None,
|
|
out processId);
|
|
|
|
Marshal.ThrowExceptionForHR(hResult);
|
|
return processId;
|
|
}
|
|
}
|
|
}
|
|
'@
|
|
}
|
|
|
|
[void][ClaudeProxyLauncher.ApplicationActivator]::Activate(
|
|
$AppUserModelId,
|
|
$Arguments
|
|
)
|
|
}
|
|
|
|
Set-ProxyEnvironment
|
|
Add-WslEnvEntries
|
|
|
|
$ClaudeApplication = Get-ClaudeApplication
|
|
$ProxyServerArgument = "--proxy-server=${HttpProxy}"
|
|
$ProxyBypassArgument = "--proxy-bypass-list=${ProxyBypassList}"
|
|
|
|
if ($ClaudeApplication.Mode -eq 'Legacy') {
|
|
Start-Process -FilePath $ClaudeApplication.Executable -ArgumentList @(
|
|
$ProxyServerArgument,
|
|
$ProxyBypassArgument
|
|
)
|
|
} else {
|
|
$ClaudeArguments = "${ProxyServerArgument} ${ProxyBypassArgument}"
|
|
Start-ClaudePackagedApplication `
|
|
-AppUserModelId $ClaudeApplication.AppUserModelId `
|
|
-Arguments $ClaudeArguments
|
|
}
|