package main import ( "context" "fmt" "sysmon/backend" ) // App struct type App struct { ctx context.Context sys *backend.SysInfo } // NewApp creates a new App application struct func NewApp() *App { return &App{} } // startup is called when the app starts. The context is saved // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx a.InitBackend(ctx) } // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) } // Initialise backend SysInfo on startup and expose its methods func (a *App) InitBackend(ctx context.Context) { if ctx == nil { ctx = context.Background() } a.ctx = ctx a.sys = backend.NewSysInfo(a.ctx) } // GetMetrics proxies to backend.SysInfo.GetMetrics func (a *App) GetMetrics() (*backend.Metrics, error) { if a.sys == nil { a.InitBackend(a.ctx) } return a.sys.GetMetrics() } // GetProcessDetail returns all available details for the given PID. func (a *App) GetProcessDetail(pid int32) (*backend.ProcessDetail, error) { return backend.FetchProcessDetail(pid) } // KillProcess terminates a process by PID. Set force=true for SIGKILL. func (a *App) KillProcess(pid int32, force bool) error { return backend.KillProcess(pid, force) }