wifi.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. MsgBox *WifiListMessageBox
  290. ConnectTry int
  291. BlockingUI bool
  292. BlockCb BlockCbFunc
  293. LastStatusMsg string
  294. Scroller *UI.ListScroller
  295. ListFontObj *ttf.Font
  296. InfoPage *WifiInfoPage
  297. MyList []*NetItem
  298. CurEssid string ///SomeWifi
  299. CurBssid string //00:00:00:00:00:00
  300. CurIP string
  301. CurSig string
  302. }
  303. func NewWifiList() *WifiList {
  304. p := &WifiList{}
  305. p.ListFontObj = UI.Fonts["notosanscjk15"]
  306. p.FootMsg = [5]string{"Nav.", "Scan", "Info", "Back", "Enter"}
  307. return p
  308. }
  309. func (self *WifiList) ShowBox(msg string) {
  310. self.MsgBox.Text = msg
  311. self.Screen.ShowMsg(msg,1)
  312. }
  313. func (self *WifiList) GenNetworkList() {
  314. self.MyList = self.MyList[:0]
  315. start_x := 0
  316. start_y := 0
  317. var is_active bool
  318. var li_idx int
  319. li_idx = 0
  320. self.WifiScanStarted()
  321. if bssList, err := GsScanManager.Scan(); err == nil {
  322. self.CurEssid = GsScanManager.GetCurrentSSID()
  323. self.CurBssid = GsScanManager.GetCurrentBSSID()
  324. for _, bss := range bssList {
  325. is_active = false
  326. fmt.Println(bss.SSID, " ", bss.BSSID, " ", bss.Signal, bss.KeyMgmt)
  327. ni := NewNetItem()
  328. ni.Parent = self
  329. ni.PosX = start_x
  330. ni.PosY = start_y + li_idx*NetItemDefaultHeight
  331. ni.Width = UI.Width
  332. ni.FontObj = self.ListFontObj
  333. ni.Essid = bss.SSID
  334. ni.Bssid = bss.BSSID
  335. ni.Signal = bss.Signal
  336. if self.CurBssid == ni.Bssid {
  337. is_active = true
  338. }
  339. ni.Init(is_active)
  340. self.MyList = append(self.MyList, ni)
  341. li_idx++
  342. }
  343. }
  344. self.WifiScanFinished()
  345. self.PsIndex = 0
  346. }
  347. func (self *WifiList) Disconnect() {
  348. self.Connecting = false
  349. //nmcli -t -f NAME c show --active
  350. //nmcli con down
  351. cli := "nmcli -t -f NAME c show --active"
  352. out := UI.SystemTrim(cli)
  353. cli = fmt.Sprintf("sudo nmcli con down \"%s\"",out)
  354. out = UI.System(cli)
  355. log.Println(out)
  356. self.CurEssid = ""
  357. self.CurBssid = ""
  358. }
  359. func (self *WifiList) ShutDownConnecting() {
  360. self.Connecting = false
  361. self.Disconnect()
  362. }
  363. func (self *WifiList) Rescan(sync bool) { // sync default should be false
  364. fmt.Println("start Rescan")
  365. self.GenNetworkList()
  366. }
  367. // dbus signal functions
  368. func (self *WifiList) WifiScanFinished() {
  369. if self.Screen.CurrentPage != self {
  370. return
  371. }
  372. self.ResetPageSelector()
  373. self.Scanning = false
  374. fmt.Println("dbus says scan finished")
  375. }
  376. func (self *WifiList) WifiScanStarted() {
  377. if self.Screen.CurrentPage != self {
  378. return
  379. }
  380. self.Scanning = true
  381. self.ShowBox("Wifi scanning")
  382. fmt.Println("dbus says start scan")
  383. }
  384. func (self *WifiList) SaveNetworkList() {
  385. }
  386. func (self *WifiList) SaveWifiPassword(essid,password string) {
  387. db, err := sql.Open("sqlite3", sysgo.SQLDB)
  388. if err != nil {
  389. log.Fatal(err)
  390. return
  391. }
  392. defer db.Close()
  393. stmt, err := db.Prepare("select count(*) from wifi where essid = ?")
  394. if err != nil {
  395. log.Println(err)
  396. return
  397. }
  398. defer stmt.Close()
  399. var count string
  400. err = stmt.QueryRow(essid).Scan(&count)
  401. if err != nil {
  402. log.Println(err)
  403. count = "0"
  404. }
  405. cnt,_ := strconv.Atoi(count)
  406. if cnt > 0 {
  407. _,err = db.Exec("update wifi set pass= :pass where essid = :essid",sql.Named("pass",password),sql.Named("essid",essid))
  408. if err != nil {
  409. log.Println(err)
  410. }
  411. }else {
  412. _,err = db.Exec("insert into wifi(essid,pass) values(:essid,:pass)",sql.Named("essid",essid),sql.Named("pass",password))
  413. if err != nil {
  414. log.Println(err)
  415. }
  416. }
  417. }
  418. func (self *WifiList) LoadWifiPassword(essid string) string {
  419. db, err := sql.Open("sqlite3", sysgo.SQLDB)
  420. if err != nil {
  421. log.Fatal(err)
  422. return ""
  423. }
  424. defer db.Close()
  425. password := ""
  426. stmt, err := db.Prepare("select pass from wifi where essid = ?")
  427. defer stmt.Close()
  428. if err != nil {
  429. log.Println(err)
  430. }else {
  431. err = stmt.QueryRow(essid).Scan(&password)
  432. if err != nil {
  433. log.Println(err)
  434. }
  435. }
  436. return password
  437. }
  438. //----------------------------------------------------------------------------------
  439. func (self *WifiList) UpdateNetList(state int, info []string, force_check bool, firstrun bool) { //force_check default ==false, firstrun default == false
  440. if force_check == true {
  441. self.GenNetworkList()
  442. self.SaveNetworkList()
  443. }
  444. }
  445. func (self *WifiList) UpdateListActive() {
  446. for i := 0; i < len(self.MyList); i++ {
  447. if self.MyList[i].Bssid == self.CurBssid {
  448. self.MyList[i].IsActive = true
  449. } else {
  450. self.MyList[i].IsActive = false
  451. }
  452. }
  453. }
  454. func (self *WifiList) ConfigWireless(password string) {
  455. ssid := self.MyList[self.PsIndex].Essid
  456. fmt.Println(ssid)
  457. fmt.Println(password)
  458. self.ShowBox("Connecting")
  459. self.Connecting = true
  460. cli := fmt.Sprintf("sudo nmcli dev wifi connect %s password \"%s\"", ssid, password)
  461. log.Println(cli)
  462. out := UI.System(cli)
  463. log.Println(out)
  464. if strings.Contains(out, "successfully") {
  465. self.CurEssid = self.MyList[self.PsIndex].Essid
  466. self.CurBssid = self.MyList[self.PsIndex].Bssid
  467. self.MyList[self.PsIndex].Password = password
  468. self.SaveWifiPassword(ssid,password)
  469. self.ShowBox("Connected")
  470. } else {
  471. self.ShowBox("Wifi connect error")
  472. self.CurEssid = ""
  473. self.CurBssid = ""
  474. }
  475. self.Connecting = false
  476. self.UpdateListActive()
  477. }
  478. func (self *WifiList) GetWirelessIP() string {
  479. cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
  480. out := UI.SystemTrim(cli)
  481. return out
  482. }
  483. func (self *WifiList) ScrollUp() {
  484. if len(self.MyList) == 0 {
  485. return
  486. }
  487. self.PsIndex -= 1
  488. if self.PsIndex < 0 {
  489. self.PsIndex = 0
  490. }
  491. cur_ni := self.MyList[self.PsIndex] //*NetItem
  492. if cur_ni.PosY < 0 {
  493. for i := 0; i < len(self.MyList); i++ {
  494. self.MyList[i].PosY += self.MyList[i].Height
  495. }
  496. }
  497. }
  498. func (self *WifiList) ScrollDown() {
  499. if len(self.MyList) == 0 {
  500. return
  501. }
  502. self.PsIndex += 1
  503. if self.PsIndex >= len(self.MyList) {
  504. self.PsIndex = len(self.MyList) - 1
  505. }
  506. cur_ni := self.MyList[self.PsIndex]
  507. if cur_ni.PosY+cur_ni.Height > self.Height {
  508. for i := 0; i < len(self.MyList); i++ {
  509. self.MyList[i].PosY -= self.MyList[i].Height
  510. }
  511. }
  512. }
  513. func (self *WifiList) AbortedAndReturnToUpLevel() {
  514. self.Screen.FootBar.ResetNavText()
  515. self.ReturnToUpLevelPage()
  516. self.Screen.Refresh()
  517. }
  518. func (self *WifiList) OnKbdReturnBackCb() {
  519. password_inputed := strings.Join(APIOBJ.PasswordPage.Textarea.MyWords, "")
  520. fmt.Println("Password inputed: ", password_inputed)
  521. if len(password_inputed) > 4 {
  522. self.ConfigWireless(password_inputed)
  523. }else {
  524. log.Println("wifi password length too short ",len(password_inputed))
  525. }
  526. }
  527. func (self *WifiList) OnReturnBackCb() {
  528. //fmt.Println("return back")
  529. }
  530. func (self *WifiList) KeyDown(ev *event.Event) {
  531. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  532. //self.ShutDownConnecting()
  533. //self.ShowBox("ShutDownConnecting...")
  534. self.AbortedAndReturnToUpLevel()
  535. }
  536. if ev.Data["Key"] == UI.CurKeys["Up"] {
  537. self.ScrollUp()
  538. self.Screen.Refresh()
  539. }
  540. if ev.Data["Key"] == UI.CurKeys["Down"] {
  541. self.ScrollDown()
  542. self.Screen.Refresh()
  543. }
  544. if ev.Data["Key"] == UI.CurKeys["Enter"] { // enter to set password,enter is B on GM
  545. if len(self.MyList) == 0 {
  546. return
  547. }
  548. if self.MyList[self.PsIndex].IsActive == true {
  549. var ip string
  550. ip = self.GetWirelessIP()
  551. self.ShowBox(ip)
  552. } else {
  553. self.Screen.PushCurPage()
  554. self.Screen.SetCurPage(APIOBJ.PasswordPage)
  555. thepass := self.LoadWifiPassword(self.MyList[self.PsIndex].Essid)
  556. fmt.Println("APIOBJ.PasswordPage.SetPassword ", thepass, len(thepass))
  557. APIOBJ.PasswordPage.SetPassword(thepass)
  558. self.Screen.Refresh()
  559. }
  560. }
  561. if ev.Data["Key"] == UI.CurKeys["X"] {
  562. self.Rescan(false)
  563. self.Screen.Refresh()
  564. }
  565. if ev.Data["Key"] == UI.CurKeys["Y"] {
  566. if len(self.MyList) == 0 {
  567. return
  568. }
  569. self.InfoPage.BSSID = self.MyList[self.PsIndex].Bssid
  570. self.InfoPage.ESSID = self.MyList[self.PsIndex].Essid
  571. self.Screen.PushPage(self.InfoPage)
  572. self.Screen.Refresh()
  573. }
  574. }
  575. func (self *WifiList) OnLoadCb() {
  576. ip := self.GetWirelessIP()
  577. if len(ip) < 6 {
  578. self.CurEssid = ""
  579. self.CurBssid = ""
  580. self.CurIP = ip
  581. }
  582. self.Rescan(false)
  583. }
  584. func (self *WifiList) Init() {
  585. self.PosX = self.Index * self.Screen.Width
  586. self.Width = self.Screen.Width
  587. self.Height = self.Screen.Height
  588. self.CanvasHWND = self.Screen.CanvasHWND
  589. ps := NewWifiListSelector()
  590. ps.Parent = self
  591. ps.Width = UI.Width - 12
  592. self.Ps = ps
  593. self.PsIndex = 0
  594. msgbox := NewWifiListMessageBox()
  595. msgbox.CanvasHWND = self.CanvasHWND
  596. msgbox.Init(" ", UI.Fonts["veramono12"], nil)
  597. msgbox.Parent = self
  598. self.MsgBox = msgbox
  599. /*
  600. {
  601. 'fields': [],
  602. 'name': 'WPA 1/2 (Passphrase)',
  603. 'optional': [],
  604. 'protected': [
  605. ['apsk', 'Preshared_Key'],
  606. ],
  607. 'required': [
  608. ['apsk', 'Preshared_Key'],
  609. ],
  610. 'type': 'wpa-psk',
  611. },
  612. */
  613. self.Scroller = UI.NewListScroller()
  614. self.Scroller.Parent = self
  615. self.Scroller.PosX = 2
  616. self.Scroller.PosY = 2
  617. self.Scroller.Init()
  618. self.InfoPage = NewWifiInfoPage()
  619. self.InfoPage.Screen = self.Screen
  620. self.InfoPage.Name = "Wifi info"
  621. self.InfoPage.Parent = self
  622. self.InfoPage.Init()
  623. }
  624. func (self *WifiList) Draw() {
  625. self.ClearCanvas()
  626. if len(self.MyList) == 0 {
  627. return
  628. }
  629. self.Ps.Draw()
  630. for _, v := range self.MyList {
  631. v.Draw()
  632. }
  633. self.Scroller.UpdateSize(len(self.MyList)*NetItemDefaultHeight, self.PsIndex*NetItemDefaultHeight)
  634. self.Scroller.Draw()
  635. }