Skip to content

Commit

Permalink
check if other icons exist within app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 12, 2024
1 parent 77eb3d3 commit db17f00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (deflated *DeflatedAppImage) ExtractMetadata() (*DeflatedAppImageMetadata,
return nil, err
}
desktopPath := path.Join(deflated.AppDir, fmt.Sprintf("%s.desktop", execName))
iconPath := path.Join(deflated.AppDir, ".DirIcon")
_, iconPath := utils.FindFileInDir(deflated.AppDir, []string{
".DirIcon",
fmt.Sprintf("%s.png", execName),
fmt.Sprintf("%s.jpg", execName),
})
metadata := &DeflatedAppImageMetadata{
DeflatedAppImage: deflated,
ExecName: execName,
Expand All @@ -72,13 +76,12 @@ func (deflated *DeflatedAppImage) ExtractExecName() (string, error) {
}

func (metadata *DeflatedAppImageMetadata) CopyIconFile(paths *AppPaths) error {
if metadata.IconPath == "" {
return nil
}
src, err := os.Open(metadata.IconPath)
if err != nil {
pngPath := path.Join(metadata.AppDir, fmt.Sprintf("%s.png", metadata.ExecName))
src, err = os.Open(pngPath)
if err != nil {
return err
}
return err
}
defer src.Close()
dest, err := os.Create(paths.Icon)
Expand Down
10 changes: 10 additions & 0 deletions utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ func WriteJsonFileAtomic[T any](name string, data *T) error {
}
return WriteFileAtomic(name, json)
}

func FindFileInDir(dir string, names []string) (bool, string) {
for _, x := range names {
p := path.Join(dir, x)
if _, err := os.Lstat(p); err == nil {
return true, p
}
}
return false, ""
}

0 comments on commit db17f00

Please sign in to comment.