Skip to content

Commit

Permalink
feat(path-utils): try to find custom app folder with index.js (#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila authored Oct 29, 2023
1 parent 84d0cf0 commit 08b8b0a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/utils/path-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -66,16 +67,48 @@ func GetUserFolder(name string) string {
var userAppsFolder = GetUserFolder("CustomApps")
var userExtensionsFolder = GetUserFolder("Extensions")

func GetCustomAppSubfolderPath(folderPath string) string {
entries, err := ioutil.ReadDir(folderPath)
if err != nil {
return ""
}

for _, entry := range entries {
if entry.IsDir() {
subfolderPath := filepath.Join(folderPath, entry.Name())
indexPath := filepath.Join(subfolderPath, "index.js")

if _, err := os.Stat(indexPath); err == nil {
return subfolderPath
}

if subfolderPath := GetCustomAppSubfolderPath(subfolderPath); subfolderPath != "" {
return subfolderPath
}
}
}

return ""
}

func GetCustomAppPath(name string) (string, error) {
customAppFolderPath := filepath.Join(userAppsFolder, name)

if _, err := os.Stat(customAppFolderPath); err == nil {
customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath)
if customAppActualFolderPath != "" {
return customAppActualFolderPath, nil
}
return customAppFolderPath, nil
}

customAppFolderPath = filepath.Join(GetExecutableDir(), "CustomApps", name)

if _, err := os.Stat(customAppFolderPath); err == nil {
customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath)
if customAppActualFolderPath != "" {
return customAppActualFolderPath, nil
}
return customAppFolderPath, nil
}

Expand Down

0 comments on commit 08b8b0a

Please sign in to comment.