diff --git a/internal/app/app.go b/internal/app/app.go index 63da930e..223d06e7 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -201,10 +201,14 @@ func run(c *cli.Context) error { //nolint:funlen func withSingleInstance(locations *locations.Locations, version *semver.Version, fn func() error) error { lock, err := checkSingleInstance(locations.GetLockFile(), version) if err != nil { + logrus.Info("Another instance is already running; raising it") + if ok := focus.TryRaise(); !ok { return fmt.Errorf("another instance is already running but it could not be raised") } + logrus.Info("The other instance has been raised") + return nil } diff --git a/internal/user/user.go b/internal/user/user.go index 9d89fb62..e3d98624 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -42,6 +42,7 @@ import ( "github.com/sirupsen/logrus" "gitlab.protontech.ch/go/liteapi" "golang.org/x/exp/maps" + "golang.org/x/exp/slices" ) var ( @@ -264,10 +265,17 @@ func (user *User) Match(query string) bool { }, user.apiUserLock, user.apiAddrsLock) } -// Emails returns all the user's email addresses via the callback. +// Emails returns all the user's email addresses. +// It returns them in sorted order; the user's primary address is first. func (user *User) Emails() []string { return safe.RLockRet(func() []string { - return xslices.Map(maps.Values(user.apiAddrs), func(addr liteapi.Address) string { + addresses := maps.Values(user.apiAddrs) + + slices.SortFunc(addresses, func(a, b liteapi.Address) bool { + return a.Order < b.Order + }) + + return xslices.Map(addresses, func(addr liteapi.Address) string { return addr.Email }) }, user.apiAddrsLock)