cuu 5 éve
szülő
commit
92417db7ad

+ 4 - 1
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 ) {

+ 4 - 1
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 ) {

+ 25 - 0
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

+ 254 - 0
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 
+
+}

+ 14 - 0
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 -
+
+

+ 1 - 1
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)

+ 1 - 0
sysgo/UI/events.go

@@ -3,4 +3,5 @@ package UI
 
 const (
     RUNEVT=1
+    RESTARTUI=2
 )

+ 7 - 1
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"
+  
 )