diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc
index 753acd11..b4d7f4bb 100644
--- a/nymea-app/resources.qrc
+++ b/nymea-app/resources.qrc
@@ -13,7 +13,6 @@
ui/images/add.svg
ui/images/back.svg
ui/images/close.svg
- ui/MainPage.qml
ui/images/info.svg
ui/components/ColorPicker.qml
ui/customviews/CustomViewBase.qml
@@ -253,5 +252,7 @@
ui/devicelistpages/SensorsDeviceListPage.qml
ui/devicelistpages/WeatherDeviceListPage.qml
ui/devicelistpages/DeviceListPageBase.qml
+ ui/MainPage.qml
+ ui/RootItem.qml
diff --git a/nymea-app/ui/EditDevicesPage.qml b/nymea-app/ui/EditDevicesPage.qml
index db5b2f2f..248698aa 100644
--- a/nymea-app/ui/EditDevicesPage.qml
+++ b/nymea-app/ui/EditDevicesPage.qml
@@ -49,7 +49,7 @@ Page {
anchors.fill: parent
model: DevicesProxy {
id: deviceProxy
- engine: app.engine
+ engine: _engine
groupByInterface: true
}
section.property: "baseInterface"
diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml
index be8ce5a3..303dc93d 100644
--- a/nymea-app/ui/Nymea.qml
+++ b/nymea-app/ui/Nymea.qml
@@ -43,161 +43,13 @@ ApplicationWindow {
property int cloudEnvironment: 0
}
- property var engine: Engine {
-
- }
-
- Binding {
- target: engine.awsClient
- property: "config"
- value: settings.cloudEnvironment
- }
-
- Component.onCompleted: {
- pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
- setupPushNotifications();
- }
- Connections {
- target: PlatformHelper
- onHasPermissionsChanged: {
- setupPushNotifications(false)
- }
- }
- Connections {
- target: PushNotifications
- onTokenChanged: {
- setupPushNotifications();
- }
- }
-
- Connections {
- target: engine.awsClient
- onIsLoggedInChanged: {
- setupPushNotifications()
- }
- }
-
- Connections {
- target: engine.jsonRpcClient
- onConnectedChanged: {
- print("json client connected changed", engine.jsonRpcClient.connected)
- if (engine.jsonRpcClient.connected) {
- settings.lastConnectedHost = engine.connection.url
- }
- init();
- }
-
- onAuthenticationRequiredChanged: {
- print("auth required changed")
- init();
- }
- onInitialSetupRequiredChanged: {
- print("setup required changed")
- init();
- }
-
- onInvalidProtocolVersion: {
- var popup = invalidVersionComponent.createObject(app.contentItem);
- popup.actualVersion = actualVersion;
- popup.minimumVersion = minimumVersion
- popup.open()
- settings.lastConnectedHost = ""
- }
- }
-
- function init() {
- print("calling init. Auth required:", engine.jsonRpcClient.authenticationRequired, "initial setup required:", engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", engine.jsonRpcClient.connected)
- pageStack.clear()
- if (!engine.connection.connected) {
- pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
- return;
- }
-
- if (engine.jsonRpcClient.authenticationRequired || engine.jsonRpcClient.initialSetupRequired) {
- if (engine.jsonRpcClient.pushButtonAuthAvailable) {
- print("opening push button auth")
- var page = pageStack.push(Qt.resolvedUrl("PushButtonAuthPage.qml"))
- page.backPressed.connect(function() {
- settings.lastConnectedHost = "";
- engine.connection.disconnect();
- init();
- })
- } else {
- var page = pageStack.push(Qt.resolvedUrl("LoginPage.qml"));
- page.backPressed.connect(function() {
- settings.lastConnectedHost = "";
- engine.connection.disconnect()
- init();
- })
- }
- } else if (engine.jsonRpcClient.connected) {
- pageStack.push(Qt.resolvedUrl("MainPage.qml"))
- } else {
- pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
- }
- }
-
- function setupPushNotifications(askForPermissions) {
- if (askForPermissions === undefined) {
- askForPermissions = true;
- }
-
- if (!engine.awsClient.isLoggedIn) {
- print("AWS not logged in. Cannot register for push");
- return;
- }
-
- if (PushNotifications.token.length === 0) {
- print("Don't have a token yet. Cannot register for push");
- return;
- }
-
- if (!PlatformHelper.hasPermissions) {
- if (askForPermissions) {
- PlatformHelper.requestPermissions();
- }
- } else {
- engine.awsClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.deviceManufacturer + " " + PlatformHelper.deviceModel, PlatformHelper.deviceSerial + "+io.guh.nymeaapp");
- }
- }
-
- // Workaround flickering on pageStack animations when the white background shines through
- Rectangle {
+ RootItem {
+ id: rootItem
anchors.fill: parent
- color: Material.background
- }
-
- StackView {
- id: pageStack
- objectName: "pageStack"
- anchors.fill: parent
- initialItem: Page {}
-// onDepthChanged: {
-// print("stackview depth changed", pageStack.depth)
-// }
}
onClosing: {
- if (Qt.platform.os == "android") {
- // If we're connected, allow going back up to MainPage
- if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
- // if we're not connected, only allow using the back button in wizards
- || (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
- close.accepted = false;
- pageStack.pop();
- }
- }
- }
-
- Connections {
- target: Qt.application
- enabled: engine.jsonRpcClient.connected && settings.returnToHome
- onStateChanged: {
- print("App active state changed:", state)
- if (state !== Qt.ApplicationActive) {
- init();
- }
- }
+ rootItem.handleCloseEvent(close)
}
property var supportedInterfaces: ["light", "weather", "sensor", "media", "garagegate", "extendedawning", "extendedshutter", "extendedblind", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"]
@@ -392,44 +244,6 @@ ApplicationWindow {
return s.substr(s.length-size);
}
- Component {
- id: invalidVersionComponent
- Popup {
- id: popup
-
- property string actualVersion: "0.0"
- property string minimumVersion: "1.0"
-
- width: app.width * .8
- height: col.childrenRect.height + app.margins * 2
- x: (app.width - width) / 2
- y: (app.height - height) / 2
- visible: false
- ColumnLayout {
- id: col
- anchors { left: parent.left; right: parent.right }
- spacing: app.margins
- Label {
- text: qsTr("Connection error")
- Layout.fillWidth: true
- font.pixelSize: app.largeFont
- }
- Label {
- text: qsTr("Sorry, the version of the %1 box you are trying to connect to is too old. This app requires at least version %2 but the %1 box only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion)
- wrapMode: Text.WordWrap
- Layout.fillWidth: true
- }
- Button {
- Layout.fillWidth: true
- text: qsTr("OK")
- onClicked: {
- engine.connection.disconnect();
- popup.close()
- }
- }
- }
- }
- }
KeyboardLoader {
id: keyboardRect
diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml
new file mode 100644
index 00000000..bd66525b
--- /dev/null
+++ b/nymea-app/ui/RootItem.qml
@@ -0,0 +1,210 @@
+import QtQuick 2.9
+import QtQuick.Controls 2.2
+import QtQuick.Controls.Material 2.2
+import QtQuick.Layouts 1.3
+import Nymea 1.0
+
+Item {
+ id: root
+
+ Engine {
+ id: engine
+ }
+ // If you need to assign to a property "engine", `engine: engine` won't work, as a workaround, use `engine: _engine`
+ // TODO: Improve this situation
+ property alias _engine: engine
+
+ Binding {
+ target: engine.awsClient
+ property: "config"
+ value: settings.cloudEnvironment
+ }
+
+ // Workaround flickering on pageStack animations when the white background shines through
+ Rectangle {
+ anchors.fill: parent
+ color: Material.background
+ }
+
+ StackView {
+ id: pageStack
+ objectName: "pageStack"
+ anchors.fill: parent
+ initialItem: Page {}
+// onDepthChanged: {
+// print("stackview depth changed", pageStack.depth)
+// }
+ }
+
+ Component.onCompleted: {
+ pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
+ setupPushNotifications();
+ }
+
+ function init() {
+ print("calling init. Auth required:", engine.jsonRpcClient.authenticationRequired, "initial setup required:", engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", engine.jsonRpcClient.connected)
+ pageStack.clear()
+ if (!engine.connection.connected) {
+ pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
+ return;
+ }
+
+ if (engine.jsonRpcClient.authenticationRequired || engine.jsonRpcClient.initialSetupRequired) {
+ if (engine.jsonRpcClient.pushButtonAuthAvailable) {
+ print("opening push button auth")
+ var page = pageStack.push(Qt.resolvedUrl("PushButtonAuthPage.qml"))
+ page.backPressed.connect(function() {
+ settings.lastConnectedHost = "";
+ engine.connection.disconnect();
+ init();
+ })
+ } else {
+ var page = pageStack.push(Qt.resolvedUrl("LoginPage.qml"));
+ page.backPressed.connect(function() {
+ settings.lastConnectedHost = "";
+ engine.connection.disconnect()
+ init();
+ })
+ }
+ } else if (engine.jsonRpcClient.connected) {
+ pageStack.push(Qt.resolvedUrl("MainPage.qml"))
+ } else {
+ pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
+ }
+ }
+
+ function handleCloseEvent(close) {
+ if (Qt.platform.os == "android") {
+ // If we're connected, allow going back up to MainPage
+ if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
+ // if we're not connected, only allow using the back button in wizards
+ || (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
+ close.accepted = false;
+ pageStack.pop();
+ }
+ }
+ }
+
+ function setupPushNotifications(askForPermissions) {
+ if (askForPermissions === undefined) {
+ askForPermissions = true;
+ }
+
+ if (!engine.awsClient.isLoggedIn) {
+ print("AWS not logged in. Cannot register for push");
+ return;
+ }
+
+ if (PushNotifications.token.length === 0) {
+ print("Don't have a token yet. Cannot register for push");
+ return;
+ }
+
+ if (!PlatformHelper.hasPermissions) {
+ if (askForPermissions) {
+ PlatformHelper.requestPermissions();
+ }
+ } else {
+ engine.awsClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.deviceManufacturer + " " + PlatformHelper.deviceModel, PlatformHelper.deviceSerial + "+io.guh.nymeaapp");
+ }
+ }
+
+ Connections {
+ target: engine.jsonRpcClient
+ onConnectedChanged: {
+ print("json client connected changed", engine.jsonRpcClient.connected)
+ if (engine.jsonRpcClient.connected) {
+ settings.lastConnectedHost = engine.connection.url
+ }
+ init();
+ }
+
+ onAuthenticationRequiredChanged: {
+ print("auth required changed")
+ init();
+ }
+ onInitialSetupRequiredChanged: {
+ print("setup required changed")
+ init();
+ }
+
+ onInvalidProtocolVersion: {
+ var popup = invalidVersionComponent.createObject(app.contentItem);
+ popup.actualVersion = actualVersion;
+ popup.minimumVersion = minimumVersion
+ popup.open()
+ settings.lastConnectedHost = ""
+ }
+ }
+
+ Connections {
+ target: Qt.application
+ enabled: engine.jsonRpcClient.connected && settings.returnToHome
+ onStateChanged: {
+ print("App active state changed:", state)
+ if (state !== Qt.ApplicationActive) {
+ init();
+ }
+ }
+ }
+
+ Connections {
+ target: PlatformHelper
+ onHasPermissionsChanged: {
+ setupPushNotifications(false)
+ }
+ }
+
+ Connections {
+ target: PushNotifications
+ onTokenChanged: {
+ setupPushNotifications();
+ }
+ }
+
+ Connections {
+ target: engine.awsClient
+ onIsLoggedInChanged: {
+ setupPushNotifications()
+ }
+ }
+
+ Component {
+ id: invalidVersionComponent
+ Popup {
+ id: popup
+
+ property string actualVersion: "0.0"
+ property string minimumVersion: "1.0"
+
+ width: app.width * .8
+ height: col.childrenRect.height + app.margins * 2
+ x: (app.width - width) / 2
+ y: (app.height - height) / 2
+ visible: false
+ ColumnLayout {
+ id: col
+ anchors { left: parent.left; right: parent.right }
+ spacing: app.margins
+ Label {
+ text: qsTr("Connection error")
+ Layout.fillWidth: true
+ font.pixelSize: app.largeFont
+ }
+ Label {
+ text: qsTr("Sorry, the version of the %1 box you are trying to connect to is too old. This app requires at least version %2 but the %1 box only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion)
+ wrapMode: Text.WordWrap
+ Layout.fillWidth: true
+ }
+ Button {
+ Layout.fillWidth: true
+ text: qsTr("OK")
+ onClicked: {
+ engine.connection.disconnect();
+ popup.close()
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/nymea-app/ui/customviews/SensorView.qml b/nymea-app/ui/customviews/SensorView.qml
index 26f4dc5b..0a1ba567 100644
--- a/nymea-app/ui/customviews/SensorView.qml
+++ b/nymea-app/ui/customviews/SensorView.qml
@@ -25,7 +25,7 @@ CustomViewBase {
ValueLogsProxyModel {
id: logsModel
- engine: app.engine
+ engine: _engine
deviceId: root.device.id
typeIds: [stateType.id]
average: zoomTabBar.currentItem.avg
diff --git a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml b/nymea-app/ui/devicelistpages/DeviceListPageBase.qml
index ed5f9bf4..652bebbf 100644
--- a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml
+++ b/nymea-app/ui/devicelistpages/DeviceListPageBase.qml
@@ -32,6 +32,6 @@ Page {
DevicesProxy {
id: devicesProxyInternal
- engine: app.engine
+ engine: _engine
}
}
diff --git a/nymea-app/ui/devicepages/ButtonDevicePage.qml b/nymea-app/ui/devicepages/ButtonDevicePage.qml
index d1a349c4..7a8ee002 100644
--- a/nymea-app/ui/devicepages/ButtonDevicePage.qml
+++ b/nymea-app/ui/devicepages/ButtonDevicePage.qml
@@ -14,7 +14,7 @@ GenericDevicePage {
text: qsTr("This button has been pressed %1 times in the last %2 days.")
logsModel: LogsModel {
- engine: app.engine
+ engine: _engine
deviceId: root.device.id
live: true
typeIds: {
diff --git a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml
index 32e2105e..0c011755 100644
--- a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml
+++ b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml
@@ -13,7 +13,7 @@ GenericDevicePage {
text: qsTr("This event has appeared %1 times in the last %2 days.")
logsModel: LogsModel {
- engine: app.engine
+ engine: _engine
deviceId: root.device.id
live: true
Component.onCompleted: update()
diff --git a/nymea-app/ui/devicepages/StateLogPage.qml b/nymea-app/ui/devicepages/StateLogPage.qml
index b113c3b0..e06a7488 100644
--- a/nymea-app/ui/devicepages/StateLogPage.qml
+++ b/nymea-app/ui/devicepages/StateLogPage.qml
@@ -28,7 +28,7 @@ Page {
LogsModel {
id: logsModel
- engine: app.engine
+ engine: _engine
deviceId: root.device.id
live: true
Component.onCompleted: update()
diff --git a/nymea-app/ui/magic/SelectActionPage.qml b/nymea-app/ui/magic/SelectActionPage.qml
index 9bd43228..f8ff42fd 100644
--- a/nymea-app/ui/magic/SelectActionPage.qml
+++ b/nymea-app/ui/magic/SelectActionPage.qml
@@ -31,7 +31,7 @@ Page {
DevicesProxy {
id: ifaceFilterModel
- engine: app.engine
+ engine: _engine
}
Component.onCompleted: {
@@ -252,7 +252,7 @@ Page {
model: DevicesProxy {
id: lightsModel
- engine: app.engine
+ engine: _engine
shownInterfaces: ["light"]
}
delegate: CheckDelegate {
@@ -337,7 +337,7 @@ Page {
model: DevicesProxy {
id: notificationsModel
- engine: app.engine
+ engine: _engine
shownInterfaces: ["notifications"]
}
delegate: CheckDelegate {
diff --git a/nymea-app/ui/magic/SelectThingPage.qml b/nymea-app/ui/magic/SelectThingPage.qml
index a987ff0a..a0b7a2ff 100644
--- a/nymea-app/ui/magic/SelectThingPage.qml
+++ b/nymea-app/ui/magic/SelectThingPage.qml
@@ -34,7 +34,7 @@ Page {
DevicesProxy {
id: devicesProxy
- engine: app.engine
+ engine: _engine
}
ColumnLayout {
diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml
index d70b0fb0..99af5924 100644
--- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml
+++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml
@@ -37,19 +37,19 @@ MainPageTile {
DevicesProxy {
id: devicesProxy
- engine: app.engine
+ engine: _engine
shownInterfaces: [model.name]
}
DevicesProxy {
id: devicesSubProxyConnectables
- engine: app.engine
+ engine: _engine
parentProxy: devicesProxy
filterDisconnected: true
}
DevicesProxy {
id: devicesSubProxyBattery
- engine: app.engine
+ engine: _engine
parentProxy: devicesProxy
filterBatteryCritical: true
}
diff --git a/nymea-app/ui/system/LogViewerPage.qml b/nymea-app/ui/system/LogViewerPage.qml
index 4d276df0..8ede8b8b 100644
--- a/nymea-app/ui/system/LogViewerPage.qml
+++ b/nymea-app/ui/system/LogViewerPage.qml
@@ -25,7 +25,7 @@ Page {
LogsModel {
id: logsModel
- engine: app.engine
+ engine: _engine
startTime: {
var date = new Date();
date.setHours(new Date().getHours() - 2);