Bläddra i källkod

replace wlan0 to sysgo.WifiDev

move execCmd to UI.ExecCmd

add read app-local.ini in config.go for dev/ run launcher out of
GameShell
cuu 2 år sedan
förälder
incheckning
d3f3a4350b

+ 3 - 3
Menu/GameShell/10_Settings/GateWay/gateway_page.go

@@ -151,7 +151,7 @@ func (self *GateWayPage) GenList() {
   last_height := 0
   
   var drivers  = [][2]string{[2]string{"usb0","USB Ethernet"},
-                             [2]string{"wlan0","Wi-Fi"}}
+                             [2]string{sysgo.WifiDev,"Wi-Fi"}}
   
 
   for _,u := range drivers {
@@ -318,8 +318,8 @@ func (self *GateWayPage) OnLoadCb() {
     if len(out) > 7 {
       if strings.Contains(out,"usb0") {
         thedrv = "usb0"
-      }else if strings.Contains(out,"wlan0") {
-        thedrv = "wlan0"
+      }else if strings.Contains(out,sysgo.WifiDev) {
+        thedrv = sysgo.WifiDev
       }
     }
   }

+ 2 - 2
Menu/GameShell/10_Settings/PowerOptions/power_options_page.go

@@ -502,9 +502,9 @@ func (self *PowerOptionsPage) Click() {
   sysgo.CurPowerLevel = cur_li.Value
   
   if sysgo.CurPowerLevel == "supersaving" {
-    UI.System("sudo iw wlan0 set power_save on >/dev/null")
+    UI.System(fmt.Sprintf("sudo iw %s set power_save on >/dev/null",sysgo.WifiDev))
   }else{
-    UI.System("sudo iw wlan0 set power_save off >/dev/null")
+    UI.System(fmt.Sprintf("sudo iw %s set power_save off >/dev/null",sysgo.WifiDev))
   }
   
   self.Screen.MsgBox.SetText("Applying")

+ 3 - 4
Menu/GameShell/10_Settings/Settings.go

@@ -19,7 +19,6 @@ import (
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Wifi"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Bluetooth"
   
-  "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/LauncherPy"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Update"
 	"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Storage"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Languages"
@@ -29,7 +28,7 @@ import (
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Airplane"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/ButtonsLayout"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/TimeZone"
-  "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Lima"
+  //"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Lima"
   "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/GateWay"
 
   
@@ -117,8 +116,8 @@ func (self *SettingsPage) GenList() []*UI.UIPlugin {
     &UI.UIPlugin{UI.PluginPackage,"",    "About",          "About",                   &About.APIOBJ},
     &UI.UIPlugin{UI.PluginPackage,"",    "PowerOFF",       "Power off",               &PowerOFF.APIOBJ},
     &UI.UIPlugin{UI.PluginPackage,"",    "ButtonsLayout",  "Buttons Layout",          &ButtonsLayout.APIOBJ},    
-    &UI.UIPlugin{UI.PluginPackage,"",    "LauncherPy",     "Switch to Launcher",      &LauncherPy.APIOBJ},
-    &UI.UIPlugin{UI.PluginPackage,"",    "Lima",           "GPU Driver Switch",       &Lima.APIOBJ},
+		// &UI.UIPlugin{UI.PluginPackage,"",    "LauncherPy",     "Switch to Launcher",      &LauncherPy.APIOBJ},
+    //&UI.UIPlugin{UI.PluginPackage,"",    "Lima",           "GPU Driver Switch",       &Lima.APIOBJ},
     &UI.UIPlugin{UI.PluginPackage,"",    "GateWay",        "Network gateway switch",  &GateWay.APIOBJ},
   }
   

+ 0 - 4
Menu/GameShell/10_Settings/Sound/volume_linux.go

@@ -20,10 +20,6 @@ func init() {
 	}
 }
 
-func cmdEnv() []string {
-	return []string{"LANG=C", "LC_ALL=C"}
-}
-
 func getVolumeCmd() []string {
 	if useAmixer {
 		return []string{"amixer", "get", "Master"}

+ 11 - 20
Menu/GameShell/10_Settings/Sound/volume_unix.go

@@ -6,25 +6,16 @@ package Sound
 
 import (
 	"errors"
-	"fmt"
-	"os"
-	"os/exec"
-	"strings"
+	//"fmt"
+	//"os"
+	//"os/exec"
+	//"strings"
+	"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
 )
 
-func execCmd(cmdArgs []string) ([]byte, error) {
-	cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
-	cmd.Env = append(os.Environ(), cmdEnv()...)
-	out, err := cmd.Output()
-	if err != nil {
-		err = fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(cmdArgs, " "), err)
-	}
-	return out, err
-}
-
 // GetVolume returns the current volume (0 to 100).
 func GetVolume() (int, error) {
-	out, err := execCmd(getVolumeCmd())
+	out, err := UI.ExecCmd(getVolumeCmd())
 	if err != nil {
 		return 0, err
 	}
@@ -36,19 +27,19 @@ func SetVolume(volume int) error {
 	if volume < 0 || 100 < volume {
 		return errors.New("out of valid volume range")
 	}
-	_, err := execCmd(setVolumeCmd(volume))
+	_, err := UI.ExecCmd(setVolumeCmd(volume))
 	return err
 }
 
 // IncreaseVolume increases (or decreases) the audio volume by the specified value.
 func IncreaseVolume(diff int) error {
-	_, err := execCmd(increaseVolumeCmd(diff))
+	_, err := UI.ExecCmd(increaseVolumeCmd(diff))
 	return err
 }
 
 // GetMuted returns the current muted status.
 func GetMuted() (bool, error) {
-	out, err := execCmd(getMutedCmd())
+	out, err := UI.ExecCmd(getMutedCmd())
 	if err != nil {
 		return false, err
 	}
@@ -57,12 +48,12 @@ func GetMuted() (bool, error) {
 
 // Mute mutes the audio.
 func Mute() error {
-	_, err := execCmd(muteCmd())
+	_, err := UI.ExecCmd(muteCmd())
 	return err
 }
 
 // Unmute unmutes the audio.
 func Unmute() error {
-	_, err := execCmd(unmuteCmd())
+	_, err := UI.ExecCmd(unmuteCmd())
 	return err
 }

+ 1 - 1
Menu/GameShell/10_Settings/Wifi/plugin_init.go

@@ -32,7 +32,7 @@ var (
 
 
 func (self *WifiPlugin) Init( main_screen *UI.MainScreen ) {
-
+		
   self.PasswordPage = UI.NewKeyboard()
   self.PasswordPage.Name = "Enter wifi password"
   self.PasswordPage.Screen= main_screen

+ 7 - 24
Menu/GameShell/10_Settings/Wifi/wifi.go

@@ -5,8 +5,8 @@ import (
     "fmt"
     //"strconv"
     "strings"
-    "os"
-    "os/exec"
+	//"os"
+	// "os/exec"
     gotime "time"
 
     //"github.com/godbus/dbus"
@@ -33,21 +33,6 @@ type WifiDisconnectConfirmPage struct {
   Parent *WifiInfoPage
 }
 
-func cmdEnv() []string {
-	return []string{"LANG=C", "LC_ALL=C"}
-}
-
-func execCmd(cmdArgs []string) ([]byte, error) {
-	cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
-	cmd.Env = append(os.Environ(), cmdEnv()...)
-	out, err := cmd.Output()
-	if err != nil {
-		err = fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(cmdArgs, " "), err)
-	}
-	return out, err
-}
-
-
 func NewWifiDisconnectConfirmPage() *WifiDisconnectConfirmPage {
   p := &WifiDisconnectConfirmPage{}  
   p.ListFont = UI.Fonts["veramono20"]
@@ -488,10 +473,10 @@ func (self *WifiList) Disconnect() {
   self.Connecting = false
 	
   wpa_cli_disconnect := []string{"wpa_cli","disconnect",self.CurEssid,"-i",sysgo.WifiDev}
-  execCmd( wpa_cli_disconnect )
+  UI.ExecCmd( wpa_cli_disconnect )
 	fmt.Println(wpa_cli_disconnect)
 	dhcp_release := []string{"dhclient","-r",sysgo.WifiDev}
-	execCmd(dhcp_release)
+	UI.ExecCmd(dhcp_release)
 
 	self.CurEssid = ""
 	self.CurBssid = ""
@@ -578,7 +563,7 @@ func (self *WifiList) ConfigWireless(password string) {
 		self.CurBssid = self.MyList[self.PsIndex].Bssid
     self.MyList[self.PsIndex].Password = password
     dhcp := []string{"dhclient" ,sysgo.WifiDev}
-    execCmd(dhcp)
+    UI.ExecCmd(dhcp)
     GsConnectManager.ReadNetAddress(gotime.Second*3)
 		self.CurIP = GsConnectManager.IPv4().String()
 		self.ShowBox("Connected")
@@ -603,10 +588,8 @@ func (self *WifiList) ConfigWireless(password string) {
 func (self *WifiList) GetWirelessIP() string {
 
   cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
-  out := UI.System(cli)
-  if len(out) > 5 {
-		out = strings.TrimSuffix(out,"\n")
-	}
+  out := UI.SystemTrim(cli)
+	
   return out
   
 }

+ 7 - 6
main.go

@@ -15,6 +15,7 @@ import (
   //"encoding/json"
 	gotime "time"
 	"github.com/veandco/go-sdl2/sdl"
+	//"github.com/go-ini/ini"
 	"github.com/cuu/gogame"
 	"github.com/cuu/gogame/display"
 	"github.com/cuu/gogame/event"
@@ -240,7 +241,7 @@ func PreparationInAdv(){
   
   if UI.FileExists("sysgo/.powerlevel") == false {
     UI.System("touch sysgo/.powerlevel")
-    UI.System("sudo iw wlan0 set power_save off >/dev/null")
+    UI.System(fmt.Sprintf("sudo iw %s set power_save off >/dev/null",sysgo.WifiDev))
     
   }else{
     b, err := ioutil.ReadFile("sysgo/.powerlevel")
@@ -253,12 +254,12 @@ func PreparationInAdv(){
     if pwl != ""{
       sysgo.CurPowerLevel = pwl
       if pwl == "supersaving" {
-        UI.System("sudo iw wlan0 set power_save on >/dev/null")
+        UI.System(fmt.Sprintf("sudo iw %s set power_save on >/dev/null",sysgo.WifiDev))
       }else{
-        UI.System("sudo iw wlan0 set power_save off >/dev/null")
+        UI.System(fmt.Sprintf("sudo iw %s set power_save off >/dev/null",sysgo.WifiDev))
       }
     }else {
-      UI.System("sudo iw wlan0 set power_save off >/dev/null")
+      UI.System(fmt.Sprintf("sudo iw %s set power_save off >/dev/null",sysgo.WifiDev))
     }
   }
   
@@ -299,7 +300,7 @@ func run() int {
 	display.Init()
 	font.Init()
 	screen := display.SetMode(int32(UI.Width),int32(UI.Height),0,32)
-    
+
 	UI.Init()
   
   PreparationInAdv()
@@ -495,7 +496,7 @@ func run() int {
 func main() {
 	
 	var exitcode int
-  
+
   //runtime.GOMAXPROCS(1)
   
 	os.Setenv("SDL_VIDEO_CENTERED","1")

+ 2 - 4
sysgo/UI/main_screen.go

@@ -364,10 +364,8 @@ func (self *MainScreen) IsWifiConnectedNow() bool {
 func (self *MainScreen) GetWirelessIP() string {
 
   cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
-  out := System(cli)
-  if len(out) > 5 {
-		out = strings.TrimSuffix(out,"\n")
-	}
+  out := SystemTrim(cli)
+
 	
   return out	
 }

+ 14 - 0
sysgo/UI/util_funcs.go

@@ -286,3 +286,17 @@ func SystemTrim(cmd string) string {
 
   return strings.Trim(ret,"\r\n")
 }
+
+func cmdEnv() []string {
+	return []string{"LANG=C", "LC_ALL=C"}
+}
+
+func ExecCmd(cmdArgs []string) ([]byte, error) {
+	cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
+	cmd.Env = append(os.Environ(), cmdEnv()...)
+	out, err := cmd.Output()
+	if err != nil {
+		err = fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(cmdArgs, " "), err)
+	}
+	return out, err
+}

+ 44 - 6
sysgo/config.go

@@ -1,5 +1,12 @@
 package sysgo
 
+import (
+	"fmt"
+	"os"
+	"github.com/go-ini/ini"
+	
+)
+
 type PowerLevel struct {
   Dim int
   Close  int
@@ -9,8 +16,8 @@ type PowerLevel struct {
 var PowerLevels map[string]*PowerLevel
 
 var (
-  CurKeySet = "PC" // PC or GameShell
-  //CurKeySet = "GameShell"
+  //CurKeySet = "PC" // PC or GameShell
+  CurKeySet = "GameShell"
   DontLeave = false
   BackLight = "/proc/driver/backlight"
   Battery   = "/sys/class/power_supply/axp20x-battery/uevent"
@@ -25,10 +32,8 @@ var (
   //load from dot files   
   CurPowerLevel= "performance"
   Lang        = "English"
-  //WifiDev     = "wlan0"
-	WifiDev     = "wlp5s0"
-
-  
+  WifiDev     = "wlan0"
+	
 )
 
 
@@ -40,4 +45,37 @@ func init() {
     PowerLevels["server"]      = &PowerLevel{40, 120, 0  }
     PowerLevels["performance"] = &PowerLevel{40, 0,   0  }
   }
+
+	//sudo LauncherGoDev=1 ./launchergo # for develop code on PC
+	dev_mode := os.Getenv("LauncherGoDev")
+	
+	if len(dev_mode) < 1 {
+		return
+	}
+	
+	if _, err := os.Stat("app-local.ini" ); err == nil {
+		load_opts := ini.LoadOptions{
+			IgnoreInlineComment:true,
+		}
+		cfg, err := ini.LoadSources(load_opts, "app-local.ini" )
+		if err != nil {
+			fmt.Printf("Fail to read file: %v\n", err)
+			return
+		}
+		section := cfg.Section("GameShell")
+		if section != nil {
+			gs_opts := section.KeyStrings()
+			for i,v := range gs_opts {
+				fmt.Println(i,v, section.Key(v).String())
+				switch v{
+					case "WifiDev":
+					WifiDev = section.Key(v).String()
+					case "CurKeySet":
+					CurKeySet = section.Key(v).String()
+					
+				}
+			}
+		}
+	}
+	
 }