Skip to content

Commit

Permalink
feat: add initial support for Dock settings #37
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Sep 5, 2023
1 parent 4835f05 commit 0308e1c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
14 changes: 14 additions & 0 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ func SaveConfig(c *Config) (err error) {
Sort: database.FolderSort(item.TileData.Arrangement),
})
}
conf.Dock.Settings = &database.DockSettings{
AutoHide: dPlist.AutoHide,
LargeSize: dPlist.LargeSize,
Magnification: dPlist.Magnification,
MinimizeToApplication: dPlist.MinimizeToApplication,
MruSpaces: dPlist.MruSpaces,
ShowRecents: dPlist.ShowRecents,
TileSize: dPlist.TileSize,
}

if c.Backup {
c.File += ".bak"
Expand Down Expand Up @@ -568,6 +577,11 @@ func LoadConfig(c *Config) error {
utils.DoubleIndent(log.WithField("other", other).Info)("adding to dock")
dPlist.AddOther(other)
}
if config.Dock.Settings != nil {
if err := dPlist.ApplySettings(*config.Dock.Settings); err != nil {
return fmt.Errorf("failed to apply dock settings: %w", err)
}
}
if err := dPlist.Save(); err != nil {
return fmt.Errorf("failed to save dock plist: %w", err)
}
Expand Down
16 changes: 14 additions & 2 deletions internal/database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ type Folder struct {
Sort FolderSort `yaml:"sort,omitempty" json:"sort,omitempty"`
}

// DockSettings is the launchpad dock settings object
type DockSettings struct {
AutoHide bool `yaml:"autohide" json:"autohide,omitempty"`
LargeSize any `yaml:"largesize" json:"largesize,omitempty"`
Magnification bool `yaml:"magnification" json:"magnification,omitempty"`
MinimizeToApplication bool `yaml:"minimize-to-application" json:"minimize-to-application,omitempty"`
MruSpaces bool `yaml:"mru-spaces" json:"mru-spaces,omitempty"`
ShowRecents bool `yaml:"show-recents" json:"show-recents,omitempty"`
TileSize any `yaml:"tilesize" json:"tilesize,omitempty"`
}

// Dock is the launchpad dock config object
type Dock struct {
Apps []string `yaml:"apps,omitempty" json:"apps,omitempty"`
Others []Folder `yaml:"others,omitempty" json:"others,omitempty"`
Apps []string `yaml:"apps,omitempty" json:"apps,omitempty"`
Others []Folder `yaml:"others,omitempty" json:"others,omitempty"`
Settings *DockSettings `yaml:"settings,omitempty" json:"settings,omitempty"`
}

// LoadConfig loads the Launchpad config from the config file
Expand Down
22 changes: 21 additions & 1 deletion internal/dock/dock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Plist struct {
PersistentApps []PAItem `plist:"persistent-apps"`
PersistentOthers []POItem `plist:"persistent-others"`
AutoHide bool `plist:"autohide"`
Largesize any `plist:"largesize"`
LargeSize any `plist:"largesize"`
Loc string `plist:"loc"`
Magnification bool `plist:"magnification"`
MinimizeToApplication bool `plist:"minimize-to-application"`
Expand Down Expand Up @@ -204,6 +204,26 @@ func (p *Plist) AddOther(other database.Folder) error {
return nil
}

// ApplySettings applies the dock settings to the plist
func (p *Plist) ApplySettings(setting database.DockSettings) error {
p.AutoHide = setting.AutoHide
if setting.LargeSize.(float64) >= 16 && setting.LargeSize.(float64) <= 128 {
p.LargeSize = setting.LargeSize
} else {
return fmt.Errorf("large size must be between 16 and 128: %d", setting.LargeSize)
}
if setting.TileSize.(float64) >= 16 && setting.TileSize.(float64) <= 128 {
p.TileSize = setting.TileSize
} else {
return fmt.Errorf("tile size must be between 16 and 128: %d", setting.TileSize)
}
p.Magnification = setting.Magnification
p.MinimizeToApplication = setting.MinimizeToApplication
p.MruSpaces = setting.MruSpaces
p.ShowRecents = setting.ShowRecents
return nil
}

// Save saves the dock plist from struct
func (p *Plist) Save() error {

Expand Down

0 comments on commit 0308e1c

Please sign in to comment.