feat: add Wails runtime library and initial application setup
- Created package.json for Wails JavaScript runtime library. - Added TypeScript definitions for runtime functions. - Implemented runtime.js with event handling and logging functions. - Initialized Go module with dependencies for Wails and other libraries. - Added main.go for application entry point and asset embedding. - Configured wails.json for application settings and build commands.
This commit is contained in:
58
app.go
Normal file
58
app.go
Normal file
@@ -0,0 +1,58 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user