From 8ee8d42cb553b1e465cb0a2eeef5e036e8898b79 Mon Sep 17 00:00:00 2001 From: cuu Date: Wed, 19 Dec 2018 19:01:39 +0800 Subject: [PATCH] add PowerOFF in Settings --- .../10_Settings/PowerOFF/plugin_init.go | 39 +++++++++++ .../PowerOFF/poweroff_confirm_page.go | 64 +++++++++++++++++++ Menu/GameShell/10_Settings/Settings.go | 5 +- 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 Menu/GameShell/10_Settings/PowerOFF/plugin_init.go create mode 100644 Menu/GameShell/10_Settings/PowerOFF/poweroff_confirm_page.go diff --git a/Menu/GameShell/10_Settings/PowerOFF/plugin_init.go b/Menu/GameShell/10_Settings/PowerOFF/plugin_init.go new file mode 100644 index 0000000..14f8691 --- /dev/null +++ b/Menu/GameShell/10_Settings/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/10_Settings/PowerOFF/poweroff_confirm_page.go b/Menu/GameShell/10_Settings/PowerOFF/poweroff_confirm_page.go new file mode 100644 index 0000000..2a848bd --- /dev/null +++ b/Menu/GameShell/10_Settings/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 sysgo/gameshell/wallpaper/seeyou.png;" + cmdpath += "sleep 3;" + cmdpath += "sudo reboot" + + event.Post(UI.RUNSYS,cmdpath) + } + +} diff --git a/Menu/GameShell/10_Settings/Settings.go b/Menu/GameShell/10_Settings/Settings.go index 1678594..c675b12 100644 --- a/Menu/GameShell/10_Settings/Settings.go +++ b/Menu/GameShell/10_Settings/Settings.go @@ -22,7 +22,8 @@ import ( "github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings/LauncherPy" "github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings/Update" "github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings/Storage" - + + "github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings/PowerOFF" ) type SettingsPageSelector struct { @@ -99,7 +100,7 @@ func (self *SettingsPage) GenList() []*UI.UIPlugin { &UI.UIPlugin{0,"", "Storage", "", &Storage.APIOBJ}, &UI.UIPlugin{0,"", "Update", "Update", &Update.APIOBJ}, &UI.UIPlugin{0,"", "About", "About", &About.APIOBJ}, - + &UI.UIPlugin{0,"", "PowerOFF", "Power off", &PowerOFF.APIOBJ}, &UI.UIPlugin{1,"", "LauncherPy", "Switch to Launcher", &LauncherPy.APIOBJ}, }