package common import ( "os" "path/filepath" "runtime" ) const ( // AppName 应用名称 AppName = "u-desk" ) // GetUserDataDir 获取用户数据目录 // 跨平台支持:Windows、macOS、Linux func GetUserDataDir() string { var basePath string switch runtime.GOOS { case "windows": // Windows: %LOCALAPPDATA% 或 %APPDATA% basePath = os.Getenv("LOCALAPPDATA") if basePath == "" { basePath = os.Getenv("APPDATA") } case "darwin": // macOS: ~/Library/Application Support homeDir, err := os.UserHomeDir() if err == nil { basePath = filepath.Join(homeDir, "Library", "Application Support") } default: // Linux: ~/.config homeDir, err := os.UserHomeDir() if err == nil { basePath = filepath.Join(homeDir, ".config") } } if basePath == "" { basePath = "." } return filepath.Join(basePath, AppName) }