package main import ( "os" "strings" "u-desk/internal/system" ) // GetSystemInfo 获取系统信息 func (a *App) GetSystemInfo() (map[string]interface{}, error) { return system.GetSystemInfo() } // GetCPUInfo 获取 CPU 信息 func (a *App) GetCPUInfo() (map[string]interface{}, error) { return system.GetCPUInfo() } // GetMemoryInfo 获取内存信息 func (a *App) GetMemoryInfo() (map[string]interface{}, error) { return system.GetMemoryInfo() } // GetDiskInfo 获取磁盘信息 func (a *App) GetDiskInfo() ([]map[string]interface{}, error) { return system.GetDiskInfo() } func (a *App) GetLocalSystemInfo() (map[string]interface{}, error) { info := make(map[string]interface{}) cpuInfo, err := system.GetCPUInfo() if err == nil && cpuInfo != nil { if v, ok := cpuInfo["usage"].(string); ok { info["cpu_usage"] = v } } memInfo, err := system.GetMemoryInfo() if err == nil && memInfo != nil { if v, ok := memInfo["usage"].(string); ok { info["mem_usage"] = v } } diskInfos, err := system.GetDiskInfo() if err == nil && len(diskInfos) > 0 { if v, ok := diskInfos[0]["usage"].(string); ok { info["disk_usage"] = v } } return info, nil } // GetCommonPaths 获取常用系统路径 func (a *App) GetCommonPaths() (map[string]string, error) { homeDir, err := os.UserHomeDir() if err != nil { return nil, err } paths := map[string]string{ "home": homeDir, } for k, v := range resolveFolderPaths(homeDir) { paths[k] = v } return paths, nil } // GetEnvVars 获取环境变量 func (a *App) GetEnvVars() (map[string]string, error) { envVars := make(map[string]string) for _, env := range os.Environ() { if key, value, found := strings.Cut(env, "="); found { envVars[key] = value } } return envVars, nil }