fix gotime TimeTicker issue,use sqlite3 to store wifi password

This commit is contained in:
cuu 2021-10-30 01:29:27 +08:00
parent 15e7d79b9b
commit 06f7589f8b
7 changed files with 100 additions and 32 deletions

View File

@ -28,7 +28,8 @@ import (
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOFF" "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOFF"
"github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOptions" "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOptions"
"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/LauncherPy"
"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"
@ -113,8 +114,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

@ -4,14 +4,17 @@ package Wifi
import ( import (
"fmt" "fmt"
//"strconv" "strconv"
"strings" "strings"
//"os" //"os"
// "os/exec" // "os/exec"
// gotime "time" // gotime "time"
"log"
//"github.com/godbus/dbus" //"github.com/godbus/dbus"
"database/sql"
_ "github.com/mattn/go-sqlite3"
"github.com/veandco/go-sdl2/ttf" "github.com/veandco/go-sdl2/ttf"
"github.com/clockworkpi/LauncherGoDev/sysgo" "github.com/clockworkpi/LauncherGoDev/sysgo"
@ -524,6 +527,64 @@ func (self *WifiList) SaveNetworkList() {
} }
func (self *WifiList) SaveWifiPassword(essid,password string) {
db, err := sql.Open("sqlite3", sysgo.SQLDB)
if err != nil {
log.Fatal(err)
return
}
defer db.Close()
stmt, err := db.Prepare("select count(*) from wifi where essid = ?")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
var count string
err = stmt.QueryRow(essid).Scan(&count)
if err != nil {
log.Fatal(err)
}
cnt,_ := strconv.Atoi(count)
if cnt > 0 {
_,err = db.Exec("update wifi set pass= :pass where essid = :essid",sql.Named("pass",password),sql.Named("essid",essid))
if err != nil {
log.Fatal(err)
}
}else {
_,err = db.Exec("insert into wifi(essid,pass) values(:essid,:pass)",sql.Named("essid",essid),sql.Named("pass",password))
if err != nil {
log.Fatal(err)
}
}
}
func (self *WifiList) LoadWifiPassword(essid string) string {
db, err := sql.Open("sqlite3", sysgo.SQLDB)
if err != nil {
log.Fatal(err)
return ""
}
defer db.Close()
stmt, err := db.Prepare("select pass from wifi where essid = ?")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
password := ""
err = stmt.QueryRow(essid).Scan(&password)
if err != nil {
log.Fatal(err)
}
return password
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
func (self *WifiList) UpdateNetList(state int, info []string, force_check bool, firstrun bool) { //force_check default ==false, firstrun default == false func (self *WifiList) UpdateNetList(state int, info []string, force_check bool, firstrun bool) { //force_check default ==false, firstrun default == false
@ -560,6 +621,7 @@ func (self *WifiList) ConfigWireless(password string) {
self.CurEssid = self.MyList[self.PsIndex].Essid self.CurEssid = self.MyList[self.PsIndex].Essid
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
self.SaveWifiPassword(ssid,password)
self.ShowBox("Connected") self.ShowBox("Connected")
} else { } else {
self.ShowBox("Wifi connect error") self.ShowBox("Wifi connect error")
@ -673,7 +735,7 @@ func (self *WifiList) KeyDown(ev *event.Event) {
self.Screen.PushCurPage() self.Screen.PushCurPage()
self.Screen.SetCurPage(APIOBJ.PasswordPage) self.Screen.SetCurPage(APIOBJ.PasswordPage)
thepass := self.MyList[self.PsIndex].Password thepass := self.LoadWifiPassword(self.MyList[self.PsIndex].Essid)
fmt.Println("APIOBJ.PasswordPage.SetPassword ", thepass, len(thepass)) fmt.Println("APIOBJ.PasswordPage.SetPassword ", thepass, len(thepass))
APIOBJ.PasswordPage.SetPassword(thepass) APIOBJ.PasswordPage.SetPassword(thepass)

View File

@ -61,7 +61,6 @@ type WareHouse struct {
resp *grab.Response resp *grab.Response
req *grab.Request req *grab.Request
RefreshTicker *gotime.Ticker
ScrolledCnt int ScrolledCnt int
} }
@ -75,7 +74,7 @@ func NewWareHouse() *WareHouse {
p.FootMsg = [5]string{"Nav","Update","Up","Back","Select"} p.FootMsg = [5]string{"Nav","Update","Up","Back","Select"}
p.WareHouseDB = "foo.db" p.WareHouseDB = sysgo.SQLDB
p.BGwidth = 320 p.BGwidth = 320
p.BGheight = 240-24-20 p.BGheight = 240-24-20
@ -115,10 +114,12 @@ func (self *WareHouse) GetAria2DownloadingPercent(url string) int {
} }
func (self *WareHouse) UpdateProcessInterval(ms int) { func (self *WareHouse) UpdateProcessInterval(ms int) {
dirty := false dirty := false
RefreshTicker := gotime.NewTicker(gotime.Duration(ms)*gotime.Millisecond)
defer RefreshTicker.Stop()
L: L:
for { for {
select { select {
case <- self.RefreshTicker.C: case <- RefreshTicker.C:
for _,i := range self.MyList { for _,i := range self.MyList {
x := i.(*WareHouseListItem) x := i.(*WareHouseListItem)
if x.Type == "launcher" || x.Type == "pico8" || x.Type == "tic80" { if x.Type == "launcher" || x.Type == "pico8" || x.Type == "tic80" {
@ -405,11 +406,6 @@ func (self *WareHouse) Init() {
self.Downloader = grab.NewClient() self.Downloader = grab.NewClient()
self.Downloading = make(chan bool,1) self.Downloading = make(chan bool,1)
self.RefreshTicker = gotime.NewTicker(500 * gotime.Millisecond)
//self.RefreshTicker.Stop()
self.SetDownloading(true)
go self.UpdateProcessInterval(500)
} }
} }
@ -771,10 +767,6 @@ func (self *WareHouse) OnKbdReturnBackCb() {
func (self *WareHouse) OnExitCb() { func (self *WareHouse) OnExitCb() {
if self.RefreshTicker != nil {
self.RefreshTicker.Stop()
}
self.SetDownloading(false) self.SetDownloading(false)
self.rpcc.Close() self.rpcc.Close()
@ -790,7 +782,8 @@ func (self *WareHouse) OnLoadCb() {
self.FootMsg[1] = "Preview" self.FootMsg[1] = "Preview"
} }
self.RefreshTicker = gotime.NewTicker(500 * gotime.Millisecond) self.SetDownloading(true)
go self.UpdateProcessInterval(500)
self.SyncList() self.SyncList()
} }
@ -895,7 +888,7 @@ func (self *WareHouse) KeyDown(ev *event.Event) {
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
self.Screen.Draw() self.Screen.Draw()
self.Screen.SwapAndShow() self.Screen.SwapAndShow()
self.RefreshTicker.Stop() self.SetDownloading(false)//shutdown UpdateProcessInterval
} }
} }

View File

@ -71,6 +71,20 @@ func InitSql() {
log.Printf("%q: %s\n",err,sqlStmt) log.Printf("%q: %s\n",err,sqlStmt)
return return
} }
sqlStmt = `
CREATE TABLE IF NOT EXISTS wifi (
id integer PRIMARY KEY,
essid text NOT NULL,
pass text NOT NULL
);
`
_,err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n",err,sqlStmt)
return
}
} }
func main() { func main() {

View File

@ -10,7 +10,7 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall" //"syscall"
//"encoding/json" //"encoding/json"
"github.com/veandco/go-sdl2/sdl" "github.com/veandco/go-sdl2/sdl"
gotime "time" gotime "time"

View File

@ -31,7 +31,6 @@ type CounterScreen struct {
inter_counter int // inter_counter int //
TheTicker *gotime.Ticker
TickerStoped chan bool TickerStoped chan bool
} }
@ -52,15 +51,16 @@ func NewCounterScreen() *CounterScreen {
} }
func (self *CounterScreen) Interval() { func (self *CounterScreen) Interval() {
TheTicker := gotime.NewTicker(500 * gotime.Millisecond)
defer TheTicker.Stop()
L:
for { for {
select { select {
case <-self.TheTicker.C: case <-TheTicker.C:
self.inter_counter += 1 self.inter_counter += 1
if self.Number == 0 { if self.Number == 0 {
self.Counting = false self.Counting = false
self.TheTicker.Stop()
fmt.Println("do the real shutdown") fmt.Println("do the real shutdown")
if sysgo.CurKeySet != "PC" { if sysgo.CurKeySet != "PC" {
@ -71,7 +71,7 @@ func (self *CounterScreen) Interval() {
} }
break break L
} }
if self.inter_counter >= 2 { if self.inter_counter >= 2 {
@ -88,7 +88,7 @@ func (self *CounterScreen) Interval() {
} }
case <-self.TickerStoped: case <-self.TickerStoped:
break break L
} }
} }
@ -104,8 +104,6 @@ func (self *CounterScreen) StartCounter() {
self.Counting = true self.Counting = true
self.TheTicker = gotime.NewTicker(500 * gotime.Millisecond)
go self.Interval() go self.Interval()
} }
@ -119,7 +117,6 @@ func (self *CounterScreen) StopCounter() {
self.Number = 0 self.Number = 0
self.inter_counter = 0 self.inter_counter = 0
self.TheTicker.Stop()
self.TickerStoped <- true self.TickerStoped <- true
} }

View File

@ -34,6 +34,7 @@ var (
WifiDev = "wlan0" WifiDev = "wlan0"
Aria2Url = "ws://localhost:6800/jsonrpc" Aria2Url = "ws://localhost:6800/jsonrpc"
SQLDB = "foo.db" //Sqlite3
) )
func init() { func init() {