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
This commit is contained in:
cuu 2021-10-10 12:44:05 +08:00
parent d463dd10ec
commit d3f3a4350b
11 changed files with 94 additions and 74 deletions

View File

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

View File

@ -502,9 +502,9 @@ func (self *PowerOptionsPage) Click() {
sysgo.CurPowerLevel = cur_li.Value sysgo.CurPowerLevel = cur_li.Value
if sysgo.CurPowerLevel == "supersaving" { 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{ }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") self.Screen.MsgBox.SetText("Applying")

View File

@ -19,7 +19,6 @@ import (
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Wifi" "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/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/Update"
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Storage" "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Storage"
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Languages" "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/Airplane"
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/ButtonsLayout" "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/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" "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,"", "About", "About", &About.APIOBJ},
&UI.UIPlugin{UI.PluginPackage,"", "PowerOFF", "Power off", &PowerOFF.APIOBJ}, &UI.UIPlugin{UI.PluginPackage,"", "PowerOFF", "Power off", &PowerOFF.APIOBJ},
&UI.UIPlugin{UI.PluginPackage,"", "ButtonsLayout", "Buttons Layout", &ButtonsLayout.APIOBJ}, &UI.UIPlugin{UI.PluginPackage,"", "ButtonsLayout", "Buttons Layout", &ButtonsLayout.APIOBJ},
&UI.UIPlugin{UI.PluginPackage,"", "LauncherPy", "Switch to Launcher", &LauncherPy.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,"", "Lima", "GPU Driver Switch", &Lima.APIOBJ},
&UI.UIPlugin{UI.PluginPackage,"", "GateWay", "Network gateway switch", &GateWay.APIOBJ}, &UI.UIPlugin{UI.PluginPackage,"", "GateWay", "Network gateway switch", &GateWay.APIOBJ},
} }

View File

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

View File

@ -6,25 +6,16 @@ package Sound
import ( import (
"errors" "errors"
"fmt" //"fmt"
"os" //"os"
"os/exec" //"os/exec"
"strings" //"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). // GetVolume returns the current volume (0 to 100).
func GetVolume() (int, error) { func GetVolume() (int, error) {
out, err := execCmd(getVolumeCmd()) out, err := UI.ExecCmd(getVolumeCmd())
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -36,19 +27,19 @@ func SetVolume(volume int) error {
if volume < 0 || 100 < volume { if volume < 0 || 100 < volume {
return errors.New("out of valid volume range") return errors.New("out of valid volume range")
} }
_, err := execCmd(setVolumeCmd(volume)) _, err := UI.ExecCmd(setVolumeCmd(volume))
return err return err
} }
// IncreaseVolume increases (or decreases) the audio volume by the specified value. // IncreaseVolume increases (or decreases) the audio volume by the specified value.
func IncreaseVolume(diff int) error { func IncreaseVolume(diff int) error {
_, err := execCmd(increaseVolumeCmd(diff)) _, err := UI.ExecCmd(increaseVolumeCmd(diff))
return err return err
} }
// GetMuted returns the current muted status. // GetMuted returns the current muted status.
func GetMuted() (bool, error) { func GetMuted() (bool, error) {
out, err := execCmd(getMutedCmd()) out, err := UI.ExecCmd(getMutedCmd())
if err != nil { if err != nil {
return false, err return false, err
} }
@ -57,12 +48,12 @@ func GetMuted() (bool, error) {
// Mute mutes the audio. // Mute mutes the audio.
func Mute() error { func Mute() error {
_, err := execCmd(muteCmd()) _, err := UI.ExecCmd(muteCmd())
return err return err
} }
// Unmute unmutes the audio. // Unmute unmutes the audio.
func Unmute() error { func Unmute() error {
_, err := execCmd(unmuteCmd()) _, err := UI.ExecCmd(unmuteCmd())
return err return err
} }

View File

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

View File

@ -15,6 +15,7 @@ import (
//"encoding/json" //"encoding/json"
gotime "time" gotime "time"
"github.com/veandco/go-sdl2/sdl" "github.com/veandco/go-sdl2/sdl"
//"github.com/go-ini/ini"
"github.com/cuu/gogame" "github.com/cuu/gogame"
"github.com/cuu/gogame/display" "github.com/cuu/gogame/display"
"github.com/cuu/gogame/event" "github.com/cuu/gogame/event"
@ -240,7 +241,7 @@ func PreparationInAdv(){
if UI.FileExists("sysgo/.powerlevel") == false { if UI.FileExists("sysgo/.powerlevel") == false {
UI.System("touch sysgo/.powerlevel") 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{ }else{
b, err := ioutil.ReadFile("sysgo/.powerlevel") b, err := ioutil.ReadFile("sysgo/.powerlevel")
@ -253,12 +254,12 @@ func PreparationInAdv(){
if pwl != ""{ if pwl != ""{
sysgo.CurPowerLevel = pwl sysgo.CurPowerLevel = pwl
if pwl == "supersaving" { 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{ }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 { }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))
} }
} }

View File

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

View File

@ -286,3 +286,17 @@ func SystemTrim(cmd string) string {
return strings.Trim(ret,"\r\n") 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
}

View File

@ -1,5 +1,12 @@
package sysgo package sysgo
import (
"fmt"
"os"
"github.com/go-ini/ini"
)
type PowerLevel struct { type PowerLevel struct {
Dim int Dim int
Close int Close int
@ -9,8 +16,8 @@ type PowerLevel struct {
var PowerLevels map[string]*PowerLevel var PowerLevels map[string]*PowerLevel
var ( var (
CurKeySet = "PC" // PC or GameShell //CurKeySet = "PC" // PC or GameShell
//CurKeySet = "GameShell" CurKeySet = "GameShell"
DontLeave = false DontLeave = false
BackLight = "/proc/driver/backlight" BackLight = "/proc/driver/backlight"
Battery = "/sys/class/power_supply/axp20x-battery/uevent" Battery = "/sys/class/power_supply/axp20x-battery/uevent"
@ -25,9 +32,7 @@ var (
//load from dot files //load from dot files
CurPowerLevel= "performance" CurPowerLevel= "performance"
Lang = "English" Lang = "English"
//WifiDev = "wlan0" WifiDev = "wlan0"
WifiDev = "wlp5s0"
) )
@ -40,4 +45,37 @@ func init() {
PowerLevels["server"] = &PowerLevel{40, 120, 0 } PowerLevels["server"] = &PowerLevel{40, 120, 0 }
PowerLevels["performance"] = &PowerLevel{40, 0, 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()
}
}
}
}
} }