wifi.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. package Wifi
  2. //wifi_list.py
  3. import (
  4. "fmt"
  5. //"strconv"
  6. "strings"
  7. //"os"
  8. // "os/exec"
  9. gotime "time"
  10. //"github.com/godbus/dbus"
  11. "github.com/veandco/go-sdl2/ttf"
  12. "github.com/cuu/gogame/surface"
  13. "github.com/cuu/gogame/font"
  14. "github.com/cuu/gogame/color"
  15. "github.com/cuu/gogame/event"
  16. "github.com/cuu/gogame/time"
  17. "github.com/cuu/gogame/rect"
  18. "github.com/cuu/gogame/draw"
  19. "github.com/clockworkpi/LauncherGoDev/sysgo"
  20. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  21. wifi "github.com/cuu/wpa-connect"
  22. )
  23. const EMPTY_NETWORK = "00:00:00:00:00:00"
  24. type WifiDisconnectConfirmPage struct {
  25. UI.ConfirmPage
  26. Parent *WifiInfoPage
  27. }
  28. func NewWifiDisconnectConfirmPage() *WifiDisconnectConfirmPage {
  29. p := &WifiDisconnectConfirmPage{}
  30. p.ListFont = UI.Fonts["veramono20"]
  31. p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
  32. p.ConfirmText ="Confirm Disconnect?"
  33. return p
  34. }
  35. func (self *WifiDisconnectConfirmPage) KeyDown(ev *event.Event ) {
  36. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  37. self.ReturnToUpLevelPage()
  38. self.Screen.Draw()
  39. self.Screen.SwapAndShow()
  40. }
  41. if ev.Data["Key"] == UI.CurKeys["B"] {
  42. fmt.Println("Disconnecting..")
  43. self.SnapMsg("Disconnecting...")
  44. self.Screen.Draw()
  45. self.Screen.SwapAndShow()
  46. self.Parent.Parent.Disconnect()
  47. time.BlockDelay(400)
  48. self.ReturnToUpLevelPage()
  49. self.Screen.Draw()
  50. self.Screen.SwapAndShow()
  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.Draw()
  191. self.Screen.SwapAndShow()
  192. }else {
  193. fmt.Println("WifiInfoPage TryDisconnect can not get IP,maybe you are offline")
  194. return
  195. }
  196. }
  197. func (self *WifiInfoPage) OnLoadCb() {
  198. /*
  199. self.FootMsg[1]="Disconnect"
  200. self.FootMsg[1] = ""
  201. */
  202. self.GenList()
  203. }
  204. func (self *WifiInfoPage) OnReturnBackCb() {
  205. self.ReturnToUpLevelPage()
  206. self.Screen.Draw()
  207. self.Screen.SwapAndShow()
  208. }
  209. func (self *WifiInfoPage) KeyDown(ev *event.Event ) {
  210. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  211. self.ReturnToUpLevelPage()
  212. self.Screen.Draw()
  213. self.Screen.SwapAndShow()
  214. }
  215. if ev.Data["Key"] == UI.CurKeys["Up"] {
  216. self.ScrollUp()
  217. self.Screen.Draw()
  218. self.Screen.SwapAndShow()
  219. }
  220. if ev.Data["Key"] == UI.CurKeys["Down"] {
  221. self.ScrollDown()
  222. self.Screen.Draw()
  223. self.Screen.SwapAndShow()
  224. }
  225. if ev.Data["Key"] == UI.CurKeys["Enter"] {
  226. self.Click()
  227. }
  228. if ev.Data["Key"] == UI.CurKeys["X"] {
  229. self.TryDisconnect()
  230. }
  231. }
  232. func (self *WifiInfoPage) Draw() {
  233. self.ClearCanvas()
  234. self.Ps.Draw()
  235. for i:=0;i<len(self.MyList);i++ {
  236. self.MyList[i].Draw()
  237. }
  238. }
  239. type WifiListSelector struct{
  240. UI.PageSelector
  241. BackgroundColor *color.Color
  242. Parent *WifiList
  243. }
  244. func NewWifiListSelector() *WifiListSelector {
  245. p := &WifiListSelector{}
  246. p.BackgroundColor = &color.Color{131,199,219,255} //SkinManager().GiveColor('Front')
  247. return p
  248. }
  249. func (self *WifiListSelector) Draw() {
  250. idx := self.Parent.PsIndex
  251. if idx < len(self.Parent.MyList) {
  252. x := self.Parent.MyList[idx].PosX + 11
  253. y := self.Parent.MyList[idx].PosY + 1
  254. h := self.Parent.MyList[idx].Height - 3
  255. self.PosX = x
  256. self.PosY = y
  257. self.Height = h
  258. rect_ := rect.Rect(x,y,self.Width,h)
  259. draw.AARoundRect(self.Parent.CanvasHWND,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
  260. }
  261. }
  262. type WifiListMessageBox struct{
  263. UI.Label
  264. Parent *WifiList
  265. }
  266. func NewWifiListMessageBox() *WifiListMessageBox{
  267. p := &WifiListMessageBox{}
  268. p.Color = &color.Color{83,83,83,255}
  269. return p
  270. }
  271. func (self *WifiListMessageBox) Draw() {
  272. my_text := font.Render(self.FontObj,self.Text,true,self.Color,nil)
  273. w := surface.GetWidth(my_text)
  274. h := surface.GetHeight(my_text)
  275. x := (self.Parent.Width - w )/2
  276. y := (self.Parent.Height - h)/2
  277. padding := 10
  278. white := &color.Color{255,255,255,255}
  279. black := &color.Color{0, 0, 0, 255}
  280. rect_ := rect.Rect(x-padding,y-padding,w+padding*2,h+padding*2)
  281. draw.Rect(self.CanvasHWND,white,&rect_,0)
  282. draw.Rect(self.CanvasHWND,black,&rect_,1)
  283. rect_2 := rect.Rect(x,y,w,h)
  284. surface.Blit(self.CanvasHWND,my_text,&rect_2,nil)
  285. my_text.Free()
  286. }
  287. //---------WifiList---------------------------------
  288. type BlockCbFunc func()
  289. type WifiList struct{
  290. UI.Page
  291. WifiPassword string
  292. Connecting bool
  293. Scanning bool
  294. ShowingMessageBox bool
  295. MsgBox *WifiListMessageBox
  296. ConnectTry int
  297. BlockingUI bool
  298. BlockCb BlockCbFunc
  299. LastStatusMsg string
  300. Scroller *UI.ListScroller
  301. ListFontObj *ttf.Font
  302. InfoPage *WifiInfoPage
  303. MyList []*NetItem
  304. CurEssid string ///SomeWifi
  305. CurBssid string //00:00:00:00:00:00
  306. CurIP string
  307. CurSig string
  308. }
  309. func NewWifiList() *WifiList {
  310. p:= &WifiList{}
  311. p.ListFontObj = UI.Fonts["notosanscjk15"]
  312. p.FootMsg = [5]string{"Nav.","Scan","Info","Back","Enter"}
  313. return p
  314. }
  315. func (self *WifiList) ShowBox(msg string ) {
  316. self.MsgBox.Text = msg
  317. self.ShowingMessageBox = true
  318. self.Screen.Draw()
  319. self.MsgBox.Draw()
  320. self.Screen.SwapAndShow()
  321. }
  322. func (self *WifiList) HideBox() {
  323. self.Draw()
  324. self.ShowingMessageBox = false
  325. self.Screen.SwapAndShow()
  326. }
  327. func (self *WifiList) GenNetworkList() {
  328. self.MyList = self.MyList[:0]
  329. start_x := 0
  330. start_y := 0
  331. var is_active bool
  332. var li_idx int
  333. li_idx = 0
  334. self.WifiScanStarted()
  335. if bssList, err := GsScanManager.Scan(); err == nil {
  336. self.CurEssid = GsScanManager.GetCurrentSSID()
  337. self.CurBssid = GsScanManager.GetCurrentBSSID()
  338. for _, bss := range bssList {
  339. is_active = false
  340. fmt.Println(bss.SSID, " ", bss.BSSID," ",bss.Signal, bss.KeyMgmt)
  341. ni := NewNetItem()
  342. ni.Parent = self
  343. ni.PosX = start_x
  344. ni.PosY = start_y + li_idx* NetItemDefaultHeight
  345. ni.Width = UI.Width
  346. ni.FontObj = self.ListFontObj
  347. ni.Essid = bss.SSID
  348. ni.Bssid = bss.BSSID
  349. ni.Signal = bss.Signal
  350. if self.CurBssid == ni.Bssid {
  351. is_active = true
  352. }
  353. ni.Init(is_active)
  354. self.MyList = append(self.MyList,ni)
  355. li_idx++
  356. }
  357. }
  358. self.WifiScanFinished()
  359. self.PsIndex = 0
  360. }
  361. func (self *WifiList) Disconnect() {
  362. self.Connecting = false
  363. wpa_cli_disconnect := []string{"wpa_cli","disconnect",self.CurEssid,"-i",sysgo.WifiDev}
  364. UI.ExecCmd( wpa_cli_disconnect )
  365. fmt.Println(wpa_cli_disconnect)
  366. dhcp_release := []string{"dhclient","-r",sysgo.WifiDev}
  367. UI.ExecCmd(dhcp_release)
  368. self.CurEssid = ""
  369. self.CurBssid = ""
  370. }
  371. func (self *WifiList) ShutDownConnecting() {
  372. self.Connecting= false
  373. self.Disconnect()
  374. }
  375. func (self *WifiList) Rescan(sync bool) { // sync default should be false
  376. fmt.Println("start Rescan")
  377. self.GenNetworkList()
  378. }
  379. // dbus signal functions
  380. func (self *WifiList) WifiScanFinished() {
  381. if self.Screen.CurrentPage != self {
  382. return
  383. }
  384. self.ResetPageSelector()
  385. self.Scanning= false
  386. self.HideBox()
  387. self.BlockingUI = false
  388. fmt.Println("dbus says scan finished")
  389. }
  390. func (self *WifiList) WifiScanStarted( ) {
  391. if self.Screen.CurrentPage != self {
  392. return
  393. }
  394. self.Scanning = true
  395. self.ShowBox("Wifi scanning...")
  396. self.BlockingUI = true
  397. fmt.Println("dbus says start scan")
  398. }
  399. func (self *WifiList) SaveNetworkList() {
  400. }
  401. //----------------------------------------------------------------------------------
  402. func (self *WifiList) UpdateNetList(state int,info []string ,force_check bool,firstrun bool) { //force_check default ==false, firstrun default == false
  403. if force_check == true {
  404. self.GenNetworkList()
  405. self.SaveNetworkList()
  406. }
  407. }
  408. func (self *WifiList) UpdateListActive() {
  409. for i:=0;i<len(self.MyList);i++ {
  410. if self.MyList[i].Bssid == self.CurBssid {
  411. self.MyList[i].IsActive = true
  412. }else {
  413. self.MyList[i].IsActive = false
  414. }
  415. }
  416. }
  417. func (self *WifiList) ConfigWireless(password string) {
  418. ssid := self.MyList[self.PsIndex].Essid
  419. fmt.Println(ssid)
  420. fmt.Println(password)
  421. self.ShowBox("Connecting...")
  422. self.Connecting = true
  423. if conn, err := GsConnectManager.Connect(ssid, password, gotime.Second * 20); err == nil {
  424. fmt.Println("Connected!", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String())
  425. self.CurEssid = self.MyList[self.PsIndex].Essid
  426. self.CurBssid = self.MyList[self.PsIndex].Bssid
  427. self.MyList[self.PsIndex].Password = password
  428. dhcp := []string{"dhclient" ,sysgo.WifiDev}
  429. UI.ExecCmd(dhcp)
  430. GsConnectManager.ReadNetAddress(gotime.Second*3)
  431. self.CurIP = GsConnectManager.IPv4().String()
  432. self.ShowBox("Connected")
  433. } else {
  434. err_str := err.Error()
  435. s := strings.Split(err_str,":")
  436. if len(s)> 1 && s[1] == "15" {
  437. self.ShowBox("Wifi auth error")
  438. }else {
  439. self.ShowBox(err_str)
  440. }
  441. self.CurEssid = ""
  442. self.CurBssid = ""
  443. }
  444. self.Connecting = false
  445. self.UpdateListActive()
  446. }
  447. func (self *WifiList) GetWirelessIP() string {
  448. cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
  449. out := UI.SystemTrim(cli)
  450. return out
  451. }
  452. func (self *WifiList) ScrollUp() {
  453. if len(self.MyList) == 0 {
  454. return
  455. }
  456. self.PsIndex -= 1
  457. if self.PsIndex < 0 {
  458. self.PsIndex=0
  459. }
  460. cur_ni := self.MyList[self.PsIndex]//*NetItem
  461. if cur_ni.PosY < 0 {
  462. for i:=0;i<len(self.MyList);i++ {
  463. self.MyList[i].PosY += self.MyList[i].Height
  464. }
  465. }
  466. }
  467. func (self *WifiList) ScrollDown() {
  468. if len(self.MyList) == 0 {
  469. return
  470. }
  471. self.PsIndex += 1
  472. if self.PsIndex >= len(self.MyList) {
  473. self.PsIndex = len(self.MyList) - 1
  474. }
  475. cur_ni := self.MyList[self.PsIndex]
  476. if cur_ni.PosY + cur_ni.Height > self.Height {
  477. for i:=0;i<len(self.MyList);i++ {
  478. self.MyList[i].PosY -= self.MyList[i].Height
  479. }
  480. }
  481. }
  482. func (self *WifiList) AbortedAndReturnToUpLevel() {
  483. self.HideBox()
  484. self.Screen.FootBar.ResetNavText()
  485. self.ReturnToUpLevelPage()
  486. self.Screen.Draw()
  487. self.Screen.SwapAndShow()
  488. }
  489. func (self *WifiList) OnKbdReturnBackCb() {
  490. password_inputed := strings.Join(APIOBJ.PasswordPage.Textarea.MyWords,"")
  491. fmt.Println("Password inputed: ",password_inputed)
  492. ip := self.GetWirelessIP()
  493. if len(ip) < 6 {
  494. self.ConfigWireless(password_inputed)
  495. }
  496. }
  497. func (self *WifiList) OnReturnBackCb() {
  498. //fmt.Println("return back")
  499. }
  500. func (self *WifiList) KeyDown( ev *event.Event ) {
  501. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  502. //self.ShutDownConnecting()
  503. //self.ShowBox("ShutDownConnecting...")
  504. self.AbortedAndReturnToUpLevel()
  505. }
  506. if ev.Data["Key"] == UI.CurKeys["Up"] {
  507. self.ScrollUp()
  508. self.Screen.Draw()
  509. self.Screen.SwapAndShow()
  510. }
  511. if ev.Data["Key"] == UI.CurKeys["Down"] {
  512. self.ScrollDown()
  513. self.Screen.Draw()
  514. self.Screen.SwapAndShow()
  515. }
  516. if ev.Data["Key"] == UI.CurKeys["Enter"] { // enter to set password,enter is B on GM
  517. if len(self.MyList) == 0 {
  518. return
  519. }
  520. if self.MyList[self.PsIndex].IsActive == true {
  521. var ip string
  522. ip = self.GetWirelessIP()
  523. self.ShowBox(ip)
  524. }else {
  525. self.Screen.PushCurPage()
  526. self.Screen.SetCurPage(APIOBJ.PasswordPage)
  527. thepass := self.MyList[self.PsIndex].Password
  528. fmt.Println("APIOBJ.PasswordPage.SetPassword ", thepass,len(thepass))
  529. APIOBJ.PasswordPage.SetPassword(thepass)
  530. self.Screen.Draw()
  531. self.Screen.SwapAndShow()
  532. }
  533. }
  534. if ev.Data["Key"] == UI.CurKeys["X"] {
  535. self.Rescan(false)
  536. }
  537. if ev.Data["Key"] == UI.CurKeys["Y"] {
  538. if len(self.MyList) == 0 {
  539. return
  540. }
  541. self.InfoPage.BSSID = self.MyList[self.PsIndex].Bssid
  542. self.InfoPage.ESSID = self.MyList[self.PsIndex].Essid
  543. self.Screen.PushPage(self.InfoPage)
  544. self.Screen.Draw()
  545. self.Screen.SwapAndShow()
  546. }
  547. }
  548. func (self *WifiList) OnLoadCb() {
  549. ip := self.GetWirelessIP()
  550. if len(ip) < 6 {
  551. self.CurEssid = ""
  552. self.CurBssid = ""
  553. self.CurIP = ip
  554. }
  555. self.Rescan(false)
  556. }
  557. func (self *WifiList) Init() {
  558. self.PosX = self.Index * self.Screen.Width
  559. self.Width = self.Screen.Width
  560. self.Height = self.Screen.Height
  561. self.CanvasHWND = self.Screen.CanvasHWND
  562. ps := NewWifiListSelector()
  563. ps.Parent = self
  564. ps.Width = UI.Width - 12
  565. self.Ps = ps
  566. self.PsIndex = 0
  567. msgbox := NewWifiListMessageBox()
  568. msgbox.CanvasHWND = self.CanvasHWND
  569. msgbox.Init(" ",UI.Fonts["veramono12"],nil)
  570. msgbox.Parent = self
  571. self.MsgBox = msgbox
  572. /*
  573. {
  574. 'fields': [],
  575. 'name': 'WPA 1/2 (Passphrase)',
  576. 'optional': [],
  577. 'protected': [
  578. ['apsk', 'Preshared_Key'],
  579. ],
  580. 'required': [
  581. ['apsk', 'Preshared_Key'],
  582. ],
  583. 'type': 'wpa-psk',
  584. },
  585. */
  586. self.Scroller = UI.NewListScroller()
  587. self.Scroller.Parent = self
  588. self.Scroller.PosX = 2
  589. self.Scroller.PosY = 2
  590. self.Scroller.Init()
  591. self.InfoPage = NewWifiInfoPage()
  592. self.InfoPage.Screen = self.Screen
  593. self.InfoPage.Name = "Wifi info"
  594. self.InfoPage.Parent = self
  595. self.InfoPage.Init()
  596. }
  597. func (self *WifiList) Draw() {
  598. self.ClearCanvas()
  599. if len(self.MyList) == 0 {
  600. return
  601. }
  602. self.Ps.Draw()
  603. for _,v := range self.MyList {
  604. v.Draw()
  605. }
  606. self.Scroller.UpdateSize( len(self.MyList)*NetItemDefaultHeight, self.PsIndex*NetItemDefaultHeight)
  607. self.Scroller.Draw()
  608. }