1 Star 0 Fork 0

fanzuquan/oh-my-posh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
segment_spotify.go 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
Jan De Dobbeleer 提交于 2019-03-13 19:14 +08:00 . feat: initial commit
package main
import (
"fmt"
)
type spotify struct {
props *properties
env environmentInfo
status string
artist string
track string
}
const (
//PlayingIcon indicates a song is playing
PlayingIcon Property = "playing_icon"
//PausedIcon indicates a song is paused
PausedIcon Property = "paused_icon"
//TrackSeparator is put between the artist and the track
TrackSeparator Property = "track_separator"
)
func (s *spotify) enabled() bool {
if s.env.getRuntimeGOOS() != "darwin" {
return false
}
var err error
// Check if running
running := s.runAppleScriptCommand("application \"Spotify\" is running")
if running == "false" || running == "" {
return false
}
s.status = s.runAppleScriptCommand("tell application \"Spotify\" to player state as string")
if err != nil {
return false
}
if s.status == "stopped" {
return false
}
s.artist = s.runAppleScriptCommand("tell application \"Spotify\" to artist of current track as string")
s.track = s.runAppleScriptCommand("tell application \"Spotify\" to name of current track as string")
return true
}
func (s *spotify) string() string {
icon := ""
switch s.status {
case "paused":
icon = s.props.getString(PausedIcon, "")
case "playing":
icon = s.props.getString(PlayingIcon, "")
}
separator := s.props.getString(TrackSeparator, " - ")
return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track)
}
func (s *spotify) init(props *properties, env environmentInfo) {
s.props = props
s.env = env
}
func (s *spotify) runAppleScriptCommand(command string) string {
return s.env.runCommand("osascript", "-e", command)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fanzuquan/oh-my-posh.git
git@gitee.com:fanzuquan/oh-my-posh.git
fanzuquan
oh-my-posh
oh-my-posh
v3.15.0

搜索帮助