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

@ -402,10 +402,13 @@ func (self *WareHouse) Init() {
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,10 +12,10 @@ 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"
)
@ -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
Parent *MusicPlayerPage// also use the MpdClient from
}
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,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()
}

1
go.mod
View File

@ -22,6 +22,7 @@ require (
)
require (
github.com/fhs/gompd/v2 v2.3.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/moutend/go-wca v0.2.0 // indirect

2
go.sum
View File

@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fhs/gompd/v2 v2.3.0 h1:wuruUjmOODRlJhrYx73rJnzS7vTSXSU7pWmZtM3VPE0=
github.com/fhs/gompd/v2 v2.3.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=

View File

@ -32,7 +32,7 @@ type DownloadProcessPage struct {
URLColor *color.Color
TextColor *color.Color
TheTicker *gotime.Ticker
//TheTicker *gotime.Ticker
Downloader *grab.Client
resp *grab.Response
@ -95,9 +95,9 @@ func (self *DownloadProcessPage) Init() {
func (self *DownloadProcessPage) OnExitCb() {
//Stop Ticker and the Grab
if self.TheTicker != nil {
self.TheTicker.Stop()
}
//if self.TheTicker != nil {
// self.TheTicker.Stop()
//}
}

View File

@ -38,6 +38,7 @@ type ScreenInterface interface {
IsPluginPackage(dirname string) bool
KeyDown(ev *event.Event)
OnExitCb()
HookExitCb()
PushCurPage()
PushPage(pg PageInterface)
RunEXE(cmdpath string)
@ -160,10 +161,13 @@ func (self *MessageBox) Draw() {
type MainScreen struct {
Widget
Pages []PageInterface
Child []PageInterface
PageMax int
PageIndex int
MyPageStack *PageStack
CurrentPage PageInterface
CanvasHWND *sdl.Surface
HWND *sdl.Surface
@ -181,6 +185,7 @@ type MainScreen struct {
LastKey string
LastKeyDown gotime.Time
}
func NewMainScreen() *MainScreen {
@ -377,8 +382,16 @@ func (self *MainScreen) RunEXE(cmdpath string) {
}
func (self *MainScreen) HookExitCb( page PageInterface) {
self.Child = append(self.Child,page)
}
func (self *MainScreen) OnExitCb() {
self.CurrentPage.OnExitCb()
PageLen := len(self.Child)
for i := 0; i < PageLen; i++ {
self.Child[i].OnExitCb()
}
}
func (self *MainScreen) KeyDown(ev *event.Event) {

View File

@ -5,7 +5,7 @@ import (
// "math"
//"reflect"
"sync"
// "sync"
"github.com/veandco/go-sdl2/sdl"
@ -19,54 +19,6 @@ import (
"github.com/cuu/gogame/transform"
)
type element struct {
data interface{}
next *element
}
type PageStack struct {
lock *sync.Mutex
head *element
Size int
}
func (stk *PageStack) 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 *PageStack) 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 *PageStack) Length() int {
return stk.Size
}
func NewPageStack() *PageStack {
stk := new(PageStack)
stk.lock = &sync.Mutex{}
return stk
}
type PageSelectorInterface interface {
Init(x, y, w, h, alpha int)
Adjust(x, y, w, h, alpha int)
@ -208,6 +160,7 @@ type PageInterface interface {
OnReturnBackCb()
OnKbdReturnBackCb()
OnExitCb()
OnPopUpCb()
// IconClick()
ResetPageSelector()
@ -806,13 +759,15 @@ func (self *Page) IconClick() {
}
func (self *Page) ReturnToUpLevelPage() {
self.Screen.CurrentPage.OnPopUpCb()
pop_page := self.Screen.MyPageStack.Pop()
if pop_page != nil {
page_ := pop_page.(PageInterface)
page_.Draw()
self.Screen.CurrentPage = page_
self.Screen.CurrentPage.OnReturnBackCb()
} else {
if self.Screen.MyPageStack.Length() == 0 {
if len(self.Screen.Pages) > 0 {
@ -824,6 +779,7 @@ func (self *Page) ReturnToUpLevelPage() {
}
}
}
}
func (self *Page) ClearCanvas() {
@ -919,9 +875,12 @@ func (self *Page) OnReturnBackCb() {
}
func (self *Page) OnExitCb() {
//MainScreen will call every page's OnExitCb when launchego ready to exit(0)
}
func (self *Page) OnPopUpCb(){
//happend when page switching
//use self.Screen.Current.OnPopUpCb to call the current custom Page's OnPopUpCb ,not this empty one
}
func (self *Page) Draw() {
self.ClearCanvas()
self.DrawIcons()

View File

@ -1,4 +1,4 @@
package MusicPlayer
package UI
import (
"sync"
@ -9,13 +9,13 @@ type element struct {
next *element
}
type MusicLibStack struct {
type PageStack struct {
lock *sync.Mutex
head *element
Size int
}
func (stk *MusicLibStack) Push(data interface{}) {
func (stk *PageStack) Push(data interface{}) {
stk.lock.Lock()
element := new(element)
@ -28,7 +28,7 @@ func (stk *MusicLibStack) Push(data interface{}) {
stk.lock.Unlock()
}
func (stk *MusicLibStack) Pop() interface{} {
func (stk *PageStack) Pop() interface{} {
if stk.head == nil {
return nil
}
@ -42,23 +42,21 @@ func (stk *MusicLibStack) Pop() interface{} {
return r
}
func (stk *MusicLibStack) Length() int {
func (stk *PageStack) Length() int {
return stk.Size
}
func (stk *MusicLibStack) Last() string {
idx := stk.Length() -1
func (stk *PageStack) Last() interface{} {
idx := stk.Length() - 1
if idx < 0 {
return "/"
return nil
} else {
return stk.head.data.(string)
return stk.head.data
}
}
func NewMusicLibStack() *MusicLibStack {
stk := new(MusicLibStack)
func NewPageStack() *PageStack {
stk := new(PageStack)
stk.lock = &sync.Mutex{}
return stk
}