From c6a915a7f505e42561fe83c26ea1155df660e3c4 Mon Sep 17 00:00:00 2001 From: cuu Date: Wed, 19 Dec 2018 18:20:13 +0800 Subject: [PATCH] add 99_PowerOFF --- .../GameShell/10_Settings/Sound/sound_page.go | 4 +- Menu/GameShell/99_PowerOFF/plugin.json | 5 ++ Menu/GameShell/99_PowerOFF/plugin_init.go | 39 +++++++++++ .../99_PowerOFF/poweroff_confirm_page.go | 64 +++++++++++++++++++ main.go | 31 +++++++-- mainscreen.go | 2 + sysgo/UI/events.go | 2 + 7 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 Menu/GameShell/99_PowerOFF/plugin.json create mode 100644 Menu/GameShell/99_PowerOFF/plugin_init.go create mode 100644 Menu/GameShell/99_PowerOFF/poweroff_confirm_page.go diff --git a/Menu/GameShell/10_Settings/Sound/sound_page.go b/Menu/GameShell/10_Settings/Sound/sound_page.go index 1641d58..1f6181c 100644 --- a/Menu/GameShell/10_Settings/Sound/sound_page.go +++ b/Menu/GameShell/10_Settings/Sound/sound_page.go @@ -186,8 +186,8 @@ func (self *SoundSlider) StepBack() { if self.Value < 0 { self.Value = 0 } - - vol := self.snd_segs[self.Value][0] + + vol := self.snd_segs[self.Value][0] + (self.snd_segs[self.Value][1]-self.snd_segs[self.Value][0])/2 if self.OnChangeCB != nil { self.OnChangeCB(vol) diff --git a/Menu/GameShell/99_PowerOFF/plugin.json b/Menu/GameShell/99_PowerOFF/plugin.json new file mode 100644 index 0000000..98fce26 --- /dev/null +++ b/Menu/GameShell/99_PowerOFF/plugin.json @@ -0,0 +1,5 @@ +{ +"SO_FILE":"", +"NAME":"PowerOFF" +} + diff --git a/Menu/GameShell/99_PowerOFF/plugin_init.go b/Menu/GameShell/99_PowerOFF/plugin_init.go new file mode 100644 index 0000000..14f8691 --- /dev/null +++ b/Menu/GameShell/99_PowerOFF/plugin_init.go @@ -0,0 +1,39 @@ +package PowerOFF + +import ( +/* + "github.com/veandco/go-sdl2/ttf" + + "github.com/cuu/gogame/surface" + "github.com/cuu/gogame/event" + "github.com/cuu/gogame/rect" + "github.com/cuu/gogame/color" +*/ + "github.com/cuu/LauncherGoDev/sysgo/UI" + //"github.com/cuu/LauncherGoDev/sysgo/DBUS" +) + +/******************************************************************************/ +type PowerOFFPlugin struct { + UI.Plugin + PowerOFFPage *PowerOFFConfirmPage +} + + +func (self *PowerOFFPlugin) Init( main_screen *UI.MainScreen ) { + self.PowerOFFPage = NewPowerOFFConfirmPage() + self.PowerOFFPage.SetScreen( main_screen) + self.PowerOFFPage.SetName("PowerOFF") + self.PowerOFFPage.Init() +} + +func (self *PowerOFFPlugin) Run( main_screen *UI.MainScreen ) { + if main_screen != nil { + main_screen.PushCurPage() + main_screen.SetCurPage(self.PowerOFFPage) + main_screen.Draw() + main_screen.SwapAndShow() + } +} + +var APIOBJ PowerOFFPlugin diff --git a/Menu/GameShell/99_PowerOFF/poweroff_confirm_page.go b/Menu/GameShell/99_PowerOFF/poweroff_confirm_page.go new file mode 100644 index 0000000..b560bf5 --- /dev/null +++ b/Menu/GameShell/99_PowerOFF/poweroff_confirm_page.go @@ -0,0 +1,64 @@ +package PowerOFF + +import ( + + "github.com/cuu/gogame/event" + "github.com/cuu/LauncherGoDev/sysgo/UI" + +) + +type PowerOFFConfirmPage struct { + UI.ConfirmPage + +} + +func NewPowerOFFConfirmPage() *PowerOFFConfirmPage { + + p := &PowerOFFConfirmPage{} + p.ListFont = UI.Fonts["veramono20"] + p.ConfirmText = "Awaiting Input" + p.FootMsg = [5]string{ "Nav","Reboot","","Cancel","Shutdown" } + + p.ConfirmPage.ConfirmText = p.ConfirmText + p.ConfirmPage.FootMsg = p.FootMsg + p.ConfirmPage.ListFont = p.ListFont + + return p + +} + +func (self *PowerOFFConfirmPage) KeyDown(ev *event.Event) { + + if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["A"] { + self.ReturnToUpLevelPage() + self.Screen.Draw() + self.Screen.SwapAndShow() + + } + + if ev.Data["Key"] == UI.CurKeys["B"] { + cmdpath := "" + + if UI.CheckBattery() < 20 { + cmdpath = "feh --bg-center sysgo/gameshell/wallpaper/gameover.png;" + }else { + cmdpath = "feh --bg-center sysgo/gameshell/wallpaper/seeyou.png;" + } + + cmdpath = cmdpath + "sleep 3;" + + cmdpath = cmdpath + "sudo halt -p" + + event.Post(UI.RUNSYS,cmdpath) + + } + + if ev.Data["Key"] == UI.CurKeys["X"] { + cmdpath := "feh --bg-center gameshell/wallpaper/seeyou.png;" + cmdpath += "sleep 3;" + cmdpath += "sudo reboot" + + event.Post(UI.RUNSYS,cmdpath) + } + +} diff --git a/main.go b/main.go index cee5fbd..f890e85 100644 --- a/main.go +++ b/main.go @@ -187,13 +187,16 @@ func InspectionTeam(main_screen *UI.MainScreen) { fmt.Println("Power Off counting down") - main_screen.CounterScreen.Draw() - main_screen.CounterScreen.SwapAndShow() - main_screen.CounterScreen.StartCounter() + if UI.FileExists(sysgo.BackLight) { d := []byte(fmt.Sprintf("%d",last_brt)) ioutil.WriteFile(sysgo.BackLight,d,0644) + + main_screen.CounterScreen.Draw() + main_screen.CounterScreen.SwapAndShow() + main_screen.CounterScreen.StartCounter() + } main_screen.TitleBar.InLowBackLight = 0 @@ -268,10 +271,11 @@ func run() int { UI.SwapAndShow() //fmt.Println(main_screen) - event.AllocEvents(3) + event.AllocEvents(4) event.AddCustomEvent(UI.RUNEVT) event.AddCustomEvent(UI.RUNSH) - + event.AddCustomEvent(UI.RUNSYS) + go FlashLed1(main_screen) go InspectionTeam(main_screen) @@ -307,7 +311,22 @@ func run() int { fmt.Println(err) } os.Exit(0) - + + case UI.RUNSYS: + main_screen.OnExitCb() + gogame.Quit() + exec_app_cmd := ev.Data["Msg"] + cmd := exec.Command("/bin/sh","-c",exec_app_cmd) + err := cmd.Start() + if err != nil { + fmt.Println(err) + } + err = cmd.Process.Release() + if err != nil { + fmt.Println(err) + } + os.Exit(0) + case UI.RUNSH: main_screen.OnExitCb() gogame.Quit() diff --git a/mainscreen.go b/mainscreen.go index f850ed8..5c12edf 100644 --- a/mainscreen.go +++ b/mainscreen.go @@ -19,11 +19,13 @@ import ( "github.com/cuu/LauncherGoDev/sysgo/UI" "github.com/cuu/LauncherGoDev/sysgo/UI/Emulator" "github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings" + "github.com/cuu/LauncherGoDev/Menu/GameShell/99_PowerOFF" ) var ( UIPluginList = []*UI.UIPlugin { &UI.UIPlugin{1,"", "Menu/GameShell/10_Settings", "Settings", &Settings.APIOBJ}, + &UI.UIPlugin{1,"", "Menu/GameShell/99_PowerOFF", "PowerOFF", &PowerOFF.APIOBJ}, } ) diff --git a/sysgo/UI/events.go b/sysgo/UI/events.go index 05546c6..287427d 100644 --- a/sysgo/UI/events.go +++ b/sysgo/UI/events.go @@ -5,4 +5,6 @@ const ( RUNEVT=1 RESTARTUI=2 RUNSH=3 + RUNSYS=4 + )