add HookExitCb for OnExitCb

This commit is contained in:
cuu
2023-01-16 12:55:12 +00:00
parent ef19017718
commit 0e62938403
13 changed files with 265 additions and 125 deletions

View File

@@ -398,14 +398,17 @@ func (self *WareHouse) Init() {
self.rpcSecret,
gotime.Second, AppNotifier{Parent:self})
if err != nil {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
}
self.rpcc = rpcc
self.Downloader = grab.NewClient()
self.Downloading = make(chan bool,1)
self.Screen.HookExitCb(self)
}
}
@@ -768,7 +771,6 @@ func (self *WareHouse) OnKbdReturnBackCb() {
}
func (self *WareHouse) OnExitCb() {
self.SetDownloading(false)
self.rpcc.Close()

View File

@@ -0,0 +1,54 @@
package MusicPlayer
import (
"fmt"
// "path/filepath"
// "github.com/cuu/gogame/event"
"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/rect"
// "github.com/cuu/gogame/surface"
// "github.com/veandco/go-sdl2/ttf"
"github.com/cuu/gogame/color"
// "github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
)
type ListPageSelector struct {
UI.InfoPageSelector
}
func NewListPageSelector() *ListPageSelector {
p := &ListPageSelector{}
p.Width = UI.Width
p.BackgroundColor = &color.Color{131, 199, 219, 255} //SkinManager().GiveColor('Front')
return p
}
func (self *ListPageSelector) Draw() {
idx := self.Parent.GetPsIndex()
mylist := self.Parent.GetMyList()
fmt.Println(idx)
if idx < len(mylist) {
x, y := mylist[idx].Coord()
_, h := mylist[idx].Size()
self.PosX = x + 2
self.PosY = y + 1
self.Height = h - 3
canvas_ := self.Parent.GetCanvasHWND()
rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
draw.AARoundRect(canvas_, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
}
}

View File

@@ -2,6 +2,7 @@ package MusicPlayer
import (
//"fmt"
"log"
"path/filepath"
"github.com/cuu/gogame/event"
@@ -11,11 +12,11 @@ import (
"github.com/cuu/gogame/color"
"github.com/clockworkpi/LauncherGoDev/sysgo"
// "github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/fhs/gompd/v2/mpd"
// "github.com/fhs/gompd/v2/mpd"
)
type MusicLibListPage struct {
@@ -28,14 +29,15 @@ type MusicLibListPage struct {
IP string
MyList []UI.ListItemInterface
MyStack *MusicLibStack
//MyList []UI.ListItemInterface
MyStack *UI.FolderStack
BGwidth int
BGheight int //70
Scroller *UI.ListScroller
Scrolled int
Parent *MusicPlayerPage// also use the MpdClient from
Parent *MusicPlayerPage
}
func NewMusicLibListPage() *MusicLibListPage {
@@ -74,12 +76,7 @@ func (self *MusicLibListPage) SetCoords() {
}
func (self *MusicLibListPage) SyncList(path string) {
conn, err := mpd.Dial("unix", sysgo.MPD_socket)
if err != nil {
log.Fatalln(err)
}
defer conn.Close()
conn := self.Parent.MpdClient
self.MyList = nil
@@ -113,25 +110,25 @@ func (self *MusicLibListPage) SyncList(path string) {
for i, m := range atts {
li : NewMusicLibListPageListItem()
li := NewMusicLibListPageListItem()
li.Parent = self
li.PosX = start_x
li.PosY = start_y + (i+hasparent)*li.Height
li.Width = UI.Width
li.Fonts["normal"] = self.ListFont
li.Fonts["normal"] = self.ListFontObj
li.MyType = UI.ICON_TYPES["FILE"]
init_val := "NoName"
if val, ok := m["directory"] ; ok {
li.MyType = UI.ICON_TYPES["DIR"]
init_val = filepath.Base(m["directory"])
li.Path = m["directory"]
init_val = filepath.Base(val)
li.Path = val
}
if val, ok = m["file"]; ok {
if val, ok := m["file"]; ok {
li.MyType = UI.ICON_TYPES["FILE"]
li.Path = m["file"]
li.Path = val
val2, ok2 := m["Title"]
if ok2 && len(val2) > 4{
@@ -162,7 +159,9 @@ func (self *MusicLibListPage) Init() {
self.Width = self.Screen.Width
self.Height = self.Screen.Height
ps := UI.NewInfoPageSelector()
ps := NewListPageSelector()
ps.Parent = self
ps.Width = UI.Width - 12
ps.PosX = 2
ps.Parent = self
@@ -195,15 +194,67 @@ func (self *MusicLibListPage) Init() {
self.Scroller.PosY = 2
self.Scroller.Init()
self.MyStack = UI.NewFolderStack()
self.MyStack.SetRootPath("/")
}
func (self *MusicLibListPage) Click() {
self.RefreshPsIndex()
if len(self.MyList) == 0 {
return
}
cur_li := self.MyList[self.PsIndex].(*MusicLibListPageListItem)
if cur_li.MyType == UI.ICON_TYPES["DIR"] {
if cur_li.Path == "[..]" {
self.MyStack.Pop()
self.SyncList( self.MyStack.Last() )
self.PsIndex = 0
} else {
self.MyStack.Push( cur_li.Path )
self.SyncList( self.MyStack.Last() )
self.PsIndex = 0
}
}
if cur_li.MyType == UI.ICON_TYPES["FILE"] {
//addfile(cur_li.Path)
//PlayListPage.SyncList()
//print("add" , cur_li._Path)
}
self.Screen.Draw()
self.Screen.SwapAndShow()
}
func (self *MusicLibListPage) KeyDown(ev *event.Event) {
if ev.Data["Key"] == UI.CurKeys["Left"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
self.ReturnToUpLevelPage()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
if ev.Data["Key"] == UI.CurKeys["Up"] {
self.ScrollUp()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
if ev.Data["Key"] == UI.CurKeys["Down"] {
self.ScrollDown()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
return
}
@@ -213,6 +264,37 @@ func (self *MusicLibListPage) Draw() {
if len(self.MyList) == 0 {
self.Icons["bg"].NewCoord(self.Width/2, self.Height/2)
self.Icons["bg"].Draw()
}else {
if len(self.MyList)*UI.DefaultInfoPageListItemHeight > self.Height {
self.Ps.(*ListPageSelector).Width = self.Width - 11
self.Ps.Draw()
for _, v := range self.MyList {
if v.(*MusicLibListPageListItem).PosY > self.Height+self.Height/2 {
break
}
if v.(*MusicLibListPageListItem).PosY < 0 {
continue
}
v.Draw()
}
} else{
self.Ps.(*ListPageSelector).Width = self.Width
self.Ps.Draw()
for _, v := range self.MyList {
if v.(*MusicLibListPageListItem).PosY > self.Height+self.Height/2 {
break
}
if v.(*MusicLibListPageListItem).PosY < 0 {
continue
}
v.Draw()
}
}
}
if self.HWND != nil {

View File

@@ -1,23 +1,23 @@
package MusicPlayer
import (
"fmt"
// "fmt"
//"io/ioutil"
//"path/filepath"
"github.com/veandco/go-sdl2/ttf"
"runtime"
"strconv"
"strings"
// "runtime"
// "strconv"
// "strings"
//"github.com/mitchellh/go-homedir"
"github.com/clockworkpi/LauncherGoDev/sysgo"
/// "github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/cuu/gogame/color"
"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/event"
"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/surface"
"github.com/cuu/gogame/time"
// "github.com/cuu/gogame/event"
// "github.com/cuu/gogame/rect"
// "github.com/cuu/gogame/surface"
// "github.com/cuu/gogame/time"
)
type MusicLibListPageListItem struct {
@@ -25,7 +25,7 @@ type MusicLibListPageListItem struct {
Active bool
Value string
MyType string
MyType int
Path string
}

View File

@@ -1,64 +0,0 @@
package MusicPlayer
import (
"sync"
)
type element struct {
data interface{}
next *element
}
type MusicLibStack struct {
lock *sync.Mutex
head *element
Size int
}
func (stk *MusicLibStack) Push(data interface{}) {
stk.lock.Lock()
element := new(element)
element.data = data
temp := stk.head
element.next = temp
stk.head = element
stk.Size++
stk.lock.Unlock()
}
func (stk *MusicLibStack) Pop() interface{} {
if stk.head == nil {
return nil
}
stk.lock.Lock()
r := stk.head.data
stk.head = stk.head.next
stk.Size--
stk.lock.Unlock()
return r
}
func (stk *MusicLibStack) Length() int {
return stk.Size
}
func (stk *MusicLibStack) Last() string {
idx := stk.Length() -1
if idx < 0 {
return "/"
} else {
return stk.head.data.(string)
}
}
func NewMusicLibStack() *MusicLibStack {
stk := new(MusicLibStack)
stk.lock = &sync.Mutex{}
return stk
}

View File

@@ -1,16 +1,18 @@
package MusicPlayer
import (
//"fmt"
"fmt"
"log"
"github.com/cuu/gogame/event"
"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/surface"
"github.com/veandco/go-sdl2/ttf"
"github.com/cuu/gogame/color"
"github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/fhs/gompd/v2/mpd"
)
type MusicPlayerPage struct {
@@ -23,15 +25,16 @@ type MusicPlayerPage struct {
IP string
MyMusicLibListPage *MusicLibListPage
MyMusicLibListPage *MusicLibListPage //also use the MpdClient *mpd.Client
MyList []UI.ListItemInterface
MyStack *MusicLibStack
//MyList []UI.ListItemInterface
MyStack *UI.FolderStack
BGwidth int
BGheight int //70
Scroller *UI.ListScroller
Scrolled int
MpdClient *mpd.Client
}
func NewMusicPlayerPage() *MusicPlayerPage {
@@ -62,6 +65,24 @@ func NewMusicPlayerPage() *MusicPlayerPage {
func (self *MusicPlayerPage) OnLoadCb() {
self.PosY = 0
if self.MpdClient == nil {
conn, err := mpd.Dial("unix", sysgo.MPD_socket)
if err != nil {
log.Fatalln(err)
}
self.MpdClient = conn
fmt.Println("Start mpd client")
}
}
func (self *MusicPlayerPage) OnPopUpCb() {
if self.MpdClient != nil {
self.MpdClient.Close()
self.MpdClient = nil
fmt.Println("Close mpd client")
}
}
func (self *MusicPlayerPage) SetCoords() {
@@ -124,6 +145,9 @@ func (self *MusicPlayerPage) Init() {
self.MyMusicLibListPage.Name = "Music Library"
self.MyMusicLibListPage.Parent = self
self.MyMusicLibListPage.Init()
self.MyStack = UI.NewFolderStack()
self.MyStack.SetRootPath("/")
}
func (self *MusicPlayerPage) KeyDown(ev *event.Event) {

View File

@@ -1,23 +1,23 @@
package MusicPlayer
import (
"fmt"
//"fmt"
//"io/ioutil"
//"path/filepath"
"github.com/veandco/go-sdl2/ttf"
"runtime"
"strconv"
"strings"
//"runtime"
//"strconv"
//"strings"
//"github.com/mitchellh/go-homedir"
"github.com/clockworkpi/LauncherGoDev/sysgo"
//"github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/cuu/gogame/color"
"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/event"
"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/surface"
"github.com/cuu/gogame/time"
//"github.com/cuu/gogame/event"
//"github.com/cuu/gogame/rect"
//"github.com/cuu/gogame/surface"
//"github.com/cuu/gogame/time"
)
type MusicPlayPageListItem struct {
@@ -25,7 +25,7 @@ type MusicPlayPageListItem struct {
Active bool
Value string
MyType string
MyType int
Path string
}
@@ -49,8 +49,8 @@ func (self *MusicPlayPageListItem) Draw() {
self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
if self.Active == true {
self.Parent.(*MusicPlayPage).Icons["sys"].NewCoord(self.Parent.(*MusicPlayPage).Width-30, self.PosY+5)
self.Parent.(*MusicPlayPage).Icons["sys"].Draw()
self.Parent.(*MusicPlayerPage).Icons["sys"].NewCoord(self.Parent.(*MusicPlayerPage).Width-30, self.PosY+5)
self.Parent.(*MusicPlayerPage).Icons["sys"].Draw()
}
self.Labels["Text"].SetBold(self.Active)

View File

@@ -11,18 +11,23 @@ import (
*/
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
//"github.com/clockworkpi/LauncherGoDev/sysgo/DBUS"
"github.com/fhs/gompd/v2/mpd"
)
/******************************************************************************/
type MusicPlayerPlugin struct {
UI.Plugin
MusicPlayerPage *MusicPlayerPage
MpdClient *mpd.Client
}
func (self *MusicPlayerPlugin) Init(main_screen *UI.MainScreen) {
self.MusicPlayerPage = NewMusicPlayerPage()
self.MusicPlayerPage.SetScreen(main_screen)
self.MusicPlayerPage.SetName("Music Player")
self.MpdClient = nil
self.MusicPlayerPage.MpdClient = self.MpdClient
self.MusicPlayerPage.Init()
}