package main import ( "embed" "fmt" "os" "strconv" "strings" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" ) //go:embed all:frontend/dist var assets embed.FS func main() { noGUI, port, help := parseSysmonArgs() if help { printHelp() os.Exit(0) } if noGUI { runServer(port) return } // Create an instance of the app structure app := NewApp() // Create application with options err := wails.Run(&options.App{ Title: "sysmon", Width: 1024, Height: 768, AssetServer: &assetserver.Options{ Assets: assets, }, BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1}, OnStartup: app.startup, Bind: []interface{}{ app, }, }) if err != nil { println("Error:", err.Error()) } } // parseSysmonArgs scans os.Args manually so we don't call flag.Parse(), // which would conflict with flags that Wails injects in dev mode (e.g. -assetdir). func parseSysmonArgs() (noGUI bool, port int, help bool) { port = 9731 args := os.Args[1:] for i := 0; i < len(args); i++ { arg := args[i] switch arg { case "--no-gui": noGUI = true case "--help", "-h": help = true case "--port": if i+1 < len(args) { i++ if p, err := strconv.Atoi(args[i]); err == nil && p > 0 && p <= 65535 { port = p } } default: if strings.HasPrefix(arg, "--port=") { if p, err := strconv.Atoi(strings.TrimPrefix(arg, "--port=")); err == nil && p > 0 && p <= 65535 { port = p } } } } return } func printHelp() { fmt.Print(`sysmon — system monitor Usage: sysmon Launch with graphical interface (default) sysmon --no-gui Run as headless HTTP API server (port 9731) sysmon --no-gui --port N Run server on port N Options: --no-gui Start without GUI, expose HTTP API instead --port HTTP server port (default: 9731, requires --no-gui) --help, -h Show this help Server endpoints (--no-gui mode): GET /api/metrics Latest metrics snapshot (JSON) GET /api/metrics/stream Server-Sent Events stream (1 s interval) GET /api/process/ Process detail (JSON) POST /api/process//kill Kill process (?force=true → SIGKILL) GET /api/man/ Manual page for a command `) }