disable power_save at startup

This commit is contained in:
cuu 2018-12-07 23:29:32 +08:00
parent c624d42977
commit edc07725d2
4 changed files with 83 additions and 4 deletions

12
.gitignore vendored
View File

@ -1,3 +1,15 @@
test
main
*.so
retroarch-core-options.cfg
*.lpl
*.swp
.bsv
*.pyc
sysgo/.powerlevel
sysgo/.buttonslayout
sysgo/.lang
*.cfg
**/Jobs/*
!**/Jobs/.gitkeep

53
main.go
View File

@ -7,10 +7,11 @@ import (
"io/ioutil"
"strconv"
"strings"
"runtime"
gotime "time"
"github.com/veandco/go-sdl2/sdl"
"github.com/cuu/gogame"
"github.com/cuu/gogame/display"
"github.com/cuu/gogame/event"
// "github.com/cuu/gogame/color"
@ -199,6 +200,33 @@ func InspectionTeam(main_screen *UI.MainScreen) {
}
}
func PreparationInAdv(){
if strings.Contains(runtime.GOARCH,"arm") == false {
return
}
if UI.FileExists("sysgo/.powerlevel") == false {
UI.System("touch sysgo/.powerlevel")
UI.System("sudo iw wlan0 set power_save off >/dev/null")
}else{
b, err := ioutil.ReadFile("sysgo/.powerlevel")
if err != nil {
log.Fatal(err)
}
pwl := strings.Trim(string(b),"\r\n ")
if pwl == "supersaving" {
UI.System("sudo iw wlan0 set power_save on >/dev/null")
}else{
UI.System("sudo iw wlan0 set power_save off >/dev/null")
}
}
}
func run() int {
display.Init()
font.Init()
@ -206,7 +234,9 @@ func run() int {
UI.Init()
UI.MyIconPool.Init()
PreparationInAdv()
main_screen := UI.NewMainScreen()
main_screen.HWND = screen
main_screen.Init()
@ -243,8 +273,25 @@ func run() int {
break
}
if ev.Type == event.USEREVENT {
fmt.Println("UserEvent: ",ev.Data["Msg"])
switch ev.Code {
case UI.RUNEVT:
main_screen.OnExitCb()
gogame.Quit()
fmt.Println("RUNEVT")
exec_app_cmd := "cd " + filepath.Dir(ev.Data["Msg"])+";"
exec_app_cmd += ev.Data["Msg"]
exec_app_cmd +="; sync & cd "+UI.GetExePath()+"; "+os.Args[0]
fmt.Println(exec_app_cmd)
}
}
if ev.Type == event.KEYDOWN {
everytime_keydown = gotime.Now()

View File

@ -111,6 +111,15 @@ func MakeExecutable(path string) {
os.Chmod(path,mode)
}
func GetExePath() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
return dir
}
func ReplaceSuffix(orig_file_str string, new_ext string) string {
orig_ext := filepath.Ext(orig_file_str)
if orig_ext!= "" {
@ -226,3 +235,14 @@ func CheckBattery() int {
return 0
}
func System(cmd string) string {
ret := ""
out,err := exec.Command("bash","-c",cmd).Output()
if err != nil {
fmt.Println(err)
}else {
ret = string(out)
}
return ret
}

View File

@ -22,7 +22,7 @@ var (
SKIN="default"
//load from dot files
CurPowerLevel= "supersaving"//"performance"
CurPowerLevel= "performance"
Lang = "English"
)