diff --git a/src/commands/clean.go b/src/commands/clean.go index ac644ed..17e8876 100644 --- a/src/commands/clean.go +++ b/src/commands/clean.go @@ -9,7 +9,7 @@ import ( type CleanCmd struct { } -func (cmd *CleanCmd) Run() (err error) { +func (cmd *CleanCmd) Run(debug bool) (err error) { appTempDir, err := utils.MakeTempAppDirPath() if err != nil { return err diff --git a/src/commands/install.go b/src/commands/install.go index 9d12412..1cc4490 100644 --- a/src/commands/install.go +++ b/src/commands/install.go @@ -3,6 +3,7 @@ package commands import ( "bread/src/helpers/repos" "bread/src/helpers/utils" + "github.com/DEVLOPRR/libappimage-go" "errors" "fmt" @@ -16,7 +17,7 @@ type InstallCmd struct { } // Function Which Will Be Called When `install` is the Command. -func (cmd *InstallCmd) Run() (err error) { +func (cmd *InstallCmd) Run(debug bool) (err error) { // Parse The user input repo, err := repos.ParseTarget(cmd.Target) if err != nil { @@ -53,10 +54,10 @@ func (cmd *InstallCmd) Run() (err error) { } // Add The Current Application To The Registry `.registry.json` - cmd.addToRegistry(targetFilePath, repo) + cmd.addToRegistry(targetFilePath, repo, debug) // Integrated The AppImage To Desktop - cmd.createDesktopIntegration(targetFilePath) + cmd.createDesktopIntegration(targetFilePath, debug) // Print Signature Info If Exist. utils.ShowSignature(targetFilePath) @@ -65,19 +66,28 @@ func (cmd *InstallCmd) Run() (err error) { } // Function To Add Installed Program To Registry (Installed App information is stored in here). -func (cmd *InstallCmd) addToRegistry(targetFilePath string, repo repos.Application) { +func (cmd *InstallCmd) addToRegistry(targetFilePath string, repo repos.Application, debug bool) (error) { sha1, _ := utils.GetFileSHA1(targetFilePath) // Get The Sha1 Hash updateInfo, _ := utils.ReadUpdateInfo(targetFilePath) // Get The UpdateInfo if updateInfo == "" { updateInfo = repo.FallBackUpdateInfo() } + appimageInfo, err := getAppImageInfo(targetFilePath, debug) + if err != nil { + return err + } + // Make a new entry struct entry := utils.RegistryEntry{ - FilePath: targetFilePath, Repo: repo.Id(), FileSha1: sha1, + AppName: "", + AppVersion: "", + FilePath: targetFilePath, UpdateInfo: updateInfo, + IsTerminalApp: appimageInfo.IsTerminalApp, + AppImageType: appimageInfo.AppImageType, } registry, _ := utils.OpenRegistry() // Open The Registry @@ -85,17 +95,30 @@ func (cmd *InstallCmd) addToRegistry(targetFilePath string, repo repos.Applicati _ = registry.Add(entry) // Add the entry to registry `.registry.json` _ = registry.Close() // Close the registry } + return nil +} + +func getAppImageInfo(targetFilePath string, debug bool) (*utils.AppImageInfo, error) { + libAppImage, err := libappimagego.NewLibAppImageBindings() // Load the `libappimage` Library For Integration + if err != nil { + return nil, err + } + + return &utils.AppImageInfo{ + IsTerminalApp: libAppImage.IsTerminalApp(targetFilePath), + AppImageType: libAppImage.GetType(targetFilePath, debug), + }, nil } // Function To Integrate The AppImage To Desktop. (Can Only Be Called From InstallCmd Struct) -func (cmd *InstallCmd) createDesktopIntegration(targetFilePath string) { - libAppImage, err := utils.NewLibAppImageBindings() // Load the `libappimage` Library For Integration +func (cmd *InstallCmd) createDesktopIntegration(targetFilePath string, debug bool) { + libAppImage, err := libappimagego.NewLibAppImageBindings() // Load the `libappimage` Library For Integration if err != nil { fmt.Println("Integration failed:", err.Error()) return } - err = libAppImage.Register(targetFilePath) // Register The File + err = libAppImage.Register(targetFilePath, debug) // Register The File if err != nil { fmt.Println("Integration failed: " + err.Error()) } else { diff --git a/src/commands/list.go b/src/commands/list.go index 18a23c7..eccebd8 100644 --- a/src/commands/list.go +++ b/src/commands/list.go @@ -14,7 +14,7 @@ type ListCmd struct { } // Function which will be executed when `list` is called. -func (r *ListCmd) Run() error { +func (r *ListCmd) Run(debug bool) error { registry, err := utils.OpenRegistry() // Open The Registry if err != nil { return err diff --git a/src/commands/remove.go b/src/commands/remove.go index 6d227c2..742403e 100644 --- a/src/commands/remove.go +++ b/src/commands/remove.go @@ -3,6 +3,7 @@ package commands import ( "fmt" "bread/src/helpers/utils" + "github.com/DEVLOPRR/libappimage-go" "os" "strings" ) @@ -13,7 +14,7 @@ type RemoveCmd struct { } // Function which will be executed when `remove` is called. -func (cmd *RemoveCmd) Run() (err error) { +func (cmd *RemoveCmd) Run(debug bool) (err error) { cmd.Target = strings.ToLower(cmd.Target) registry, err := utils.OpenRegistry() // Open The Registry if err != nil { @@ -33,7 +34,7 @@ func (cmd *RemoveCmd) Run() (err error) { return fmt.Errorf("application not found \"" + cmd.Target + "\"") } - err = removeDesktopIntegration(entry.FilePath) // Remove the application desktop integration + err = removeDesktopIntegration(entry.FilePath, debug) // Remove the application desktop integration if err != nil { fmt.Println("Desktop integration removal failed: " + err.Error()) } @@ -52,8 +53,8 @@ func (cmd *RemoveCmd) Run() (err error) { } // Function which will remove the application desktop integration -func removeDesktopIntegration(filePath string) error { - libAppImage, err := utils.NewLibAppImageBindings() +func removeDesktopIntegration(filePath string, debug bool) error { + libAppImage, err := libappimagego.NewLibAppImageBindings() if err != nil { return err } @@ -62,5 +63,5 @@ func removeDesktopIntegration(filePath string) error { return nil } - return libAppImage.Unregister(filePath) + return libAppImage.Unregister(filePath, debug) } diff --git a/src/commands/run.go b/src/commands/run.go index 077fa38..3794a43 100644 --- a/src/commands/run.go +++ b/src/commands/run.go @@ -50,7 +50,7 @@ func executeCmd(target string, arguments []string) { <-doneChan } -func (cmd *RunCmd) Run() (err error) { +func (cmd *RunCmd) Run(debug bool) (err error) { // Parse The user input repo, err := repos.ParseTarget(cmd.Target) if err != nil { diff --git a/src/commands/search.go b/src/commands/search.go index f2bb896..e8b940e 100644 --- a/src/commands/search.go +++ b/src/commands/search.go @@ -12,7 +12,7 @@ type SearchCmd struct { Name string `arg:"" name:"name" help:"name to search for." type:"string"` } -func (cmd *SearchCmd) Run() (error) { +func (cmd *SearchCmd) Run(debug bool) (error) { var err error fmt.Println("Getting Latest List...") err = utils.FetchAppImageListJson() diff --git a/src/commands/update.go b/src/commands/update.go index 69ede1d..14715fb 100644 --- a/src/commands/update.go +++ b/src/commands/update.go @@ -20,7 +20,7 @@ type UpdateCmd struct { var NoUpdateInfo = errors.New("there is no update information") // Function Which Will Be Executed When `update` is called. -func (cmd *UpdateCmd) Run() (err error) { +func (cmd *UpdateCmd) Run(debug bool) (err error) { if cmd.All { // if `update all` cmd.Targets, err = getAllTargets() // Load all the application info into targets if err != nil {