From 08b8b0aabce8f3877b6a90e3f0a7d61524ab707d Mon Sep 17 00:00:00 2001 From: Grigory Date: Sun, 29 Oct 2023 18:37:13 +0500 Subject: [PATCH] feat(path-utils): try to find custom app folder with `index.js` (#2604) --- src/utils/path-utils.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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 }