-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
115 lines (95 loc) · 2.53 KB
/
app.go
File metadata and controls
115 lines (95 loc) · 2.53 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
package main
import (
"context"
"nvidia-color-control/display"
)
// App struct
type App struct {
ctx context.Context
store *ProfileStore
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{
store: NewProfileStore(),
}
}
// startup is called when the app starts
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
display.GetHelperDir()
}
// shutdown is called when the app is closing — reset display to default
func (a *App) shutdown(ctx context.Context) {
display.ResetToDefault()
display.CleanupHelpers()
}
// --- Display bindings ---
// GetDisplays returns all detected displays
func (a *App) GetDisplays() ([]display.DisplayInfo, error) {
return display.ListDisplays()
}
// --- Profile CRUD bindings ---
// GetProfiles returns all saved profiles
func (a *App) GetProfiles() ([]Profile, error) {
return a.store.LoadProfiles()
}
// SaveProfile updates an existing profile
func (a *App) SaveProfile(profile Profile) error {
return a.store.UpdateProfile(profile)
}
// AddProfile creates a new profile
func (a *App) AddProfile(name string, icon string) (*Profile, error) {
return a.store.AddProfile(name, icon)
}
// DeleteProfile deletes a profile by ID
func (a *App) DeleteProfile(id string) error {
return a.store.DeleteProfile(id)
}
// DuplicateProfile duplicates a profile
func (a *App) DuplicateProfile(id string) (*Profile, error) {
return a.store.DuplicateProfile(id)
}
// --- Display control bindings ---
// ApplyProfile applies a profile's display settings to the specified display
func (a *App) ApplyProfile(profile Profile, displayIdx int) error {
if profile.ID == "default" {
return a.ResetDisplay(displayIdx)
}
err := display.ApplySettings(
displayIdx,
profile.Gamma,
profile.Contrast/50.0,
profile.Red,
profile.Green,
profile.Blue,
profile.Brightness-50,
)
if err != nil {
return err
}
if display.IsVibranceAvailable() {
// UI scale from 50 (default) to 100 (max) corresponds to NVAPI 0 to 63.
if profile.Vibrance < 50 {
profile.Vibrance = 50
}
v := int(float64(profile.Vibrance-50) * 63.0 / 50.0)
_ = display.SetVibrance(v)
}
return nil
}
// ResetDisplay resets a specific display to default settings
func (a *App) ResetDisplay(displayIdx int) error {
err := display.ResetDisplay(displayIdx)
if err != nil {
return err
}
if display.IsVibranceAvailable() {
_ = display.SetVibrance(0)
}
return nil
}
// IsVibranceAvailable checks if digital vibrance control is available
func (a *App) IsVibranceAvailable() bool {
return display.IsVibranceAvailable()
}