|
| 1 | +package profiles |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "os/exec" |
| 7 | + "path/filepath" |
| 8 | + "runtime" |
| 9 | + "strings" |
| 10 | +) |
| 11 | + |
| 12 | +func platformBinaryName() string { return "Claude.exe" } |
| 13 | + |
| 14 | +func platformCommonPaths() []string { |
| 15 | + // MSIX install: query the package install location via PowerShell. |
| 16 | + out, err := exec.Command("powershell", "-Command", |
| 17 | + `(Get-AppxPackage -Name "Claude" | Select-Object -First 1).InstallLocation`).Output() |
| 18 | + if err == nil { |
| 19 | + loc := strings.TrimSpace(string(out)) |
| 20 | + if loc != "" { |
| 21 | + p := filepath.Join(loc, "app", "Claude.exe") |
| 22 | + if _, err := os.Stat(p); err == nil { |
| 23 | + return []string{p} |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + // Squirrel install fallback. |
| 29 | + localAppData := os.Getenv("LOCALAPPDATA") |
| 30 | + if localAppData == "" { |
| 31 | + return nil |
| 32 | + } |
| 33 | + return []string{ |
| 34 | + filepath.Join(localAppData, "Programs", "claude-desktop", "Claude.exe"), |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func platformInstallHint() string { |
| 39 | + return "Opens the Claude download page in your browser.\nInstall the app, then come back here to launch it." |
| 40 | +} |
| 41 | + |
| 42 | +func platformConfigure(baseURL string) error { |
| 43 | + regPath := `HKCU\SOFTWARE\Policies\Claude` |
| 44 | + entries := [][2]string{ |
| 45 | + {"inferenceProvider", "gateway"}, |
| 46 | + {"inferenceGatewayApiKey", "-"}, |
| 47 | + {"inferenceGatewayBaseUrl", baseURL}, |
| 48 | + } |
| 49 | + for _, e := range entries { |
| 50 | + cmd := exec.Command("reg", "add", regPath, "/v", e[0], "/t", "REG_SZ", "/d", e[1], "/f") |
| 51 | + if err := cmd.Run(); err != nil { |
| 52 | + return fmt.Errorf("reg add %s: %w", e[0], err) |
| 53 | + } |
| 54 | + } |
| 55 | + return nil |
| 56 | +} |
| 57 | + |
| 58 | +func platformReadGatewayURL() string { |
| 59 | + out, err := exec.Command("reg", "query", `HKCU\SOFTWARE\Policies\Claude`, "/v", "inferenceGatewayBaseUrl").Output() |
| 60 | + if err != nil { |
| 61 | + return "" |
| 62 | + } |
| 63 | + // reg query output: " inferenceGatewayBaseUrl REG_SZ https://..." |
| 64 | + for _, line := range strings.Split(string(out), "\n") { |
| 65 | + line = strings.TrimSpace(line) |
| 66 | + if strings.Contains(line, "inferenceGatewayBaseUrl") { |
| 67 | + parts := strings.Fields(line) |
| 68 | + if len(parts) >= 3 { |
| 69 | + return parts[len(parts)-1] |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + return "" |
| 74 | +} |
| 75 | + |
| 76 | +func platformInstallCmd() *exec.Cmd { |
| 77 | + url := "https://claude.ai/api/desktop/win32/x64/setup/latest/redirect?utm_source=aperture_cli" |
| 78 | + if runtime.GOARCH == "arm64" { |
| 79 | + url = "https://claude.ai/api/desktop/win32/arm64/setup/latest/redirect?utm_source=aperture_cli" |
| 80 | + } |
| 81 | + return exec.Command("cmd", "/c", "start", "", url) |
| 82 | +} |
| 83 | + |
| 84 | +func platformLaunch() error { |
| 85 | + return exec.Command("cmd", "/c", "start", "", "claude://").Run() |
| 86 | +} |
0 commit comments