From 92417db7adfe51e5ed5d262c3415f17333fa841a Mon Sep 17 00:00:00 2001 From: cuu Date: Mon, 3 Dec 2018 23:19:39 +0800 Subject: [PATCH] ... --- .../10_Settings/Brightness/plugin_init.go | 5 +- .../10_Settings/Sound/plugin_init.go | 5 +- .../10_Settings/Update/plugin_init.go | 25 ++ .../10_Settings/Update/update_page.go | 254 ++++++++++++++++++ build.sh | 14 + main.go | 2 +- sysgo/UI/events.go | 1 + sysgo/config.go | 8 +- 8 files changed, 310 insertions(+), 4 deletions(-) create mode 100644 Menu/GameShell/10_Settings/Update/update_page.go diff --git a/Menu/GameShell/10_Settings/Brightness/plugin_init.go b/Menu/GameShell/10_Settings/Brightness/plugin_init.go index 2aef26f..0727bd6 100644 --- a/Menu/GameShell/10_Settings/Brightness/plugin_init.go +++ b/Menu/GameShell/10_Settings/Brightness/plugin_init.go @@ -24,7 +24,10 @@ type BrightnessPlugin struct { func (self *BrightnessPlugin) Init( main_screen *UI.MainScreen ) { - + self.BrightnessPage = NewBrightnessPage() + self.BrightnessPage.SetScreen( main_screen) + self.BrightnessPage.SetName("Brightness") + self.BrightnessPage.Init() } func (self *BrightnessPlugin) Run( main_screen *UI.MainScreen ) { diff --git a/Menu/GameShell/10_Settings/Sound/plugin_init.go b/Menu/GameShell/10_Settings/Sound/plugin_init.go index 4250db1..eaf1b3a 100644 --- a/Menu/GameShell/10_Settings/Sound/plugin_init.go +++ b/Menu/GameShell/10_Settings/Sound/plugin_init.go @@ -25,7 +25,10 @@ type SoundPlugin struct { func (self *SoundPlugin) Init( main_screen *UI.MainScreen ) { - + self.SoundPage = NewSoundPage() + self.SoundPage.SetScreen( main_screen) + self.SoundPage.SetName("Sound volume") + self.SoundPage.Init() } func (self *SoundPlugin) Run( main_screen *UI.MainScreen ) { diff --git a/Menu/GameShell/10_Settings/Update/plugin_init.go b/Menu/GameShell/10_Settings/Update/plugin_init.go index e69de29..c95fac1 100644 --- a/Menu/GameShell/10_Settings/Update/plugin_init.go +++ b/Menu/GameShell/10_Settings/Update/plugin_init.go @@ -0,0 +1,25 @@ +package main + +/******************************************************************************/ +type UpdatePlugin struct { + UI.Plugin + Page UI.PageInterface +} + + +func (self *UpdatePlugin) Init( main_screen *UI.MainScreen ) { + self.Page = NewUpdatePage() + self.Page.SetScreen( main_screen) + self.Page.SetName("Update") + self.Page.Init() +} + +func (self *UpdatePlugin) Run( main_screen *UI.MainScreen ) { + if main_screen != nil { + main_screen.PushPage(self.Page) + main_screen.Draw() + main_screen.SwapAndShow() + } +} + +var APIOBJ UpdatePlugin diff --git a/Menu/GameShell/10_Settings/Update/update_page.go b/Menu/GameShell/10_Settings/Update/update_page.go new file mode 100644 index 0000000..92fd20f --- /dev/null +++ b/Menu/GameShell/10_Settings/Update/update_page.go @@ -0,0 +1,254 @@ +package main + +import ( + "fmt" + "bytes" + "strings" + gotime "time" + "os/exec" + "encoding/json" + "net/http" + "github.com/veandco/go-sdl2/ttf" + "github.com/cuu/gogame/time" +// "github.com/cuu/gogame/surface" + "github.com/cuu/gogame/event" + "github.com/cuu/gogame/rect" + "github.com/cuu/gogame/color" +// "github.com/cuu/gogame/font" + "github.com/cuu/gogame/draw" + + "github.com/cuu/LauncherGoDev/sysgo" + "github.com/cuu/LauncherGoDev/sysgo/UI" +) + +var InfoPageListItemDefaultHeight = 30 +var launchergo_path = "/home/cpi/launchergo" + +type UpdateConfirmPage struct { + UI.ConfirmPage + + URL string + MD5 string + Version string + GIT bool +} + +func NewUpdateConfirmPage() *UpdateConfirmPage { + p := &UpdateConfirmPage{} + + p.ListFont = UI.Fonts["veramono20"] + p.FootMsg = [5]string{"Nav","","","Cancel","Yes"} + p.ConfirmText = "Confirm Update?" + + +} + +func (self *UpdateConfirmPage) KeyDown(ev *event.Event) { + + if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] { + self.ReturnToUpLevelPage() + self.Screen.Draw() + self.Screen.SwapAndShow() + } + + if ev.Data["Key"] == CurKeys["B"] { + if self.GIT == true { + cmdpath := fmt.Sprintf("feh --bg-center %s/sys.go/gameshell/wallpaper/updating.png; cd %s ;git pull; git reset --hard %s ; feh --bg-center %s/sys.py/gameshell/wallpaper/loading.png ", + launchergo_path, + launchergo_path, + self.Version, + launchergo_path ) + + event.Post(UI.RUNEVT,cmdpath) + return + } + } +} + +func (self *UpdateConfirmPage) OnReturnBackCb() { + self.ReturnToUpLevelPage() + self.Screen.Draw() + self.Screen.SwapAndShow() +} + +func (self *UpdateConfirmPage) Draw() { + self.ClearCanvas() + self.DrawBG() + for _,v := range self.MyList{ + v.Draw() + } + self.Reset() +} + +type UpdatePage struct { + UI.Page + AList map[string]map[string]string + ListFontObj *ttf.Font + MyList []*UI.InfoPageListItem + ConfirmPage *UpdateConfirmPage +} + +func NewUpdatePage() *UpdatePage { + p := &UpdatePage{} + p.FootMsg = [5]string{ "Nav","Check Update","","Back","" } + p.PageIconMargin = 20 + p.SelectedIconTopOffset = 20 + p.EasingDur = 10 + + p.Align = ALIGN["SLeft"] + p.ListFontObj = UI.Fonts["varela15"] + + return p +} + +func (self *UpdatePage) GenList() { + self.MyList = nil + self.MyList = make([]*UI.InfoPageListItem,0) + + start_x := 0 + start_y := 0 + i := 0 + + for k,_ := range self.AList { + li := UI.NewInfoPageListItem() + li.Parent = self + li.PosX = start_x + li.PosY = start_y + i*InfoPageListItemDefaultHeight + li.Width = UI.Width + li.Fonts["normal"] = self.ListFontObj + li.Fonts["small"] = UI.Fonts["varela12"] + + if self.AList[k]["label"] != "" { + li.Init(self.AList[k]["label"]) + }else { + li.Init(self.AList[k]["key"] ) + } + + li.Flag = self.AList[k]["value"] + self.MyList = append(self.MyList,li) + + i+=1 + } +} + +func (self *UpdatePage) Init() { + self.CanvasHWND = self.Screen.CanvasHWND + self.Width = self.Screen.Width + self.Height = self.Screen.Height + + self.ConfirmPage = NewUpdateConfirmPage() + self.ConfirmPage.Screen = self.Screen + self.ConfirmPage.Name = "Update Confirm" + self.ConfirmPage.Init() + + it := make(map[string]string) + it["key"] = "version" + it["label"] = "Version" + it["value"] = sysgo.VERSION + + self.AList["version"] = it + + self.GenList() +} + +func (self *UpdatePage) CheckUpdate() bool { + self.Screen.MsgBox.SetText("Checking Update") + self.Screen.MsgBox.Draw() + self.Screen.SwapAndShow() + + type Response struct { + GitVersion string `json:"gitversion"` + } + + + timeout := gotime.Duration(8 * gotime.Second) + client := http.Client{ + Timeout: timeout, + } + + resp, err := client.Get(sysgo.UPDATE_URL) + if err != nil { + fmt.Println(err) + return false + } + var ret Response + buf := new(bytes.Buffer) + buf.ReadFrom(resp.Body) + respByte := buf.Bytes() + if err := json.Unmarshal(respByte, &ret); err != nil { + fmt.Println(err) + return false + } + + fmt.Println("got git version :", ret.GitVersion) + + launchergo_git_rev_parse := exec.Command("git", "rev-parse", "--short", "HEAD") + launchergo_git_rev_parse.Dir = launchergo_path + var out bytes.Buffer + launchergo_git_rev_parse.Stdout = &out + err = launchergo_git_rev_parse.Run() + + if err != nil { + fmt.Println(err) + return false + } + + git_revision_short_hash := strings.Trim(out.String(), "\r\n ") + + if git_revision_short_hash != ret.GitVersion { + self.ConfirmPage.Version = ret.GitVersion + self.Screen.PushCurPage() + self.Screen.SetCurPage(self.ConfirmPage) + + self.Screen.Draw() + + self.ConfirmPage.SnapMsg( fmt.Sprintf("Update to %s?",ret.GitVersion)) + self.Screen.SwapAndShow() + + }else { + self.Screen.Draw() + self.Screen.MsgBox.SetText("Launcher is up to date") + self.Screen.MsgBox.Draw() + self.Screen.SwapAndShow() + time.BlockDelay(765) + } + + defer resp.Body.Close() + + + return true + +} + +func (self *UpdatePage) KeyDown(ev *event.Event) { + if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] { + self.ReturnToUpLevelPage() + self.Screen.Draw() + self.Screen.SwapAndShow() + } + + if ev.Data["Key"] == UI.CurKeys["X"] { + if self.Screen.DBusManager.IsWifiConnectedNow() == true { + if self.CheckUpdate() == true { + self.Screen.Draw() + self.Screen.SwapAndShow() + }else { + self.Screen.Draw() + self.Screen.MsgBox.SetText("Check Update Failed") + self.Screen.MsgBox.Draw() + self.Screen.SwapAndShow() + } + }else { + self.Screen.Draw() + self.Screen.MsgBox.SetText("Please Check your Wi-Fi connection") + self.Screen.MsgBox.Draw() + self.Screen.SwapAndShow() + } + } +} + +func (self *UpdatePage) Draw() { + self.ClearCanvas() + for + +} diff --git a/build.sh b/build.sh index 7407bb3..3f58a1f 100755 --- a/build.sh +++ b/build.sh @@ -20,3 +20,17 @@ cd Menu/GameShell/10_Settings/Wifi go build -o wifi.so -buildmode=plugin cd - +cd Menu/GameShell/10_Settings/Sound +go build --ldflags="-s -w" o sound.so -buildmode=plugin +cd - + +cd Menu/GameShell/10_Settings/Brightness +go build --ldflags="-s -w" o brightness.so -buildmode=plugin +cd - + + +cd Menu/GameShell/10_Settings/Update +go build -o update.so -buildmode=plugin +cd - + + diff --git a/main.go b/main.go index 2593a4f..48004f4 100644 --- a/main.go +++ b/main.go @@ -68,7 +68,7 @@ func run() int { }else if ev.Data["Key"] == "D" { time.Delay(1000) }else if ev.Data["Key"] == "P" { - event.Post(UI.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simpify the stuff + event.Post(UI.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simplify the stuff }else { main_screen.KeyDown(ev) diff --git a/sysgo/UI/events.go b/sysgo/UI/events.go index d31d25c..b36737e 100644 --- a/sysgo/UI/events.go +++ b/sysgo/UI/events.go @@ -3,4 +3,5 @@ package UI const ( RUNEVT=1 + RESTARTUI=2 ) diff --git a/sysgo/config.go b/sysgo/config.go index 9b5cc40..807a2cf 100644 --- a/sysgo/config.go +++ b/sysgo/config.go @@ -5,6 +5,12 @@ var ( DontLeave = false BackLight = "/proc/driver/backlight" Battery = "/sys/class/power_supply/axp20x-battery/uevent" - + MPD_socket = "/tmp/mpd.socket" + + UPDATE_URL="https://raw.githubusercontent.com/cuu/CPI/master/launchergo_ver.json" + + VERSION="stable 1.22" + SKIN="default" + )