From 405f9fb5530798f322d5e239b938e81254269bbb Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 9 Oct 2022 17:53:37 +0800 Subject: [PATCH] change: go ios apps --- hrp/cmd/ios/apps.go | 44 ++++++++++++++++++++++++++++++++------------ hrp/cmd/root.go | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/hrp/cmd/ios/apps.go b/hrp/cmd/ios/apps.go index 5021a422..a77f74c7 100644 --- a/hrp/cmd/ios/apps.go +++ b/hrp/cmd/ios/apps.go @@ -2,12 +2,18 @@ package ios import ( "fmt" - "strings" - "github.com/pkg/errors" + giDevice "github.com/electricbubble/gidevice" + "github.com/mitchellh/mapstructure" "github.com/spf13/cobra" ) +type Application struct { + CFBundleVersion string `json:"version"` + CFBundleDisplayName string `json:"name"` + CFBundleIdentifier string `json:"bundleId"` +} + var listAppsCmd = &cobra.Command{ Use: "apps", Short: "List all iOS installed apps", @@ -17,17 +23,31 @@ var listAppsCmd = &cobra.Command{ return err } - apps, err := device.AppList() - if err != nil { - return errors.Wrap(err, "get ios apps failed") + var applicationType giDevice.ApplicationType + switch appType { + case "user": + applicationType = giDevice.ApplicationTypeUser + case "system": + applicationType = giDevice.ApplicationTypeSystem + case "internal": + applicationType = giDevice.ApplicationTypeInternal + case "all": + applicationType = giDevice.ApplicationTypeAny } - for _, app := range apps { - if appType != "all" && strings.ToLower(app.Type) != appType { - continue - } - fmt.Printf("%-10.10s %-30.30s %-50.50s %-s\n", - app.Type, app.DisplayName, app.CFBundleIdentifier, app.Version) + result, errList := device.InstallationProxyBrowse( + giDevice.WithApplicationType(applicationType), + giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier")) + if errList != nil { + return fmt.Errorf("get app list failed") + } + + for _, app := range result { + a := Application{} + mapstructure.Decode(app, &a) + + fmt.Printf("%-30.30s %-50.50s %-s\n", + a.CFBundleDisplayName, a.CFBundleIdentifier, a.CFBundleVersion) } return nil }, @@ -37,6 +57,6 @@ var appType string func init() { listAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid") - listAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|pluginkit|all]") + listAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|internal|all]") iosRootCmd.AddCommand(listAppsCmd) } diff --git a/hrp/cmd/root.go b/hrp/cmd/root.go index f7572d10..616fd0ab 100644 --- a/hrp/cmd/root.go +++ b/hrp/cmd/root.go @@ -41,7 +41,7 @@ Copyright 2017 debugtalk`, } if !logJSON { log.Logger = zerolog.New(zerolog.ConsoleWriter{NoColor: noColor, Out: os.Stderr}).With().Timestamp().Logger() - log.Info().Msg("Set log to color console other than JSON format.") + log.Info().Msg("Set log to color console") } }, Version: version.VERSION,