/
lastfm.go
62 lines (53 loc) · 1.39 KB
/
lastfm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ui
import (
"fmt"
"github.com/anhoder/foxful-cli/model"
"github.com/go-musicfox/spotifox/internal/storage"
"github.com/go-musicfox/spotifox/utils/locale"
"github.com/skratchdot/open-golang/open"
)
type Lastfm struct {
baseMenu
auth *LastfmAuth
}
func NewLastfm(base baseMenu) *Lastfm {
return &Lastfm{
baseMenu: base,
auth: NewLastfmAuth(base),
}
}
func (m *Lastfm) GetMenuKey() string {
return "last_fm"
}
func (m *Lastfm) MenuViews() []model.MenuItem {
if m.spotifox.lastfmUser == nil || m.spotifox.lastfmUser.SessionKey == "" {
return []model.MenuItem{
{Title: locale.MustT("to_auth")},
}
}
return []model.MenuItem{
{Title: locale.MustT("view_user_info")},
{Title: locale.MustT("clear_auth")},
}
}
func (m *Lastfm) SubMenu(_ *model.App, index int) model.Menu {
if m.spotifox.lastfmUser == nil || m.spotifox.lastfmUser.SessionKey == "" {
return m.auth
}
switch index {
case 0:
_ = open.Start(m.spotifox.lastfmUser.Url)
case 1:
m.spotifox.lastfmUser = &storage.LastfmUser{}
m.spotifox.lastfmUser.Clear()
return NewLastfmRes(m.baseMenu, locale.MustT("clear_auth"), nil, 2)
}
return nil
}
func (m *Lastfm) FormatMenuItem(item *model.MenuItem) {
if m.spotifox.lastfmUser == nil || m.spotifox.lastfmUser.SessionKey == "" {
item.Subtitle = "[" + locale.MustT("unauth") + "]"
} else {
item.Subtitle = fmt.Sprintf("[%s]", m.spotifox.lastfmUser.Name)
}
}