瀏覽代碼

disable power_save at startup

cuu 5 年之前
父節點
當前提交
edc07725d2
共有 4 個文件被更改,包括 83 次插入4 次删除
  1. 12 0
      .gitignore
  2. 50 3
      main.go
  3. 20 0
      sysgo/UI/util_funcs.go
  4. 1 1
      sysgo/config.go

+ 12 - 0
.gitignore

@@ -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
+

+ 50 - 3
main.go

@@ -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()

+ 20 - 0
sysgo/UI/util_funcs.go

@@ -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
+}

+ 1 - 1
sysgo/config.go

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