wifi.go 17 KB

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