-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
119 lines (98 loc) Β· 4.84 KB
/
app.go
File metadata and controls
119 lines (98 loc) Β· 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"context"
"time"
"github.com/user/archtask-pro/internal"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App is the Wails application struct. All exported methods are bound to JS.
type App struct {
ctx context.Context
stopCh chan struct{}
}
// NewApp creates a new App instance.
func NewApp() *App {
return &App{
stopCh: make(chan struct{}),
}
}
// startup is called by the Wails runtime when the app starts.
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// Start real-time metrics streaming at 500ms
go a.streamMetrics()
}
// shutdown is called when the app is about to quit.
func (a *App) shutdown(ctx context.Context) {
close(a.stopCh)
}
// streamMetrics emits hardware metrics to the frontend every 500ms.
func (a *App) streamMetrics() {
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-a.stopCh:
return
case <-ticker.C:
metrics, err := internal.CollectMetrics()
if err == nil {
runtime.EventsEmit(a.ctx, "metrics:update", metrics)
}
}
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// PROCESSES
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GetProcesses returns all running processes grouped into user and system.
func (a *App) GetProcesses() (*internal.ProcessResult, error) {
return internal.GetProcesses()
}
// KillProcesses sends SIGTERM to the given PIDs. Uses pkexec for system PIDs.
func (a *App) KillProcesses(pids []int32, force bool) []internal.KillResult {
return internal.KillProcesses(pids, force)
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// STARTUP APPS
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GetStartupApps scans ~/.config/autostart/ and /etc/xdg/autostart/ for .desktop files.
func (a *App) GetStartupApps() ([]internal.StartupApp, error) {
return internal.GetStartupApps()
}
// ToggleStartupApp enables or disables a startup application by name.
// Disabling adds Hidden=true to the user-level .desktop file.
// Enabling removes that flag (or the override file entirely).
func (a *App) ToggleStartupApp(filePath string, enable bool) error {
return internal.ToggleStartupApp(filePath, enable)
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// SERVICES
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GetServices returns all systemd service units.
func (a *App) GetServices() ([]internal.ServiceInfo, error) {
return internal.GetServices()
}
// ServiceAction performs start/stop/restart/enable/disable on a service.
func (a *App) ServiceAction(serviceName, action string) error {
return internal.ServiceAction(serviceName, action)
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GAMEMODE & CPU GOVERNOR
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GetGameModeStatus checks if gamemoded is installed and running.
func (a *App) GetGameModeStatus() internal.GameModeStatus {
return internal.CheckGameMode()
}
// GetCPUGovernor returns the current CPU frequency scaling governor.
func (a *App) GetCPUGovernor() string {
return string(internal.GetCPUGovernor())
}
// SetCPUGovernor switches the governor for all cores via pkexec + cpupower.
func (a *App) SetCPUGovernor(mode string) error {
return internal.SetCPUGovernor(internal.GovernorMode(mode))
}
// ApplyGameModeToProcess applies GameMode to a given PID.
func (a *App) ApplyGameModeToProcess(pid int32) error {
return internal.ApplyGameModeToProcess(pid)
}