Skip to content

Commit

Permalink
Remove double namespacing from alfred ns
Browse files Browse the repository at this point in the history
Much more conventional to have alfred.Item instead of alfred.alfredItem
  • Loading branch information
sheelc committed Jul 28, 2017
1 parent bb4a1b6 commit 9b14a8c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
38 changes: 19 additions & 19 deletions alfred/alfred.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ import (
"fmt"
)

type AlfredIcon struct {
type Icon struct {
Type string `json:"type,omitempty"`
Path string `json:"path,omitempty"`
}

type AlfredMod struct {
type Mod struct {
Valid bool `json:"valid,omitempty"`
Arg string `json:"arg,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
}

type AlfredMods struct {
Ctrl AlfredMod `json:"ctrl,omitempty"`
Alt AlfredMod `json:"alt,omitempty"`
Cmd AlfredMod `json:"cmd,omitempty"`
type Mods struct {
Ctrl Mod `json:"ctrl,omitempty"`
Alt Mod `json:"alt,omitempty"`
Cmd Mod `json:"cmd,omitempty"`
}

type AlfredItem struct {
Uid string `json:"uid,omitempty"`
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Arg string `json:"arg,omitempty"`
Autocomplete string `json:"autocomplete,omitempty"`
Valid *bool `json:"valid,omitempty"`
Icon AlfredIcon `json:"icon,omitempty"`
Mods AlfredMods `json:"mods,omitempty"`
type Item struct {
Uid string `json:"uid,omitempty"`
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Arg string `json:"arg,omitempty"`
Autocomplete string `json:"autocomplete,omitempty"`
Valid *bool `json:"valid,omitempty"`
Icon Icon `json:"icon,omitempty"`
Mods Mods `json:"mods,omitempty"`
}

type AlfredItems struct {
Items []AlfredItem `json:"items"`
type Items struct {
Items []Item `json:"items"`
}

func PrintMenu(items AlfredItems) error {
func PrintMenu(items Items) error {
itemsBytes, err := json.Marshal(items)

if err != nil {
Expand Down
108 changes: 54 additions & 54 deletions menus/menus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const (
)

func SetupAuthMenu() error {
items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "Authenticate to Spot",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/configuration.png",
},
Valid: newFalse(),
Expand All @@ -31,9 +31,9 @@ func SetupAuthMenu() error {
}

func ClientIdMenuInstruction() error {
items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "Paste the Client Id above and press enter",
},
},
Expand All @@ -43,9 +43,9 @@ func ClientIdMenuInstruction() error {
}

func ClientIdMenuStepFinished() error {
items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "The client id is set, press enter to close",
},
},
Expand All @@ -55,9 +55,9 @@ func ClientIdMenuStepFinished() error {
}

func ClientSecretMenuInstruction() error {
items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "Paste the Client Secret above and press enter",
},
},
Expand All @@ -67,9 +67,9 @@ func ClientSecretMenuInstruction() error {
}

func ClientSecretMenuStepFinished() error {
items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "Setup is now complete! Press enter to close",
},
},
Expand All @@ -85,29 +85,29 @@ func StatusMenu(spotifyStatus spotify.Status) error {
playerStatusIcon = "icons/paused.png"
}

items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: spotifyStatus.SongTitle,
Subtitle: fmt.Sprintf("%s by %s", spotifyStatus.Album, spotifyStatus.Artist),
Arg: "-action playpause",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: playerStatusIcon,
},
},
alfred.AlfredItem{
alfred.Item{
Title: spotifyStatus.Artist,
Subtitle: "More from this artist...",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/artist.png",
},
Valid: newFalse(),
Autocomplete: fmt.Sprintf("-artist=\"%s\" ", spotifyStatus.Artist),
},
alfred.AlfredItem{
alfred.Item{
Title: spotifyStatus.Album,
Subtitle: "More from this album...",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/album.png",
},
Valid: newFalse(),
Expand All @@ -127,27 +127,27 @@ func ControlsMenu(spotifyStatus spotify.Status) error {
playerStatusIcon = "icons/paused.png"
}

items := alfred.AlfredItems{
Items: []alfred.AlfredItem{
alfred.AlfredItem{
items := alfred.Items{
Items: []alfred.Item{
alfred.Item{
Title: "Next Track",
Arg: "--action next",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/next.png",
},
},
alfred.AlfredItem{
alfred.Item{
Title: "Previous Track",
Arg: "--action previous",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/previous.png",
},
},
alfred.AlfredItem{
alfred.Item{
Title: spotifyStatus.SongTitle,
Subtitle: fmt.Sprintf("%s by %s", spotifyStatus.Album, spotifyStatus.Artist),
Arg: "--action playpause",
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: playerStatusIcon,
},
},
Expand All @@ -169,31 +169,31 @@ func popularityToMeter(popularity int) string {
return meter
}

func albumItem(album client.SimpleAlbum) alfred.AlfredItem {
return alfred.AlfredItem{
func albumItem(album client.SimpleAlbum) alfred.Item {
return alfred.Item{
Uid: string(album.URI),
Title: album.Name,
Valid: newFalse(),
Autocomplete: fmt.Sprintf("-album=\"%s\" ", album.Name),
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/album.png",
},
Mods: alfred.AlfredMods{
Ctrl: alfred.AlfredMod{
Mods: alfred.Mods{
Ctrl: alfred.Mod{
Arg: fmt.Sprintf("--action revealinspotify --context %s", album.URI),
Subtitle: "Reveal in Spotify",
},
},
}
}

func albumItemWithArtist(album client.SimpleAlbum, artist string) alfred.AlfredItem {
func albumItemWithArtist(album client.SimpleAlbum, artist string) alfred.Item {
item := albumItem(album)
item.Autocomplete = fmt.Sprintf("-artist=\"%s\" -album=\"%s\" ", artist, album.Name)
return item
}

func trackItem(track client.FullTrack, contextType int) alfred.AlfredItem {
func trackItem(track client.FullTrack, contextType int) alfred.Item {
var arg string
if contextType == albumContext {
arg = fmt.Sprintf("--action playtrack --track %s --context %s", track.URI, track.Album.URI)
Expand All @@ -203,35 +203,35 @@ func trackItem(track client.FullTrack, contextType int) alfred.AlfredItem {
arg = fmt.Sprintf("--action playtrack --track %s", track.URI)
}

return alfred.AlfredItem{
return alfred.Item{
Uid: string(track.URI),
Title: track.Name,
Subtitle: popularityToMeter(track.Popularity),
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/track.png",
},
Arg: arg,
Mods: alfred.AlfredMods{
Ctrl: alfred.AlfredMod{
Mods: alfred.Mods{
Ctrl: alfred.Mod{
Arg: fmt.Sprintf("--action revealinspotify --context %s", track.URI),
Subtitle: "Reveal in Spotify",
},
},
}
}

func artistItem(artist client.FullArtist) alfred.AlfredItem {
return alfred.AlfredItem{
func artistItem(artist client.FullArtist) alfred.Item {
return alfred.Item{
Uid: string(artist.URI),
Title: artist.Name,
Subtitle: popularityToMeter(artist.Popularity),
Icon: alfred.AlfredIcon{
Icon: alfred.Icon{
Path: "icons/artist.png",
},
Valid: newFalse(),
Autocomplete: fmt.Sprintf("-artist=\"%s\" ", artist.Name),
Mods: alfred.AlfredMods{
Ctrl: alfred.AlfredMod{
Mods: alfred.Mods{
Ctrl: alfred.Mod{
Arg: fmt.Sprintf("--action revealinspotify --context %s", artist.URI),
Subtitle: "Reveal in Spotify",
},
Expand All @@ -252,14 +252,14 @@ func AlbumDetailMenu(album string, args []string) error {
}

tracks := searchResults.Tracks.Tracks
items := make([]alfred.AlfredItem, 0, len(tracks))
items := make([]alfred.Item, 0, len(tracks))

for _, track := range tracks {
items = append(items, trackItem(track, albumContext))

}

alfredItems := alfred.AlfredItems{
alfredItems := alfred.Items{
Items: items,
}

Expand All @@ -280,7 +280,7 @@ func ArtistDetailMenu(artist string, args []string) error {

albums := searchResults.Albums.Albums
tracks := searchResults.Tracks.Tracks
items := make([]alfred.AlfredItem, 0, len(albums)+len(tracks))
items := make([]alfred.Item, 0, len(albums)+len(tracks))

for _, track := range tracks {
items = append(items, trackItem(track, artistContext))
Expand All @@ -292,7 +292,7 @@ func ArtistDetailMenu(artist string, args []string) error {

}

alfredItems := alfred.AlfredItems{
alfredItems := alfred.Items{
Items: items,
}

Expand All @@ -314,7 +314,7 @@ func SearchMenu(args []string) error {
albums := searchResults.Albums.Albums
tracks := searchResults.Tracks.Tracks
artists := searchResults.Artists.Artists
items := make([]alfred.AlfredItem, 0, len(albums)+len(tracks)+len(artists))
items := make([]alfred.Item, 0, len(albums)+len(tracks)+len(artists))

for _, track := range tracks {
items = append(items, trackItem(track, artistContext))
Expand All @@ -331,7 +331,7 @@ func SearchMenu(args []string) error {

}

alfredItems := alfred.AlfredItems{
alfredItems := alfred.Items{
Items: items,
}

Expand Down

0 comments on commit 9b14a8c

Please sign in to comment.