From a439f966d66555251fedbae99fb51757778c7456 Mon Sep 17 00:00:00 2001 From: Milan Srdinko Date: Fri, 21 Apr 2017 13:17:49 +0200 Subject: WiFi: Fix WiFi UI not sync with network manager Fix error that state of WiFi ON/OFF button after widget start is not in sync with actual state of wireless adapter. Change-Id: I71ac07d11b2364d6dbb69b492774323c9c39fbd6 AGL-BUG: SPEC-531 Signed-off-by: Milan Srdinko --- app/Settings.qml | 2 + app/wifi/Wifi.qml | 117 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/app/Settings.qml b/app/Settings.qml index b3a622a..0d74c3b 100644 --- a/app/Settings.qml +++ b/app/Settings.qml @@ -49,6 +49,8 @@ ApplicationWindow { if (!app.isSetting) continue settingsModel.append({'icon': app.icon, 'title': app.title, 'checkable': app.checkable, 'app': app}) app.visible = false + + if (app.isWifi) app.activateWifi() } } diff --git a/app/wifi/Wifi.qml b/app/wifi/Wifi.qml index b4e3357..20d12c0 100644 --- a/app/wifi/Wifi.qml +++ b/app/wifi/Wifi.qml @@ -27,6 +27,8 @@ SettingPage { icon: '/wifi/images/HMI_Settings_WifiIcon.svg' title: 'Wifi' checkable: true + readonly property bool isWifi: true + property bool isInitializing: true property string wifiAPIpath: bindingAddress + '/wifi-manager/' //http://localhost:12345/api @@ -48,6 +50,8 @@ SettingPage { property string request_str: "" property string status_str: "" + + WebSocket { id: websocket url: address_str @@ -122,6 +126,13 @@ SettingPage { } } + else if (verb_str == "status") { + + var status = "OFF" + status = (message_json[2].response).Power + + checked = (status === "ON") ? true : false + } } else console.log("Unhadled websocket message", message_json[0]) } @@ -136,7 +147,35 @@ SettingPage { } else if (websocket.status == WebSocket.Open) { status_str = "Socket opened; sending message..." + //first get the status + verb_str = "status" + parameterJson = 'None' + sendSocketMesage(verb_str, parameterJson) + + + + } else if (websocket.status == WebSocket.Closed) { + status_str = "Socket closed" + console.log("Socket closed, bye.") + + websocket.active = false + + } + + console.log(status_str) + } + active: false + } + + onCheckedChanged: { + console.log("Wifi set to", checked) + + if (websocket.active) { + + if (checked == true) { + //subscribe for events + var parameterJson //network list updated event verb_str = "eventadd" @@ -182,60 +221,52 @@ SettingPage { parameterJson = 'None' sendSocketMesage(verb_str, parameterJson) + } else { - } else if (websocket.status == WebSocket.Closed) { - status_str = "Socket closed" - console.log("Socket closed, bye.") - - } - - console.log(status_str) - } - active: false - } - - onCheckedChanged: { - console.log("Wifi set to", checked) + if (!isInitializing) { - if (checked == true) { - //activating is done when socket is opened - websocket.active = true + networkList.clear() - } else { - networkList.clear() + verb_str = "deactivate" + parameterJson = 'None' + sendSocketMesage(verb_str, parameterJson) - verb_str = "deactivate" - var parameterJson = 'None' - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventunsub" + parameterJson = { + tag: 'passkey' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventunsub" - parameterJson = { - tag: 'passkey' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventdel" + parameterJson = { + tag: 'passkey' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventdel" - parameterJson = { - tag: 'passkey' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventunsub" + parameterJson = { + tag: 'networkList' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventunsub" - parameterJson = { - tag: 'networkList' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventdel" + parameterJson = { + tag: 'networkList' + } - verb_str = "eventdel" - parameterJson = { - tag: 'networkList' - } + } + } + isInitializing = false + } - websocket.active = false + else { + console.log("Websocket not active.") + websocket.active = true } + } @@ -444,4 +475,8 @@ SettingPage { } } + function activateWifi(){ + websocket.active = true + } + } -- cgit 1.2.3-korg