simplify profiles

This commit is contained in:
Celogeek 2024-05-10 18:05:51 +02:00
parent 113e7ebcb0
commit 5c7775cd47
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
2 changed files with 7 additions and 13 deletions

View File

@ -330,7 +330,7 @@ func (o *Options) SaveConfig() error {
// GetProfile shortcut to get current profile
func (o *Options) GetProfile() *profiles.Profile {
return o.profiles.Get(o.Profile)
return o.profiles[o.Profile]
}
// AvailableProfiles all available profiles

View File

@ -13,11 +13,12 @@ type Profile struct {
Height int `json:"height"`
}
type Profiles []Profile
type Profiles map[string]*Profile
// New Initialize list of all supported profiles.
func New() Profiles {
return []Profile{
res := make(Profiles)
for _, r := range []Profile{
// High Resolution for Tablet
{"HR", "High Resolution", 2400, 3840},
{"SR", "Standard Resolution", 1200, 1920},
@ -50,7 +51,10 @@ func New() Profiles {
// reMarkable
{"RM1", "reMarkable 1", 1404, 1872},
{"RM2", "reMarkable 2", 1404, 1872},
} {
res[r.Code] = &r
}
return res
}
func (p Profiles) String() string {
@ -65,13 +69,3 @@ func (p Profiles) String() string {
}
return strings.Join(s, "\n")
}
// Get Lookup profile by code
func (p Profiles) Get(name string) *Profile {
for _, profile := range p {
if profile.Code == name {
return &profile
}
}
return nil
}