mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-07 02:42:50 +08:00
rewrite using IoC and DI
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/model"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -26,16 +25,33 @@ func (b *bascicConfig) CreatePanel() fyne.CanvasObject {
|
||||
if b.panel != nil {
|
||||
return b.panel
|
||||
}
|
||||
|
||||
randomPlaylist := container.NewHBox(
|
||||
widget.NewLabel(i18n.T("gui.config.basic.random_playlist")),
|
||||
widget.NewCheckWithData(
|
||||
newCheckInit(
|
||||
i18n.T("gui.config.basic.random_playlist.user"),
|
||||
binding.BindBool(&controller.UserPlaylist.Config.RandomNext)),
|
||||
widget.NewCheckWithData(
|
||||
func(b bool) {
|
||||
l().Infof("Set random playlist for user: %t", b)
|
||||
if b {
|
||||
controller.Instance.Playlists().GetCurrent().Model().Mode = model.PlaylistModeRandom
|
||||
} else {
|
||||
controller.Instance.Playlists().GetCurrent().Model().Mode = model.PlaylistModeNormal
|
||||
}
|
||||
},
|
||||
controller.Instance.Playlists().GetCurrent().Model().Mode == model.PlaylistModeRandom),
|
||||
newCheckInit(
|
||||
i18n.T("gui.config.basic.random_playlist.system"),
|
||||
binding.BindBool(&controller.SystemPlaylist.Config.RandomNext)),
|
||||
func(b bool) {
|
||||
l().Infof("Set random playlist for system: %t", b)
|
||||
if b {
|
||||
controller.Instance.Playlists().GetDefault().Model().Mode = model.PlaylistModeRandom
|
||||
} else {
|
||||
controller.Instance.Playlists().GetDefault().Model().Mode = model.PlaylistModeNormal
|
||||
}
|
||||
},
|
||||
controller.Instance.Playlists().GetDefault().Model().Mode == model.PlaylistModeRandom),
|
||||
)
|
||||
devices := controller.GetAudioDevices()
|
||||
devices := controller.Instance.PlayControl().GetAudioDevices()
|
||||
deviceDesc := make([]string, len(devices))
|
||||
deviceDesc2Name := make(map[string]string)
|
||||
for i, device := range devices {
|
||||
@@ -43,17 +59,20 @@ func (b *bascicConfig) CreatePanel() fyne.CanvasObject {
|
||||
deviceDesc2Name[device.Description] = device.Name
|
||||
}
|
||||
deviceSel := widget.NewSelect(deviceDesc, func(s string) {
|
||||
controller.SetAudioDevice(deviceDesc2Name[s])
|
||||
controller.Instance.PlayControl().SetAudioDevice(deviceDesc2Name[s])
|
||||
})
|
||||
deviceSel.Selected = config.Player.AudioDevice
|
||||
deviceSel.Selected = controller.Instance.PlayControl().GetCurrentAudioDevice()
|
||||
outputDevice := container.NewBorder(nil, nil,
|
||||
widget.NewLabel(i18n.T("gui.config.basic.audio_device")), nil,
|
||||
deviceSel)
|
||||
skipPlaylist := container.NewHBox(
|
||||
widget.NewLabel(i18n.T("gui.config.basic.skip_playlist")),
|
||||
widget.NewCheckWithData(
|
||||
newCheckInit(
|
||||
i18n.T("gui.config.basic.skip_playlist.prompt"),
|
||||
binding.BindBool(&config.Player.SkipPlaylist),
|
||||
func(b bool) {
|
||||
controller.Instance.PlayControl().SetSkipPlaylist(b)
|
||||
},
|
||||
controller.Instance.PlayControl().GetSkipPlaylist(),
|
||||
),
|
||||
)
|
||||
b.panel = container.NewVBox(randomPlaylist, outputDevice, skipPlaylist)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/common/logger"
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/logger"
|
||||
"AynaLivePlayer/resource"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/model"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
@@ -80,7 +81,7 @@ func newFixedSplitContainer(horizontal bool, leading, trailing fyne.CanvasObject
|
||||
return fs
|
||||
}
|
||||
|
||||
func newImageFromPlayerPicture(picture player.Picture) (*canvas.Image, error) {
|
||||
func newImageFromPlayerPicture(picture model.Picture) (*canvas.Image, error) {
|
||||
if picture.Data != nil {
|
||||
img := canvas.NewImageFromReader(bytes.NewReader(picture.Data), "cover")
|
||||
// return an error when img is nil
|
||||
@@ -104,3 +105,15 @@ func newImageFromPlayerPicture(picture player.Picture) (*canvas.Image, error) {
|
||||
return img, nil
|
||||
}
|
||||
}
|
||||
|
||||
func showDialogIfError(err error) {
|
||||
if err != nil {
|
||||
dialog.ShowError(err, MainWindow)
|
||||
}
|
||||
}
|
||||
|
||||
func newCheckInit(name string, changed func(bool), checked bool) *widget.Check {
|
||||
check := widget.NewCheck(name, changed)
|
||||
check.SetChecked(checked)
|
||||
return check
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/event"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/event"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/model"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var History = &struct {
|
||||
Playlist *player.Playlist
|
||||
Playlist *model.Playlist
|
||||
List *widget.List
|
||||
mux sync.RWMutex
|
||||
}{}
|
||||
|
||||
func createHistoryList() fyne.CanvasObject {
|
||||
History.Playlist = controller.History
|
||||
History.Playlist = controller.Instance.Playlists().GetHistory().Model().Copy()
|
||||
History.List = widget.NewList(
|
||||
func() int {
|
||||
return History.Playlist.Size()
|
||||
@@ -36,7 +38,7 @@ func createHistoryList() fyne.CanvasObject {
|
||||
newLabelWithWrapping("user", fyne.TextTruncate)))
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
m := History.Playlist.Playlist[History.Playlist.Size()-id-1]
|
||||
m := History.Playlist.Medias[History.Playlist.Size()-id-1].Copy()
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Label).SetText(
|
||||
m.Title)
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Label).SetText(
|
||||
@@ -45,11 +47,12 @@ func createHistoryList() fyne.CanvasObject {
|
||||
m.ToUser().Name)
|
||||
object.(*fyne.Container).Objects[1].(*widget.Label).SetText(fmt.Sprintf("%d", id))
|
||||
btns := object.(*fyne.Container).Objects[2].(*fyne.Container).Objects
|
||||
m.User = controller.HistoryUser
|
||||
btns[0].(*widget.Button).OnTapped = func() {
|
||||
controller.Play(controller.ToHistoryMedia(m))
|
||||
controller.Instance.PlayControl().Play(m)
|
||||
}
|
||||
btns[1].(*widget.Button).OnTapped = func() {
|
||||
controller.UserPlaylist.Push(controller.ToHistoryMedia(m))
|
||||
controller.Instance.Playlists().GetCurrent().Push(m)
|
||||
}
|
||||
})
|
||||
registerHistoryHandler()
|
||||
@@ -66,9 +69,10 @@ func createHistoryList() fyne.CanvasObject {
|
||||
}
|
||||
|
||||
func registerHistoryHandler() {
|
||||
History.Playlist.Handler.RegisterA(player.EventPlaylistUpdate, "gui.history.update", func(event *event.Event) {
|
||||
History.Playlist.Lock.RLock()
|
||||
controller.Instance.Playlists().GetHistory().EventManager().RegisterA(model.EventPlaylistUpdate, "gui.history.update", func(event *event.Event) {
|
||||
History.mux.RLock()
|
||||
History.Playlist = event.Data.(model.PlaylistUpdateEvent).Playlist
|
||||
History.List.Refresh()
|
||||
History.Playlist.Lock.RUnlock()
|
||||
History.mux.RUnlock()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/event"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/common/util"
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/event"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/util"
|
||||
"AynaLivePlayer/model"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/aynakeya/go-mpv"
|
||||
)
|
||||
|
||||
type PlayControllerContainer struct {
|
||||
@@ -76,13 +75,13 @@ func createPlayController() fyne.CanvasObject {
|
||||
|
||||
func registerPlayControllerHandler() {
|
||||
PlayController.ButtonPrev.OnTapped = func() {
|
||||
controller.Seek(0, true)
|
||||
controller.Instance.PlayControl().Seek(0, true)
|
||||
}
|
||||
PlayController.ButtonSwitch.OnTapped = func() {
|
||||
controller.Toggle()
|
||||
controller.Instance.PlayControl().Toggle()
|
||||
}
|
||||
PlayController.ButtonNext.OnTapped = func() {
|
||||
controller.PlayNext()
|
||||
controller.Instance.PlayControl().PlayNext()
|
||||
}
|
||||
|
||||
PlayController.ButtonLrc.OnTapped = func() {
|
||||
@@ -92,94 +91,104 @@ func registerPlayControllerHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("pause", func(property *mpv.EventProperty) {
|
||||
if property.Data == nil {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPlayIcon()
|
||||
return
|
||||
}
|
||||
if property.Data.(mpv.Node).Value.(bool) {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPlayIcon()
|
||||
} else {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPauseIcon()
|
||||
}
|
||||
}) != nil {
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropPause, "gui.play_controller.pause", func(ev *event.Event) {
|
||||
data := ev.Data.(model.PlayerPropertyUpdateEvent).Value
|
||||
if data == nil {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPlayIcon()
|
||||
return
|
||||
}
|
||||
if data.(bool) {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPlayIcon()
|
||||
} else {
|
||||
PlayController.ButtonSwitch.Icon = theme.MediaPauseIcon()
|
||||
}
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for switch button with property pause")
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("percent-pos", func(property *mpv.EventProperty) {
|
||||
if property.Data == nil {
|
||||
PlayController.Progress.Value = 0
|
||||
} else {
|
||||
PlayController.Progress.Value = property.Data.(mpv.Node).Value.(float64) * 10
|
||||
}
|
||||
PlayController.Progress.Refresh()
|
||||
}) != nil {
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropPercentPos, "gui.play_controller.percent_pos", func(ev *event.Event) {
|
||||
data := ev.Data.(model.PlayerPropertyUpdateEvent).Value
|
||||
if data == nil {
|
||||
PlayController.Progress.Value = 0
|
||||
} else {
|
||||
PlayController.Progress.Value = data.(float64) * 10
|
||||
}
|
||||
PlayController.Progress.Refresh()
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for progress bar with property percent-pos")
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("idle-active", func(property *mpv.EventProperty) {
|
||||
isIdle := property.Data.(mpv.Node).Value.(bool)
|
||||
l().Debug("receive idle active ", isIdle, " set/reset info")
|
||||
// todo: @3
|
||||
if isIdle {
|
||||
PlayController.Progress.Value = 0
|
||||
PlayController.Progress.Max = 0
|
||||
//PlayController.Title.SetText("Title")
|
||||
//PlayController.Artist.SetText("Artist")
|
||||
//PlayController.Username.SetText("Username")
|
||||
//PlayController.SetDefaultCover()
|
||||
} else {
|
||||
PlayController.Progress.Max = 1000
|
||||
}
|
||||
}) != nil {
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropIdleActive, "gui.play_controller.idle_active", func(ev *event.Event) {
|
||||
isIdle := ev.Data.(model.PlayerPropertyUpdateEvent).Value.(bool)
|
||||
l().Debug("receive idle active ", isIdle, " set/reset info")
|
||||
// todo: @3
|
||||
if isIdle {
|
||||
PlayController.Progress.Value = 0
|
||||
PlayController.Progress.Max = 0
|
||||
//PlayController.Title.SetText("Title")
|
||||
//PlayController.Artist.SetText("Artist")
|
||||
//PlayController.Username.SetText("Username")
|
||||
//PlayController.SetDefaultCover()
|
||||
} else {
|
||||
PlayController.Progress.Max = 1000
|
||||
}
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for progress bar with property idle-active")
|
||||
}
|
||||
|
||||
PlayController.Progress.Max = 0
|
||||
PlayController.Progress.OnChanged = func(f float64) {
|
||||
controller.Seek(f/10, false)
|
||||
controller.Instance.PlayControl().Seek(f/10, false)
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("time-pos", func(property *mpv.EventProperty) {
|
||||
if property.Data == nil {
|
||||
PlayController.CurrentTime.SetText("0:00")
|
||||
return
|
||||
}
|
||||
PlayController.CurrentTime.SetText(util.FormatTime(int(property.Data.(mpv.Node).Value.(float64))))
|
||||
}) != nil {
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropTimePos, "gui.play_controller.time_pos", func(ev *event.Event) {
|
||||
data := ev.Data.(model.PlayerPropertyUpdateEvent).Value
|
||||
if data == nil {
|
||||
PlayController.CurrentTime.SetText("0:00")
|
||||
return
|
||||
}
|
||||
PlayController.CurrentTime.SetText(util.FormatTime(int(data.(float64))))
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for current time with property time-pos")
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("duration", func(property *mpv.EventProperty) {
|
||||
if property.Data == nil {
|
||||
PlayController.TotalTime.SetText("0:00")
|
||||
return
|
||||
}
|
||||
PlayController.TotalTime.SetText(util.FormatTime(int(property.Data.(mpv.Node).Value.(float64))))
|
||||
}) != nil {
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropDuration, "gui.play_controller.duration", func(ev *event.Event) {
|
||||
data := ev.Data.(model.PlayerPropertyUpdateEvent).Value
|
||||
if data == nil {
|
||||
PlayController.TotalTime.SetText("0:00")
|
||||
return
|
||||
}
|
||||
PlayController.TotalTime.SetText(util.FormatTime(int(data.(float64))))
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for total time with property duration")
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("volume", func(property *mpv.EventProperty) {
|
||||
l().Trace("receive volume change event", *property)
|
||||
if property.Data == nil {
|
||||
PlayController.Volume.Value = 0
|
||||
} else {
|
||||
PlayController.Volume.Value = property.Data.(mpv.Node).Value.(float64)
|
||||
}
|
||||
if controller.Instance.PlayControl().GetPlayer().ObserveProperty(
|
||||
model.PlayerPropVolume, "gui.play_controller.volume", func(ev *event.Event) {
|
||||
data := ev.Data.(model.PlayerPropertyUpdateEvent).Value
|
||||
if data == nil {
|
||||
PlayController.Volume.Value = 0
|
||||
} else {
|
||||
PlayController.Volume.Value = data.(float64)
|
||||
}
|
||||
|
||||
PlayController.Volume.Refresh()
|
||||
}) != nil {
|
||||
PlayController.Volume.Refresh()
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for progress bar with property percent-pos")
|
||||
}
|
||||
|
||||
PlayController.Volume.OnChanged = func(f float64) {
|
||||
controller.SetVolume(f)
|
||||
controller.Instance.PlayControl().SetVolume(f)
|
||||
}
|
||||
|
||||
controller.MainPlayer.EventHandler.RegisterA(player.EventPlay, "gui.player.updateinfo", func(event *event.Event) {
|
||||
controller.Instance.PlayControl().EventManager().RegisterA(model.EventPlay, "gui.player.updateinfo", func(event *event.Event) {
|
||||
l().Debug("receive EventPlay update player info")
|
||||
media := event.Data.(player.PlayEvent).Media
|
||||
media := event.Data.(model.PlayEvent).Media
|
||||
//PlayController.Title.SetText(
|
||||
// util.StringNormalize(media.Title, 16, 16))
|
||||
//PlayController.Artist.SetText(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/event"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/event"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/model"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
@@ -16,9 +16,9 @@ func createLyricWindow() fyne.Window {
|
||||
w := App.NewWindow("Lyric")
|
||||
currentLrc := newLabelWithWrapping("", fyne.TextWrapBreak)
|
||||
currentLrc.Alignment = fyne.TextAlignCenter
|
||||
lrcs := make([]string, len(controller.CurrentLyric.Lyrics))
|
||||
lrcs := make([]string, len(controller.Instance.PlayControl().GetLyric().Get().Lyrics))
|
||||
for i := 0; i < len(lrcs); i++ {
|
||||
lrcs[i] = controller.CurrentLyric.Lyrics[i].Lyric
|
||||
lrcs[i] = controller.Instance.PlayControl().GetLyric().Get().Lyrics[i].Lyric
|
||||
}
|
||||
fullLrc := widget.NewRichTextWithText(strings.Join(lrcs, "\n\n"))
|
||||
fullLrc.Scroll = container.ScrollVerticalOnly
|
||||
@@ -31,30 +31,32 @@ func createLyricWindow() fyne.Window {
|
||||
w.CenterOnScreen()
|
||||
|
||||
// register handlers
|
||||
controller.CurrentLyric.Handler.RegisterA(player.EventLyricUpdate, "player.lyric.current_lyric", func(event *event.Event) {
|
||||
e := event.Data.(player.LyricUpdateEvent)
|
||||
if e.Lyric == nil {
|
||||
currentLrc.SetText("")
|
||||
return
|
||||
}
|
||||
currentLrc.SetText(e.Lyric.Lyric)
|
||||
})
|
||||
controller.CurrentLyric.Handler.RegisterA(player.EventLyricReload, "player.lyric.new_media", func(event *event.Event) {
|
||||
e := event.Data.(player.LyricReloadEvent)
|
||||
lrcs := make([]string, len(e.Lyrics.Lyrics))
|
||||
for i := 0; i < len(lrcs); i++ {
|
||||
lrcs[i] = e.Lyrics.Lyrics[i].Lyric
|
||||
}
|
||||
fullLrc.Segments[0] = &widget.TextSegment{
|
||||
Style: widget.RichTextStyleInline,
|
||||
Text: strings.Join(lrcs, "\n\n"),
|
||||
}
|
||||
fullLrc.Refresh()
|
||||
})
|
||||
controller.Instance.PlayControl().GetLyric().EventManager().RegisterA(
|
||||
model.EventLyricUpdate, "player.lyric.current_lyric", func(event *event.Event) {
|
||||
e := event.Data.(model.LyricUpdateEvent)
|
||||
if e.Lyric == nil {
|
||||
currentLrc.SetText("")
|
||||
return
|
||||
}
|
||||
currentLrc.SetText(e.Lyric.Lyric)
|
||||
})
|
||||
controller.Instance.PlayControl().GetLyric().EventManager().RegisterA(
|
||||
model.EventLyricReload, "player.lyric.new_media", func(event *event.Event) {
|
||||
e := event.Data.(model.LyricReloadEvent)
|
||||
lrcs := make([]string, len(e.Lyrics.Lyrics))
|
||||
for i := 0; i < len(lrcs); i++ {
|
||||
lrcs[i] = e.Lyrics.Lyrics[i].Lyric
|
||||
}
|
||||
fullLrc.Segments[0] = &widget.TextSegment{
|
||||
Style: widget.RichTextStyleInline,
|
||||
Text: strings.Join(lrcs, "\n\n"),
|
||||
}
|
||||
fullLrc.Refresh()
|
||||
})
|
||||
|
||||
w.SetOnClosed(func() {
|
||||
controller.CurrentLyric.Handler.Unregister("player.lyric.current_lyric")
|
||||
controller.CurrentLyric.Handler.Unregister("player.lyric.new_media")
|
||||
controller.Instance.PlayControl().GetLyric().EventManager().Unregister("player.lyric.current_lyric")
|
||||
controller.Instance.PlayControl().GetLyric().EventManager().Unregister("player.lyric.new_media")
|
||||
PlayController.LrcWindowOpen = false
|
||||
})
|
||||
return w
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/event"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/event"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/model"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type playlistOperationButton struct {
|
||||
@@ -25,10 +26,10 @@ func (b *playlistOperationButton) Tapped(e *fyne.PointEvent) {
|
||||
func newPlaylistOperationButton() *playlistOperationButton {
|
||||
b := &playlistOperationButton{Index: 0}
|
||||
deleteItem := fyne.NewMenuItem(i18n.T("gui.player.playlist.op.delete"), func() {
|
||||
controller.UserPlaylist.Delete(b.Index)
|
||||
controller.Instance.Playlists().GetCurrent().Delete(b.Index)
|
||||
})
|
||||
topItem := fyne.NewMenuItem(i18n.T("gui.player.playlist.op.top"), func() {
|
||||
controller.UserPlaylist.Move(b.Index, 0)
|
||||
controller.Instance.Playlists().GetCurrent().Move(b.Index, 0)
|
||||
})
|
||||
m := fyne.NewMenu("", deleteItem, topItem)
|
||||
b.menu = m
|
||||
@@ -38,15 +39,14 @@ func newPlaylistOperationButton() *playlistOperationButton {
|
||||
return b
|
||||
}
|
||||
|
||||
type PlaylistContainer struct {
|
||||
Playlist *player.Playlist
|
||||
var UserPlaylist = &struct {
|
||||
Playlist *model.Playlist
|
||||
List *widget.List
|
||||
}
|
||||
|
||||
var UserPlaylist = &PlaylistContainer{}
|
||||
mux sync.RWMutex
|
||||
}{}
|
||||
|
||||
func createPlaylist() fyne.CanvasObject {
|
||||
UserPlaylist.Playlist = controller.UserPlaylist
|
||||
UserPlaylist.Playlist = controller.Instance.Playlists().GetCurrent().Model().Copy()
|
||||
UserPlaylist.List = widget.NewList(
|
||||
func() int {
|
||||
//debug.PrintStack()
|
||||
@@ -62,11 +62,11 @@ func createPlaylist() fyne.CanvasObject {
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Label).SetText(
|
||||
UserPlaylist.Playlist.Playlist[id].Title)
|
||||
UserPlaylist.Playlist.Medias[id].Title)
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Label).SetText(
|
||||
UserPlaylist.Playlist.Playlist[id].Artist)
|
||||
UserPlaylist.Playlist.Medias[id].Artist)
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*widget.Label).SetText(
|
||||
UserPlaylist.Playlist.Playlist[id].ToUser().Name)
|
||||
UserPlaylist.Playlist.Medias[id].ToUser().Name)
|
||||
object.(*fyne.Container).Objects[1].(*widget.Label).SetText(fmt.Sprintf("%d", id))
|
||||
object.(*fyne.Container).Objects[2].(*playlistOperationButton).Index = id
|
||||
})
|
||||
@@ -85,10 +85,12 @@ func createPlaylist() fyne.CanvasObject {
|
||||
}
|
||||
|
||||
func registerPlaylistHandler() {
|
||||
UserPlaylist.Playlist.Handler.RegisterA(player.EventPlaylistUpdate, "gui.playlist.update", func(event *event.Event) {
|
||||
// @6 Read lock Playlist when updating free after updating.
|
||||
UserPlaylist.Playlist.Lock.RLock()
|
||||
controller.Instance.Playlists().GetCurrent().EventManager().RegisterA(model.EventPlaylistUpdate, "gui.playlist.update", func(event *event.Event) {
|
||||
// Read lock Playlists when updating free after updating.
|
||||
l().Tracef("Playlist update event received: %s", event.Data.(model.PlaylistUpdateEvent).Playlist)
|
||||
UserPlaylist.mux.RLock()
|
||||
UserPlaylist.Playlist = event.Data.(model.PlaylistUpdateEvent).Playlist
|
||||
UserPlaylist.List.Refresh()
|
||||
UserPlaylist.Playlist.Lock.RUnlock()
|
||||
UserPlaylist.mux.RUnlock()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/i18n"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -25,10 +24,7 @@ type PlaylistManagerContainer struct {
|
||||
}
|
||||
|
||||
func (p *PlaylistManagerContainer) UpdateCurrentSystemPlaylist() {
|
||||
if config.Player.PlaylistIndex >= len(controller.PlaylistManager) {
|
||||
p.CurrentSystemPlaylist.SetText(i18n.T("gui.playlist.current.none"))
|
||||
}
|
||||
p.CurrentSystemPlaylist.SetText(i18n.T("gui.playlist.current") + controller.PlaylistManager[config.Player.PlaylistIndex].Name)
|
||||
p.CurrentSystemPlaylist.SetText(i18n.T("gui.playlist.current") + controller.Instance.Playlists().GetDefault().Name())
|
||||
}
|
||||
|
||||
var PlaylistManager = &PlaylistManagerContainer{}
|
||||
@@ -36,17 +32,17 @@ var PlaylistManager = &PlaylistManagerContainer{}
|
||||
func createPlaylists() fyne.CanvasObject {
|
||||
PlaylistManager.Playlists = widget.NewList(
|
||||
func() int {
|
||||
return len(controller.PlaylistManager)
|
||||
return controller.Instance.Playlists().Size()
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("AAAAAAAAAAAAAAAA")
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
object.(*widget.Label).SetText(
|
||||
controller.PlaylistManager[id].Name)
|
||||
controller.Instance.Playlists().Get(id).Name())
|
||||
})
|
||||
PlaylistManager.AddBtn = widget.NewButton(i18n.T("gui.playlist.button.add"), func() {
|
||||
providerEntry := widget.NewSelect(config.Provider.Priority, nil)
|
||||
providerEntry := widget.NewSelect(controller.Instance.Provider().GetPriority(), nil)
|
||||
idEntry := widget.NewEntry()
|
||||
dia := dialog.NewCustomConfirm(
|
||||
i18n.T("gui.playlist.add.title"),
|
||||
@@ -64,7 +60,7 @@ func createPlaylists() fyne.CanvasObject {
|
||||
),
|
||||
func(b bool) {
|
||||
if b && len(providerEntry.Selected) > 0 && len(idEntry.Text) > 0 {
|
||||
controller.AddPlaylist(providerEntry.Selected, idEntry.Text)
|
||||
controller.Instance.Playlists().Add(providerEntry.Selected, idEntry.Text)
|
||||
PlaylistManager.Playlists.Refresh()
|
||||
PlaylistManager.PlaylistMedia.Refresh()
|
||||
}
|
||||
@@ -75,7 +71,7 @@ func createPlaylists() fyne.CanvasObject {
|
||||
dia.Show()
|
||||
})
|
||||
PlaylistManager.RemoveBtn = widget.NewButton(i18n.T("gui.playlist.button.remove"), func() {
|
||||
controller.RemovePlaylist(PlaylistManager.Index)
|
||||
controller.Instance.Playlists().Remove(PlaylistManager.Index)
|
||||
//PlaylistManager.Index = 0
|
||||
PlaylistManager.Playlists.Select(0)
|
||||
PlaylistManager.Playlists.Refresh()
|
||||
@@ -99,13 +95,13 @@ func createPlaylistMedias() fyne.CanvasObject {
|
||||
PlaylistManager.RefreshBtn = createAsyncButton(
|
||||
widget.NewButtonWithIcon(i18n.T("gui.playlist.button.refresh"), theme.ViewRefreshIcon(), nil),
|
||||
func() {
|
||||
controller.PreparePlaylistByIndex(PlaylistManager.Index)
|
||||
showDialogIfError(controller.Instance.Playlists().PreparePlaylistByIndex(PlaylistManager.Index))
|
||||
PlaylistManager.PlaylistMedia.Refresh()
|
||||
})
|
||||
PlaylistManager.SetAsSystemBtn = createAsyncButton(
|
||||
widget.NewButton(i18n.T("gui.playlist.button.set_as_system"), nil),
|
||||
func() {
|
||||
controller.SetSystemPlaylist(PlaylistManager.Index)
|
||||
showDialogIfError(controller.Instance.Playlists().SetDefault(PlaylistManager.Index))
|
||||
PlaylistManager.PlaylistMedia.Refresh()
|
||||
PlaylistManager.UpdateCurrentSystemPlaylist()
|
||||
})
|
||||
@@ -113,10 +109,10 @@ func createPlaylistMedias() fyne.CanvasObject {
|
||||
PlaylistManager.UpdateCurrentSystemPlaylist()
|
||||
PlaylistManager.PlaylistMedia = widget.NewList(
|
||||
func() int {
|
||||
if len(controller.PlaylistManager) == 0 {
|
||||
if controller.Instance.Playlists().Size() == 0 {
|
||||
return 0
|
||||
}
|
||||
return controller.PlaylistManager[PlaylistManager.Index].Size()
|
||||
return controller.Instance.Playlists().Get(PlaylistManager.Index).Size()
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return container.NewBorder(nil, nil,
|
||||
@@ -130,18 +126,19 @@ func createPlaylistMedias() fyne.CanvasObject {
|
||||
newLabelWithWrapping("artist", fyne.TextTruncate)))
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
m := controller.PlaylistManager[PlaylistManager.Index].Playlist[id]
|
||||
m := controller.Instance.Playlists().Get(PlaylistManager.Index).Get(id).Copy()
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Label).SetText(
|
||||
m.Title)
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Label).SetText(
|
||||
m.Artist)
|
||||
object.(*fyne.Container).Objects[1].(*widget.Label).SetText(fmt.Sprintf("%d", id))
|
||||
btns := object.(*fyne.Container).Objects[2].(*fyne.Container).Objects
|
||||
m.User = controller.SystemUser
|
||||
btns[0].(*widget.Button).OnTapped = func() {
|
||||
controller.Play(controller.ToSystemMedia(m))
|
||||
controller.Instance.PlayControl().Play(m)
|
||||
}
|
||||
btns[1].(*widget.Button).OnTapped = func() {
|
||||
controller.UserPlaylist.Push(controller.ToSystemMedia(m))
|
||||
controller.Instance.Playlists().GetCurrent().Push(m)
|
||||
}
|
||||
})
|
||||
return container.NewBorder(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/event"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/event"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/liveclient"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -27,14 +27,14 @@ var RoomTab = &struct {
|
||||
func createRoomSelector() fyne.CanvasObject {
|
||||
RoomTab.Rooms = widget.NewList(
|
||||
func() int {
|
||||
return controller.LiveRoomManager.Size()
|
||||
return controller.Instance.LiveRooms().Size()
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("AAAAAAAAAAAAAAAA")
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
object.(*widget.Label).SetText(
|
||||
controller.LiveRoomManager.LiveRooms[id].Title())
|
||||
controller.Instance.LiveRooms().Get(id).Title())
|
||||
})
|
||||
RoomTab.AddBtn = widget.NewButton(i18n.T("gui.room.button.add"), func() {
|
||||
clientNameEntry := widget.NewSelect(liveclient.GetAllClientNames(), nil)
|
||||
@@ -55,7 +55,7 @@ func createRoomSelector() fyne.CanvasObject {
|
||||
),
|
||||
func(b bool) {
|
||||
if b && len(clientNameEntry.Selected) > 0 && len(idEntry.Text) > 0 {
|
||||
_, err := controller.LiveRoomManager.AddRoom(clientNameEntry.Selected, idEntry.Text)
|
||||
_, err := controller.Instance.LiveRooms().AddRoom(clientNameEntry.Selected, idEntry.Text)
|
||||
if err != nil {
|
||||
dialog.ShowError(err, MainWindow)
|
||||
return
|
||||
@@ -69,7 +69,7 @@ func createRoomSelector() fyne.CanvasObject {
|
||||
dia.Show()
|
||||
})
|
||||
RoomTab.RemoveBtn = widget.NewButton(i18n.T("gui.room.button.remove"), func() {
|
||||
if err := controller.LiveRoomManager.DeleteRoom(PlaylistManager.Index); err != nil {
|
||||
if err := controller.Instance.LiveRooms().DeleteRoom(PlaylistManager.Index); err != nil {
|
||||
dialog.ShowError(err, MainWindow)
|
||||
return
|
||||
}
|
||||
@@ -77,13 +77,13 @@ func createRoomSelector() fyne.CanvasObject {
|
||||
RoomTab.Rooms.Refresh()
|
||||
})
|
||||
RoomTab.Rooms.OnSelected = func(id widget.ListItemID) {
|
||||
rom := controller.LiveRoomManager.GetRoom(PlaylistManager.Index)
|
||||
rom := controller.Instance.LiveRooms().Get(PlaylistManager.Index)
|
||||
if rom != nil {
|
||||
rom.Client().Handler().Unregister("gui.liveroom.status")
|
||||
rom.EventManager().Unregister("gui.liveroom.status")
|
||||
}
|
||||
RoomTab.Index = id
|
||||
rom = controller.LiveRoomManager.GetRoom(RoomTab.Index)
|
||||
rom.Client().Handler().RegisterA(liveclient.EventStatusChange, "gui.liveroom.status", func(event *event.Event) {
|
||||
rom = controller.Instance.LiveRooms().Get(RoomTab.Index)
|
||||
rom.EventManager().RegisterA(liveclient.EventStatusChange, "gui.liveroom.status", func(event *event.Event) {
|
||||
d := event.Data.(liveclient.StatusChangeEvent)
|
||||
if d.Connected {
|
||||
RoomTab.Status.SetText(i18n.T("gui.room.status.connected"))
|
||||
@@ -93,8 +93,8 @@ func createRoomSelector() fyne.CanvasObject {
|
||||
RoomTab.Status.Refresh()
|
||||
})
|
||||
RoomTab.RoomTitle.SetText(rom.Title())
|
||||
RoomTab.AutoConnect.SetChecked(rom.AutoConnect)
|
||||
if rom.Client().Status() {
|
||||
RoomTab.AutoConnect.SetChecked(rom.Model().AutoConnect)
|
||||
if controller.Instance.LiveRooms().GetRoomStatus(RoomTab.Index) {
|
||||
RoomTab.Status.SetText(i18n.T("gui.room.status.connected"))
|
||||
} else {
|
||||
RoomTab.Status.SetText(i18n.T("gui.room.status.disconnected"))
|
||||
@@ -115,19 +115,19 @@ func createRoomController() fyne.CanvasObject {
|
||||
RoomTab.ConnectBtn = widget.NewButton(i18n.T("gui.room.btn.connect"), func() {
|
||||
RoomTab.ConnectBtn.Disable()
|
||||
go func() {
|
||||
_ = controller.LiveRoomManager.ConnectRoom(RoomTab.Index)
|
||||
_ = controller.Instance.LiveRooms().Connect(RoomTab.Index)
|
||||
RoomTab.ConnectBtn.Enable()
|
||||
}()
|
||||
})
|
||||
RoomTab.DisConnectBtn = widget.NewButton(i18n.T("gui.room.btn.disconnect"), func() {
|
||||
_ = controller.LiveRoomManager.DisconnectRoom(RoomTab.Index)
|
||||
_ = controller.Instance.LiveRooms().Disconnect(RoomTab.Index)
|
||||
})
|
||||
RoomTab.Status = widget.NewLabel(i18n.T("gui.room.waiting"))
|
||||
RoomTab.RoomTitle = widget.NewLabel("")
|
||||
RoomTab.AutoConnect = widget.NewCheck(i18n.T("gui.room.check.autoconnect"), func(b bool) {
|
||||
rom := controller.LiveRoomManager.GetRoom(RoomTab.Index)
|
||||
rom := controller.Instance.LiveRooms().Get(RoomTab.Index)
|
||||
if rom != nil {
|
||||
rom.AutoConnect = b
|
||||
rom.Model().AutoConnect = b
|
||||
}
|
||||
return
|
||||
})
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/model"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
@@ -14,7 +13,7 @@ var SearchBar = &struct {
|
||||
Input *widget.Entry
|
||||
Button *widget.Button
|
||||
UseSource *widget.CheckGroup
|
||||
Items []*player.Media
|
||||
Items []*model.Media
|
||||
}{}
|
||||
|
||||
func createSearchBar() fyne.CanvasObject {
|
||||
@@ -26,18 +25,18 @@ func createSearchBar() fyne.CanvasObject {
|
||||
s := make([]string, len(SearchBar.UseSource.Selected))
|
||||
|
||||
copy(s, SearchBar.UseSource.Selected)
|
||||
items := make([]*player.Media, 0)
|
||||
items := make([]*model.Media, 0)
|
||||
for _, p := range s {
|
||||
if r, err := controller.SearchWithProvider(keyword, p); err == nil {
|
||||
if r, err := controller.Instance.Provider().SearchWithProvider(keyword, p); err == nil {
|
||||
items = append(items, r...)
|
||||
}
|
||||
}
|
||||
controller.ApplyUser(items, player.SystemUser)
|
||||
controller.ApplyUser(items, controller.SystemUser)
|
||||
SearchResult.Items = items
|
||||
SearchResult.List.Refresh()
|
||||
})
|
||||
s := make([]string, len(config.Provider.Priority))
|
||||
copy(s, config.Provider.Priority)
|
||||
s := make([]string, len(controller.Instance.Provider().GetPriority()))
|
||||
copy(s, controller.Instance.Provider().GetPriority())
|
||||
|
||||
SearchBar.UseSource = widget.NewCheckGroup(s, nil)
|
||||
SearchBar.UseSource.Horizontal = true
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/common/i18n"
|
||||
"AynaLivePlayer/controller"
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/player"
|
||||
"AynaLivePlayer/provider"
|
||||
"AynaLivePlayer/model"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -14,9 +13,9 @@ import (
|
||||
|
||||
var SearchResult = &struct {
|
||||
List *widget.List
|
||||
Items []*player.Media
|
||||
Items []*model.Media
|
||||
}{
|
||||
Items: []*player.Media{},
|
||||
Items: []*model.Media{},
|
||||
}
|
||||
|
||||
func createSearchList() fyne.CanvasObject {
|
||||
@@ -42,14 +41,14 @@ func createSearchList() fyne.CanvasObject {
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Label).SetText(
|
||||
SearchResult.Items[id].Artist)
|
||||
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*widget.Label).SetText(
|
||||
SearchResult.Items[id].Meta.(provider.Meta).Name)
|
||||
SearchResult.Items[id].Meta.(model.Meta).Name)
|
||||
object.(*fyne.Container).Objects[1].(*widget.Label).SetText(fmt.Sprintf("%d", id))
|
||||
btns := object.(*fyne.Container).Objects[2].(*fyne.Container).Objects
|
||||
btns[0].(*widget.Button).OnTapped = func() {
|
||||
controller.Play(SearchResult.Items[id])
|
||||
controller.Instance.PlayControl().Play(SearchResult.Items[id])
|
||||
}
|
||||
btns[1].(*widget.Button).OnTapped = func() {
|
||||
controller.UserPlaylist.Push(SearchResult.Items[id])
|
||||
controller.Instance.Playlists().GetCurrent().Push(SearchResult.Items[id])
|
||||
}
|
||||
})
|
||||
return container.NewBorder(
|
||||
|
||||
Reference in New Issue
Block a user