Skip to content

Commit

Permalink
feat: support relative paths in dock_items.others #38
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Sep 5, 2023
1 parent 0308e1c commit 1fdfe15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ func SaveConfig(c *Config) (err error) {

log.Infof(bold, "SAVING LAUNCHPAD DATABASE")

home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user home directory: %v", err)
}

// find launchpad database
tmpDir := os.Getenv("TMPDIR")
lpad.Folder = filepath.Join(tmpDir, "../0/com.apple.dock.launchpad/db")
Expand Down Expand Up @@ -398,8 +403,12 @@ func SaveConfig(c *Config) (err error) {
conf.Dock.Apps = append(conf.Dock.Apps, item.TileData.GetPath())
}
for _, item := range dPlist.PersistentOthers {
abspath := item.TileData.GetPath()
if relPath, err := filepath.Rel(home, abspath); err == nil {
abspath = filepath.Join("~", relPath)
}
conf.Dock.Others = append(conf.Dock.Others, database.Folder{
Path: item.TileData.GetPath(),
Path: abspath,
Display: database.FolderDisplay(item.TileData.DisplayAs),
View: database.FolderView(item.TileData.ShowAs),
Sort: database.FolderSort(item.TileData.Arrangement),
Expand Down
6 changes: 5 additions & 1 deletion internal/dock/dock.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (p *Plist) AddApp(appPath string) error {

// AddOther adds an other to the dock plist
func (p *Plist) AddOther(other database.Folder) error {
abspath, err := filepath.Abs(other.Path)
if err != nil {
return fmt.Errorf("failed to get absolute path for '%s': %v", other.Path, err)
}
pother := POItem{
GUID: rand.Intn(9999999999),
TileType: "directory-tile",
Expand All @@ -191,7 +195,7 @@ func (p *Plist) AddOther(other database.Folder) error {
DisplayAs: int(other.Display),
ShowAs: int(other.View),
FileData: FileData{
URLString: other.Path,
URLString: abspath,
URLStringType: 0,
},
FileLabel: fileNameWithoutExtTrimSuffix(other.Path),
Expand Down

0 comments on commit 1fdfe15

Please sign in to comment.