diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 1097ed6430..02e513079b 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -2,6 +2,7 @@ package utils import ( "errors" + "io/ioutil" "os" "path/filepath" "runtime" @@ -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 }