wifi.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. package Wifi
  2. //wifi_list.py
  3. import (
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. //"os"
  8. // "os/exec"
  9. // gotime "time"
  10. "log"
  11. //"github.com/godbus/dbus"
  12. "database/sql"
  13. _ "github.com/mattn/go-sqlite3"
  14. "github.com/veandco/go-sdl2/ttf"
  15. "github.com/clockworkpi/LauncherGoDev/sysgo"
  16. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  17. "github.com/cuu/gogame/color"
  18. "github.com/cuu/gogame/draw"
  19. "github.com/cuu/gogame/event"
  20. "github.com/cuu/gogame/font"
  21. "github.com/cuu/gogame/rect"
  22. "github.com/cuu/gogame/surface"
  23. "github.com/cuu/gogame/time"
  24. wifi "github.com/cuu/wpa-connect"
  25. )
  26. const EMPTY_NETWORK = "00:00:00:00:00:00"
  27. type WifiDisconnectConfirmPage struct {
  28. UI.ConfirmPage
  29. Parent *WifiInfoPage
  30. }
  31. func NewWifiDisconnectConfirmPage() *WifiDisconnectConfirmPage {
  32. p := &WifiDisconnectConfirmPage{}
  33. p.ListFont = UI.Fonts["veramono20"]
  34. p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
  35. p.ConfirmText = "Confirm Disconnect?"
  36. return p
  37. }
  38. func (self *WifiDisconnectConfirmPage) KeyDown(ev *event.Event) {
  39. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  40. self.ReturnToUpLevelPage()
  41. self.Screen.Draw()
  42. self.Screen.SwapAndShow()
  43. }
  44. if ev.Data["Key"] == UI.CurKeys["B"] {
  45. fmt.Println("Disconnecting..")
  46. self.SnapMsg("Disconnecting...")
  47. self.Screen.Draw()
  48. self.Screen.SwapAndShow()
  49. self.Parent.Parent.Disconnect()
  50. time.BlockDelay(400)
  51. self.ReturnToUpLevelPage()
  52. self.Screen.Draw()
  53. self.Screen.SwapAndShow()
  54. self.Parent.Parent.Rescan(false)
  55. }
  56. }
  57. type WifiInfoPage struct {
  58. UI.Page
  59. ListFontObj *ttf.Font
  60. Bss *wifi.BSS
  61. AList map[string]map[string]string
  62. ESSID string
  63. BSSID string
  64. MyList []UI.ListItemInterface
  65. DisconnectConfirmPage *WifiDisconnectConfirmPage //child page
  66. Parent *WifiList
  67. }
  68. func NewWifiInfoPage() *WifiInfoPage {
  69. p := &WifiInfoPage{}
  70. p.FootMsg = [5]string{"Nav", "Disconnect", "", "Back", ""}
  71. p.ListFontObj = UI.Fonts["varela15"]
  72. p.AList = make(map[string]map[string]string)
  73. p.BSSID = ""
  74. p.ESSID = ""
  75. return p
  76. }
  77. func (self *WifiInfoPage) GenList() {
  78. self.MyList = nil
  79. self.MyList = make([]UI.ListItemInterface, 0)
  80. if self.BSSID != "" {
  81. self.AList["ip"]["value"] = "Not Connected"
  82. if self.BSSID == self.Parent.CurBssid {
  83. var ip string
  84. ip = self.Parent.GetWirelessIP()
  85. if len(ip) > 0 {
  86. self.AList["ip"]["value"] = ip
  87. }
  88. } else {
  89. fmt.Println(self.BSSID)
  90. }
  91. self.AList["ssid"]["value"] = self.ESSID
  92. }
  93. start_x := 0
  94. start_y := 0
  95. i := 0
  96. for k, _ := range self.AList {
  97. li := UI.NewInfoPageListItem()
  98. li.Parent = self
  99. li.PosX = start_x
  100. li.PosY = start_y + i*li.Height //default is 30
  101. li.Width = UI.Width
  102. li.Fonts["normal"] = self.ListFontObj
  103. li.Fonts["small"] = UI.Fonts["varela12"]
  104. if self.AList[k]["label"] != "" {
  105. li.Init(self.AList[k]["label"])
  106. } else {
  107. li.Init(self.AList[k]["key"])
  108. }
  109. li.Flag = self.AList[k]["key"]
  110. li.SetSmallText(self.AList[k]["value"])
  111. self.MyList = append(self.MyList, li)
  112. i += 1
  113. }
  114. }
  115. func (self *WifiInfoPage) Init() {
  116. if self.Screen != nil {
  117. if self.Screen.CanvasHWND != nil && self.CanvasHWND == nil {
  118. self.CanvasHWND = self.Screen.CanvasHWND
  119. }
  120. }
  121. self.PosX = self.Index * self.Screen.Width
  122. self.Width = self.Screen.Width
  123. self.Height = self.Screen.Height
  124. ps := UI.NewInfoPageSelector()
  125. ps.Parent = self
  126. ps.PosX = 2
  127. self.Ps = ps
  128. self.PsIndex = 0
  129. ip := make(map[string]string) // ip = {}
  130. ip["key"] = "ip"
  131. ip["label"] = "IP"
  132. ip["value"] = "Not Connected"
  133. ssid := make(map[string]string) // ssid = {}
  134. ssid["key"] = "ssid"
  135. ssid["label"] = "SSID"
  136. ssid["value"] = ""
  137. self.AList["ip"] = ip
  138. self.AList["ssid"] = ssid
  139. self.DisconnectConfirmPage = NewWifiDisconnectConfirmPage()
  140. self.DisconnectConfirmPage.Screen = self.Screen
  141. self.DisconnectConfirmPage.Name = "Confirm Disconnect"
  142. self.DisconnectConfirmPage.Parent = self
  143. self.DisconnectConfirmPage.Init()
  144. }
  145. func (self *WifiInfoPage) ScrollUp() {
  146. if len(self.MyList) == 0 {
  147. return
  148. }
  149. self.PsIndex -= 1
  150. if self.PsIndex < 0 {
  151. self.PsIndex = 0
  152. }
  153. cur_li := self.MyList[self.PsIndex]
  154. x, y := cur_li.Coord()
  155. if x < 0 {
  156. for i := 0; i < len(self.MyList); i++ {
  157. _, h := self.MyList[i].Size()
  158. x, y = self.MyList[i].Coord()
  159. self.MyList[i].NewCoord(x, y+h)
  160. }
  161. }
  162. }
  163. func (self *WifiInfoPage) ScrollDown() {
  164. if len(self.MyList) == 0 {
  165. return
  166. }
  167. self.PsIndex += 1
  168. if self.PsIndex >= len(self.MyList) {
  169. self.PsIndex = len(self.MyList) - 1
  170. }
  171. cur_li := self.MyList[self.PsIndex]
  172. x, y := cur_li.Coord()
  173. _, h := cur_li.Size()
  174. if y+h > self.Height {
  175. for i := 0; i < len(self.MyList); i++ {
  176. _, h = self.MyList[i].Size()
  177. x, y = self.MyList[i].Coord()
  178. self.MyList[i].NewCoord(x, y-h)
  179. }
  180. }
  181. }
  182. func (self *WifiInfoPage) Click() {
  183. /*
  184. cur_li = self._MyList[self._PsIndex]
  185. print(cur_li._Flag)
  186. */
  187. }
  188. func (self *WifiInfoPage) TryDisconnect() {
  189. var ip string
  190. ip = self.Parent.GetWirelessIP()
  191. if len(ip) > 6 {
  192. self.Screen.PushPage(self.DisconnectConfirmPage)
  193. self.Screen.Draw()
  194. self.Screen.SwapAndShow()
  195. } else {
  196. fmt.Println("WifiInfoPage TryDisconnect can not get IP,maybe you are offline")
  197. return
  198. }
  199. }
  200. func (self *WifiInfoPage) OnLoadCb() {
  201. /*
  202. self.FootMsg[1]="Disconnect"
  203. self.FootMsg[1] = ""
  204. */
  205. self.GenList()
  206. }
  207. func (self *WifiInfoPage) OnReturnBackCb() {
  208. self.ReturnToUpLevelPage()
  209. self.Screen.Draw()
  210. self.Screen.SwapAndShow()
  211. }
  212. func (self *WifiInfoPage) KeyDown(ev *event.Event) {
  213. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  214. self.ReturnToUpLevelPage()
  215. self.Screen.Draw()
  216. self.Screen.SwapAndShow()
  217. }
  218. if ev.Data["Key"] == UI.CurKeys["Up"] {
  219. self.ScrollUp()
  220. self.Screen.Draw()
  221. self.Screen.SwapAndShow()
  222. }
  223. if ev.Data["Key"] == UI.CurKeys["Down"] {
  224. self.ScrollDown()
  225. self.Screen.Draw()
  226. self.Screen.SwapAndShow()
  227. }
  228. if ev.Data["Key"] == UI.CurKeys["Enter"] {
  229. self.Click()
  230. }
  231. if ev.Data["Key"] == UI.CurKeys["X"] {
  232. self.TryDisconnect()
  233. }
  234. }
  235. func (self *WifiInfoPage) Draw() {
  236. self.ClearCanvas()
  237. self.Ps.Draw()
  238. for i := 0; i < len(self.MyList); i++ {
  239. self.MyList[i].Draw()
  240. }
  241. }
  242. type WifiListSelector struct {
  243. UI.PageSelector
  244. BackgroundColor *color.Color
  245. Parent *WifiList
  246. }
  247. func NewWifiListSelector() *WifiListSelector {
  248. p := &WifiListSelector{}
  249. p.BackgroundColor = &color.Color{131, 199, 219, 255} //SkinManager().GiveColor('Front')
  250. return p
  251. }
  252. func (self *WifiListSelector) Draw() {
  253. idx := self.Parent.PsIndex
  254. if idx < len(self.Parent.MyList) {
  255. x := self.Parent.MyList[idx].PosX + 11
  256. y := self.Parent.MyList[idx].PosY + 1
  257. h := self.Parent.MyList[idx].Height - 3
  258. self.PosX = x
  259. self.PosY = y
  260. self.Height = h
  261. rect_ := rect.Rect(x, y, self.Width, h)
  262. draw.AARoundRect(self.Parent.CanvasHWND, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
  263. }
  264. }
  265. type WifiListMessageBox struct {
  266. UI.Label
  267. Parent *WifiList
  268. }
  269. func NewWifiListMessageBox() *WifiListMessageBox {
  270. p := &WifiListMessageBox{}
  271. p.Color = &color.Color{83, 83, 83, 255}
  272. return p
  273. }
  274. func (self *WifiListMessageBox) Draw() {
  275. my_text := font.Render(self.FontObj, self.Text, true, self.Color, nil)
  276. w := surface.GetWidth(my_text)
  277. h := surface.GetHeight(my_text)
  278. x := (self.Parent.Width - w) / 2
  279. y := (self.Parent.Height - h) / 2
  280. padding := 10
  281. white := &color.Color{255, 255, 255, 255}
  282. black := &color.Color{0, 0, 0, 255}
  283. rect_ := rect.Rect(x-padding, y-padding, w+padding*2, h+padding*2)
  284. draw.Rect(self.CanvasHWND, white, &rect_, 0)
  285. draw.Rect(self.CanvasHWND, black, &rect_, 1)
  286. rect_2 := rect.Rect(x, y, w, h)
  287. surface.Blit(self.CanvasHWND, my_text, &rect_2, nil)
  288. my_text.Free()
  289. }
  290. //---------WifiList---------------------------------
  291. type BlockCbFunc func()
  292. type WifiList struct {
  293. UI.Page
  294. WifiPassword string
  295. Connecting bool
  296. Scanning bool
  297. ShowingMessageBox bool
  298. MsgBox *WifiListMessageBox
  299. ConnectTry int
  300. BlockingUI bool
  301. BlockCb BlockCbFunc
  302. LastStatusMsg string
  303. Scroller *UI.ListScroller
  304. ListFontObj *ttf.Font
  305. InfoPage *WifiInfoPage
  306. MyList []*NetItem
  307. CurEssid string ///SomeWifi
  308. CurBssid string //00:00:00:00:00:00
  309. CurIP string
  310. CurSig string
  311. }
  312. func NewWifiList() *WifiList {
  313. p := &WifiList{}
  314. p.ListFontObj = UI.Fonts["notosanscjk15"]
  315. p.FootMsg = [5]string{"Nav.", "Scan", "Info", "Back", "Enter"}
  316. return p
  317. }
  318. func (self *WifiList) ShowBox(msg string) {
  319. self.MsgBox.Text = msg
  320. self.ShowingMessageBox = true
  321. self.Screen.Draw()
  322. self.MsgBox.Draw()
  323. self.Screen.SwapAndShow()
  324. }
  325. func (self *WifiList) HideBox() {
  326. self.Draw()
  327. self.ShowingMessageBox = false
  328. self.Screen.SwapAndShow()
  329. }
  330. func (self *WifiList) GenNetworkList() {
  331. self.MyList = self.MyList[:0]
  332. start_x := 0
  333. start_y := 0
  334. var is_active bool
  335. var li_idx int
  336. li_idx = 0
  337. self.WifiScanStarted()
  338. if bssList, err := GsScanManager.Scan(); err == nil {
  339. self.CurEssid = GsScanManager.GetCurrentSSID()
  340. self.CurBssid = GsScanManager.GetCurrentBSSID()
  341. for _, bss := range bssList {
  342. is_active = false
  343. fmt.Println(bss.SSID, " ", bss.BSSID, " ", bss.Signal, bss.KeyMgmt)
  344. ni := NewNetItem()
  345. ni.Parent = self
  346. ni.PosX = start_x
  347. ni.PosY = start_y + li_idx*NetItemDefaultHeight
  348. ni.Width = UI.Width
  349. ni.FontObj = self.ListFontObj
  350. ni.Essid = bss.SSID
  351. ni.Bssid = bss.BSSID
  352. ni.Signal = bss.Signal
  353. if self.CurBssid == ni.Bssid {
  354. is_active = true
  355. }
  356. ni.Init(is_active)
  357. self.MyList = append(self.MyList, ni)
  358. li_idx++
  359. }
  360. }
  361. self.WifiScanFinished()
  362. self.PsIndex = 0
  363. }
  364. func (self *WifiList) Disconnect() {
  365. self.Connecting = false
  366. //nmcli -t -f NAME c show --active
  367. //nmcli con down
  368. cli := "nmcli -t -f NAME c show --active"
  369. out := UI.SystemTrim(cli)
  370. cli = fmt.Sprintf("sudo nmcli con down \"%s\"",out)
  371. UI.System(cli)
  372. self.CurEssid = ""
  373. self.CurBssid = ""
  374. }
  375. func (self *WifiList) ShutDownConnecting() {
  376. self.Connecting = false
  377. self.Disconnect()
  378. }
  379. func (self *WifiList) Rescan(sync bool) { // sync default should be false
  380. fmt.Println("start Rescan")
  381. self.GenNetworkList()
  382. }
  383. // dbus signal functions
  384. func (self *WifiList) WifiScanFinished() {
  385. if self.Screen.CurrentPage != self {
  386. return
  387. }
  388. self.ResetPageSelector()
  389. self.Scanning = false
  390. self.HideBox()
  391. self.BlockingUI = false
  392. fmt.Println("dbus says scan finished")
  393. }
  394. func (self *WifiList) WifiScanStarted() {
  395. if self.Screen.CurrentPage != self {
  396. return
  397. }
  398. self.Scanning = true
  399. self.ShowBox("Wifi scanning...")
  400. self.BlockingUI = true
  401. fmt.Println("dbus says start scan")
  402. }
  403. func (self *WifiList) SaveNetworkList() {
  404. }
  405. func (self *WifiList) SaveWifiPassword(essid,password string) {
  406. db, err := sql.Open("sqlite3", sysgo.SQLDB)
  407. if err != nil {
  408. log.Fatal(err)
  409. return
  410. }
  411. defer db.Close()
  412. stmt, err := db.Prepare("select count(*) from wifi where essid = ?")
  413. if err != nil {
  414. log.Println(err)
  415. return
  416. }
  417. defer stmt.Close()
  418. var count string
  419. err = stmt.QueryRow(essid).Scan(&count)
  420. if err != nil {
  421. log.Println(err)
  422. count = "0"
  423. }
  424. cnt,_ := strconv.Atoi(count)
  425. if cnt > 0 {
  426. _,err = db.Exec("update wifi set pass= :pass where essid = :essid",sql.Named("pass",password),sql.Named("essid",essid))
  427. if err != nil {
  428. log.Println(err)
  429. }
  430. }else {
  431. _,err = db.Exec("insert into wifi(essid,pass) values(:essid,:pass)",sql.Named("essid",essid),sql.Named("pass",password))
  432. if err != nil {
  433. log.Println(err)
  434. }
  435. }
  436. }
  437. func (self *WifiList) LoadWifiPassword(essid string) string {
  438. db, err := sql.Open("sqlite3", sysgo.SQLDB)
  439. if err != nil {
  440. log.Fatal(err)
  441. return ""
  442. }
  443. defer db.Close()
  444. password := ""
  445. stmt, err := db.Prepare("select pass from wifi where essid = ?")
  446. defer stmt.Close()
  447. if err != nil {
  448. log.Println(err)
  449. }else {
  450. err = stmt.QueryRow(essid).Scan(&password)
  451. if err != nil {
  452. log.Println(err)
  453. }
  454. }
  455. return password
  456. }
  457. //----------------------------------------------------------------------------------
  458. func (self *WifiList) UpdateNetList(state int, info []string, force_check bool, firstrun bool) { //force_check default ==false, firstrun default == false
  459. if force_check == true {
  460. self.GenNetworkList()
  461. self.SaveNetworkList()
  462. }
  463. }
  464. func (self *WifiList) UpdateListActive() {
  465. for i := 0; i < len(self.MyList); i++ {
  466. if self.MyList[i].Bssid == self.CurBssid {
  467. self.MyList[i].IsActive = true
  468. } else {
  469. self.MyList[i].IsActive = false
  470. }
  471. }
  472. }
  473. func (self *WifiList) ConfigWireless(password string) {
  474. ssid := self.MyList[self.PsIndex].Essid
  475. fmt.Println(ssid)
  476. fmt.Println(password)
  477. self.ShowBox("Connecting...")
  478. self.Connecting = true
  479. out := UI.System(fmt.Sprintf("sudo nmcli dev wifi connect %s password \"%s\"", ssid, password))
  480. if strings.Contains(out, "successfully") {
  481. self.CurEssid = self.MyList[self.PsIndex].Essid
  482. self.CurBssid = self.MyList[self.PsIndex].Bssid
  483. self.MyList[self.PsIndex].Password = password
  484. self.SaveWifiPassword(ssid,password)
  485. self.ShowBox("Connected")
  486. } else {
  487. self.ShowBox("Wifi connect error")
  488. self.CurEssid = ""
  489. self.CurBssid = ""
  490. }
  491. self.Connecting = false
  492. self.UpdateListActive()
  493. }
  494. func (self *WifiList) GetWirelessIP() string {
  495. cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
  496. out := UI.SystemTrim(cli)
  497. return out
  498. }
  499. func (self *WifiList) ScrollUp() {
  500. if len(self.MyList) == 0 {
  501. return
  502. }
  503. self.PsIndex -= 1
  504. if self.PsIndex < 0 {
  505. self.PsIndex = 0
  506. }
  507. cur_ni := self.MyList[self.PsIndex] //*NetItem
  508. if cur_ni.PosY < 0 {
  509. for i := 0; i < len(self.MyList); i++ {
  510. self.MyList[i].PosY += self.MyList[i].Height
  511. }
  512. }
  513. }
  514. func (self *WifiList) ScrollDown() {
  515. if len(self.MyList) == 0 {
  516. return
  517. }
  518. self.PsIndex += 1
  519. if self.PsIndex >= len(self.MyList) {
  520. self.PsIndex = len(self.MyList) - 1
  521. }
  522. cur_ni := self.MyList[self.PsIndex]
  523. if cur_ni.PosY+cur_ni.Height > self.Height {
  524. for i := 0; i < len(self.MyList); i++ {
  525. self.MyList[i].PosY -= self.MyList[i].Height
  526. }
  527. }
  528. }
  529. func (self *WifiList) AbortedAndReturnToUpLevel() {
  530. self.HideBox()
  531. self.Screen.FootBar.ResetNavText()
  532. self.ReturnToUpLevelPage()
  533. self.Screen.Draw()
  534. self.Screen.SwapAndShow()
  535. }
  536. func (self *WifiList) OnKbdReturnBackCb() {
  537. password_inputed := strings.Join(APIOBJ.PasswordPage.Textarea.MyWords, "")
  538. fmt.Println("Password inputed: ", password_inputed)
  539. ip := self.GetWirelessIP()
  540. if len(ip) < 6 {
  541. self.ConfigWireless(password_inputed)
  542. }
  543. }
  544. func (self *WifiList) OnReturnBackCb() {
  545. //fmt.Println("return back")
  546. }
  547. func (self *WifiList) KeyDown(ev *event.Event) {
  548. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  549. //self.ShutDownConnecting()
  550. //self.ShowBox("ShutDownConnecting...")
  551. self.AbortedAndReturnToUpLevel()
  552. }
  553. if ev.Data["Key"] == UI.CurKeys["Up"] {
  554. self.ScrollUp()
  555. self.Screen.Draw()
  556. self.Screen.SwapAndShow()
  557. }
  558. if ev.Data["Key"] == UI.CurKeys["Down"] {
  559. self.ScrollDown()
  560. self.Screen.Draw()
  561. self.Screen.SwapAndShow()
  562. }
  563. if ev.Data["Key"] == UI.CurKeys["Enter"] { // enter to set password,enter is B on GM
  564. if len(self.MyList) == 0 {
  565. return
  566. }
  567. if self.MyList[self.PsIndex].IsActive == true {
  568. var ip string
  569. ip = self.GetWirelessIP()
  570. self.ShowBox(ip)
  571. } else {
  572. self.Screen.PushCurPage()
  573. self.Screen.SetCurPage(APIOBJ.PasswordPage)
  574. thepass := self.LoadWifiPassword(self.MyList[self.PsIndex].Essid)
  575. fmt.Println("APIOBJ.PasswordPage.SetPassword ", thepass, len(thepass))
  576. APIOBJ.PasswordPage.SetPassword(thepass)
  577. self.Screen.Draw()
  578. self.Screen.SwapAndShow()
  579. }
  580. }
  581. if ev.Data["Key"] == UI.CurKeys["X"] {
  582. self.Rescan(false)
  583. }
  584. if ev.Data["Key"] == UI.CurKeys["Y"] {
  585. if len(self.MyList) == 0 {
  586. return
  587. }
  588. self.InfoPage.BSSID = self.MyList[self.PsIndex].Bssid
  589. self.InfoPage.ESSID = self.MyList[self.PsIndex].Essid
  590. self.Screen.PushPage(self.InfoPage)
  591. self.Screen.Draw()
  592. self.Screen.SwapAndShow()
  593. }
  594. }
  595. func (self *WifiList) OnLoadCb() {
  596. ip := self.GetWirelessIP()
  597. if len(ip) < 6 {
  598. self.CurEssid = ""
  599. self.CurBssid = ""
  600. self.CurIP = ip
  601. }
  602. self.Rescan(false)
  603. }
  604. func (self *WifiList) Init() {
  605. self.PosX = self.Index * self.Screen.Width
  606. self.Width = self.Screen.Width
  607. self.Height = self.Screen.Height
  608. self.CanvasHWND = self.Screen.CanvasHWND
  609. ps := NewWifiListSelector()
  610. ps.Parent = self
  611. ps.Width = UI.Width - 12
  612. self.Ps = ps
  613. self.PsIndex = 0
  614. msgbox := NewWifiListMessageBox()
  615. msgbox.CanvasHWND = self.CanvasHWND
  616. msgbox.Init(" ", UI.Fonts["veramono12"], nil)
  617. msgbox.Parent = self
  618. self.MsgBox = msgbox
  619. /*
  620. {
  621. 'fields': [],
  622. 'name': 'WPA 1/2 (Passphrase)',
  623. 'optional': [],
  624. 'protected': [
  625. ['apsk', 'Preshared_Key'],
  626. ],
  627. 'required': [
  628. ['apsk', 'Preshared_Key'],
  629. ],
  630. 'type': 'wpa-psk',
  631. },
  632. */
  633. self.Scroller = UI.NewListScroller()
  634. self.Scroller.Parent = self
  635. self.Scroller.PosX = 2
  636. self.Scroller.PosY = 2
  637. self.Scroller.Init()
  638. self.InfoPage = NewWifiInfoPage()
  639. self.InfoPage.Screen = self.Screen
  640. self.InfoPage.Name = "Wifi info"
  641. self.InfoPage.Parent = self
  642. self.InfoPage.Init()
  643. }
  644. func (self *WifiList) Draw() {
  645. self.ClearCanvas()
  646. if len(self.MyList) == 0 {
  647. return
  648. }
  649. self.Ps.Draw()
  650. for _, v := range self.MyList {
  651. v.Draw()
  652. }
  653. self.Scroller.UpdateSize(len(self.MyList)*NetItemDefaultHeight, self.PsIndex*NetItemDefaultHeight)
  654. self.Scroller.Draw()
  655. }