-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
76 lines (60 loc) · 1.83 KB
/
Copy pathapp.go
File metadata and controls
76 lines (60 loc) · 1.83 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
package main
import (
"context"
)
// version is the application version. It is overridden at build time via
// -ldflags "-X main.version=x.y.z"; CI stamps the same value into wails.json.
var version = "dev"
// App is the Wails-bound application object.
type App struct {
ctx context.Context
}
// GetVersion returns the build version so the UI can display it instead of a
// hardcoded string that drifts from the released package/registry version.
func (a *App) GetVersion() string {
return version
}
// NewApp creates a new App application struct.
func NewApp() *App {
return &App{}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// ---- Service queries ----
// ListServices returns every Windows service with its current state.
func (a *App) ListServices() ([]ServiceInfo, error) {
return listServices()
}
// ---- Service actions (batched) ----
func (a *App) StartServices(names []string) []ActionResult {
return runBatch(names, startService)
}
func (a *App) StopServices(names []string) []ActionResult {
return runBatch(names, stopService)
}
func (a *App) RestartServices(names []string) []ActionResult {
return runBatch(names, restartService)
}
// SetStartType sets the startup type ("auto", "manual" or "disabled") for the
// given services.
func (a *App) SetStartType(names []string, startType string) []ActionResult {
value, err := startTypeValue(startType)
if err != nil {
results := make([]ActionResult, 0, len(names))
for _, n := range names {
results = append(results, ActionResult{Name: n, OK: false, Error: err.Error()})
}
return results
}
return runBatch(names, func(name string) error {
return setStartType(name, value)
})
}
// ---- Config / custom views ----
func (a *App) GetConfig() (Config, error) {
return loadConfig()
}
func (a *App) SaveConfig(cfg Config) error {
return saveConfig(cfg)
}