70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
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: 正确检测架构
|
|
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 {
|
|
// 在 macOS 上通过 launchctl 和 Shell 配置文件设置
|
|
cmd := exec.CommandContext(ctx, "launchctl", "setenv", key, value)
|
|
return cmd.Run()
|
|
}
|
|
|
|
func (p *DarwinPlatform) AddToPath(ctx context.Context, dir string) error {
|
|
// TODO: 添加到 Shell 配置文件
|
|
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"
|
|
}
|
|
|
|
func (p *DarwinPlatform) InstallFont(ctx context.Context, fontPath string) error {
|
|
return nil
|
|
}
|