package platform import ( "context" "os" "os/exec" ) // DarwinPlatform macOS 平台实现 type DarwinPlatform struct { homeDir string } // NewDarwinPlatform 创建 macOS 平台实例 func NewDarwinPlatform() *DarwinPlatform { home, _ := os.UserHomeDir() return &DarwinPlatform{homeDir: home} } func (p *DarwinPlatform) OS() string { return "darwin" } func (p *DarwinPlatform) Arch() string { return "amd64" } // TODO: detect properly func (p *DarwinPlatform) HomeDir() string { return p.homeDir } func (p *DarwinPlatform) ConfigDir() string { return p.homeDir + "/Library/Application Support" } func (p *DarwinPlatform) DataDir() string { return p.homeDir + "/Library/Application Support" } func (p *DarwinPlatform) GetEnvVar(key string) string { return os.Getenv(key) } func (p *DarwinPlatform) SetEnvVar(ctx context.Context, key, value string) error { // On macOS, set via launchctl and shell profile cmd := exec.CommandContext(ctx, "launchctl", "setenv", key, value) return cmd.Run() } func (p *DarwinPlatform) AddToPath(ctx context.Context, dir string) error { // TODO: Add to shell profile return nil } func (p *DarwinPlatform) IsAdmin() bool { return os.Geteuid() == 0 } func (p *DarwinPlatform) PackageManagers() []string { var pms []string if _, err := exec.LookPath("brew"); err == nil { pms = append(pms, "homebrew") } return pms } func (p *DarwinPlatform) DefaultShell() string { shell := os.Getenv("SHELL") if shell != "" { return shell } return "/bin/zsh" }