improve startup and connection

This commit is contained in:
Michael Zanetti 2019-01-30 00:31:07 +01:00
parent 8335be43a3
commit 8091cbb8c6
13 changed files with 88 additions and 38 deletions

View File

@ -14,24 +14,24 @@ NymeaDiscovery::NymeaDiscovery(QObject *parent) : QObject(parent)
{ {
m_discoveryModel = new DiscoveryModel(this); m_discoveryModel = new DiscoveryModel(this);
connect(m_discoveryModel, &DiscoveryModel::deviceAdded, this, [this](DiscoveryDevice *device) { connect(m_discoveryModel, &DiscoveryModel::deviceAdded, this, [this](DiscoveryDevice *device) {
if (device->uuid() != m_pendingHostResolution) { if (!m_pendingHostResolutions.contains(device->uuid())) {
return; return;
} }
Connection *c = device->connections()->bestMatch(); Connection *c = device->connections()->bestMatch();
if (!c) { if (!c) {
qDebug() << "Host found but there isn't a valid candidate yet?"; qDebug() << "Host found but there isn't a valid candidate yet?";
connect(device->connections(), &Connections::connectionAdded, this, [this, device](Connection *connection) { connect(device->connections(), &Connections::connectionAdded, this, [this, device](Connection *connection) {
if (device->uuid() == m_pendingHostResolution) { if (m_pendingHostResolutions.contains(device->uuid())) {
qDebug() << "Host" << m_pendingHostResolution << "resolved to" << connection->url().toString(); qDebug() << "Host" << device->uuid() << "resolved to" << connection->url().toString();
m_pendingHostResolution = QUuid(); m_pendingHostResolutions.removeAll(device->uuid());
emit serverUuidResolved(connection->url().toString()); emit serverUuidResolved(device->uuid(), connection->url().toString());
} }
}); });
return; return;
} }
qDebug() << "Host" << m_pendingHostResolution << "appeared! Best match is" << c->url(); qDebug() << "Host" << device->uuid() << "appeared! Best match is" << c->url();
m_pendingHostResolution = QUuid(); m_pendingHostResolutions.removeAll(device->uuid());
emit serverUuidResolved(c->url().toString()); emit serverUuidResolved(device->uuid(), c->url().toString());
}); });
m_upnp = new UpnpDiscovery(m_discoveryModel, this); m_upnp = new UpnpDiscovery(m_discoveryModel, this);
@ -133,6 +133,7 @@ void NymeaDiscovery::setAwsClient(AWSClient *awsClient)
} }
if (m_awsClient) { if (m_awsClient) {
m_awsClient->fetchDevices();
connect(m_awsClient, &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices); connect(m_awsClient, &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices);
syncCloudDevices(); syncCloudDevices();
} }
@ -144,17 +145,17 @@ void NymeaDiscovery::resolveServerUuid(const QUuid &uuid)
DiscoveryDevice *dev = m_discoveryModel->find(uuid); DiscoveryDevice *dev = m_discoveryModel->find(uuid);
if (!dev) { if (!dev) {
qDebug() << "Host" << uuid << "not known yet..."; qDebug() << "Host" << uuid << "not known yet...";
m_pendingHostResolution = uuid; m_pendingHostResolutions.append(uuid);
return; return;
} }
Connection *c = dev->connections()->bestMatch(); Connection *c = dev->connections()->bestMatch();
if (!c) { if (!c) {
qDebug() << "Host" << uuid << "is known but doesn't have a usable connection option yet."; qDebug() << "Host" << uuid << "is known but doesn't have a usable connection option yet.";
m_pendingHostResolution = uuid; m_pendingHostResolutions.append(uuid);
return; return;
} }
qDebug() << "Host" << uuid << "is known. Best match is" << c->url(); qDebug() << "Host" << uuid << "is known. Best match is" << c->url();
emit serverUuidResolved(c->url().toString()); emit serverUuidResolved(uuid, c->url().toString());
} }
void NymeaDiscovery::syncCloudDevices() void NymeaDiscovery::syncCloudDevices()

View File

@ -38,7 +38,7 @@ signals:
void discoveringChanged(); void discoveringChanged();
void awsClientChanged(); void awsClientChanged();
void serverUuidResolved(const QString &url); void serverUuidResolved(const QUuid &uuid, const QString &url);
private slots: private slots:
void syncCloudDevices(); void syncCloudDevices();
@ -54,7 +54,7 @@ private:
QTimer m_cloudPollTimer; QTimer m_cloudPollTimer;
QUuid m_pendingHostResolution; QList<QUuid> m_pendingHostResolutions;
}; };

View File

@ -119,8 +119,5 @@ int main(int argc, char *argv[])
engine->load(QUrl(QLatin1String("qrc:/ui/Nymea.qml"))); engine->load(QUrl(QLatin1String("qrc:/ui/Nymea.qml")));
#ifdef Q_OS_ANDROID
QtAndroid::hideSplashScreen(250);
#endif
return application.exec(); return application.exec();
} }

View File

@ -25,6 +25,8 @@ public:
Q_INVOKABLE virtual void requestPermissions() = 0; Q_INVOKABLE virtual void requestPermissions() = 0;
Q_INVOKABLE virtual void hideSplashScreen() = 0;
virtual bool hasPermissions() const = 0; virtual bool hasPermissions() const = 0;
virtual QString machineHostname() const = 0; virtual QString machineHostname() const = 0;
virtual QString deviceSerial() const = 0; virtual QString deviceSerial() const = 0;

View File

@ -16,6 +16,16 @@ void PlatformHelperAndroid::requestPermissions()
// Not using any fancy permissions in android yet... // Not using any fancy permissions in android yet...
} }
void PlatformHelperAndroid::hideSplashScreen()
{
// Android's splash will flicker when fading out twice
static bool alreadyHiding = false;
if (!alreadyHiding) {
QtAndroid::hideSplashScreen(250);
alreadyHiding = true;
}
}
bool PlatformHelperAndroid::hasPermissions() const bool PlatformHelperAndroid::hasPermissions() const
{ {
// Not using any fancy permissions in android yet... // Not using any fancy permissions in android yet...

View File

@ -13,6 +13,8 @@ public:
Q_INVOKABLE void requestPermissions() override; Q_INVOKABLE void requestPermissions() override;
Q_INVOKABLE void hideSplashScreen() override;
bool hasPermissions() const override; bool hasPermissions() const override;
QString machineHostname() const override; QString machineHostname() const override;
QString deviceSerial() const override; QString deviceSerial() const override;

View File

@ -10,6 +10,11 @@ void PlatformHelperGeneric::requestPermissions()
emit permissionsRequestFinished(); emit permissionsRequestFinished();
} }
void PlatformHelperGeneric::hideSplashScreen()
{
}
bool PlatformHelperGeneric::hasPermissions() const bool PlatformHelperGeneric::hasPermissions() const
{ {
return true; return true;

View File

@ -12,6 +12,8 @@ public:
Q_INVOKABLE virtual void requestPermissions() override; Q_INVOKABLE virtual void requestPermissions() override;
Q_INVOKABLE virtual void hideSplashScreen() override;
virtual bool hasPermissions() const override; virtual bool hasPermissions() const override;
virtual QString machineHostname() const override; virtual QString machineHostname() const override;
virtual QString deviceSerial() const override; virtual QString deviceSerial() const override;

View File

@ -38,7 +38,6 @@ ApplicationWindow {
property alias windowWidth: app.width property alias windowWidth: app.width
property alias windowHeight: app.height property alias windowHeight: app.height
property bool returnToHome: false property bool returnToHome: false
property bool darkTheme: false
property string graphStyle: "bars" property string graphStyle: "bars"
property string style: "light" property string style: "light"
property bool showHiddenOptions: false property bool showHiddenOptions: false
@ -56,7 +55,7 @@ ApplicationWindow {
id: discovery id: discovery
objectName: "discovery" objectName: "discovery"
awsClient: AWSClient awsClient: AWSClient
discovering: pageStack.currentItem.objectName === "discoveryPage" // discovering: pageStack.currentItem.objectName === "discoveryPage"
} }
onClosing: { onClosing: {

View File

@ -35,6 +35,14 @@ Item {
tabbar.currentIndex = swipeView.currentIndex tabbar.currentIndex = swipeView.currentIndex
} }
function removeTab(index) { function removeTab(index) {
if (swipeView.currentIndex === index) {
if (swipeView.currentIndex > 0) {
swipeView.currentIndex--;
} else {
swipeView.currentIndex++;
}
}
remove(index); remove(index);
settings.tabCount--; settings.tabCount--;
tabbar.currentIndex = swipeView.currentIndex tabbar.currentIndex = swipeView.currentIndex
@ -89,7 +97,7 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"), StackView.Immediate)
setupPushNotifications(); setupPushNotifications();
} }
@ -98,6 +106,7 @@ Item {
pageStack.clear() pageStack.clear()
if (!engine.connection.connected) { if (!engine.connection.connected) {
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
PlatformHelper.hideSplashScreen();
return; return;
} }
@ -118,11 +127,10 @@ Item {
init(); init();
}) })
} }
} else if (engine.jsonRpcClient.connected) {
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
} else { } else {
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml")) pageStack.push(Qt.resolvedUrl("MainPage.qml"))
} }
PlatformHelper.hideSplashScreen();
} }
function handleCloseEvent(close) { function handleCloseEvent(close) {
@ -135,7 +143,7 @@ Item {
pageStack.pop(); pageStack.pop();
} }
} }
} }
function setupPushNotifications(askForPermissions) { function setupPushNotifications(askForPermissions) {
if (askForPermissions === undefined) { if (askForPermissions === undefined) {
@ -166,7 +174,7 @@ Item {
onConnectedChanged: { onConnectedChanged: {
print("json client connected changed", engine.jsonRpcClient.connected) print("json client connected changed", engine.jsonRpcClient.connected)
if (engine.jsonRpcClient.connected) { if (engine.jsonRpcClient.connected) {
tabSettings.lastConnectedHost = engine.connection.url tabSettings.lastConnectedHost = engine.jsonRpcClient.serverUuid
} }
init(); init();
} }
@ -271,15 +279,23 @@ Item {
id: tabbar id: tabbar
Layout.fillWidth: true Layout.fillWidth: true
Material.elevation: 2 Material.elevation: 2
position: TabBar.Footer
Repeater { Repeater {
model: mainRepeater.count model: tabModel.count
delegate: TabButton { delegate: TabButton {
id: hostTabButton id: hostTabButton
property var engine: mainRepeater.itemAt(index)._engine property var engine: mainRepeater.itemAt(index)._engine
property string serverName: engine.nymeaConfiguration.serverName property string serverName: engine.nymeaConfiguration.serverName
Material.elevation: index Material.elevation: index
width: Math.max(150, tabbar.width / tabbar.count)
Rectangle {
anchors.fill: parent
color: Material.foreground
opacity: 0.06
}
contentItem: RowLayout { contentItem: RowLayout {
Label { Label {
@ -324,7 +340,6 @@ Item {
} }
} }
} }
} }
} }
} }

View File

@ -11,9 +11,11 @@ Page {
readonly property bool haveHosts: discovery.discoveryModel.count > 0 readonly property bool haveHosts: discovery.discoveryModel.count > 0
Component.onCompleted: { Component.onCompleted: {
print("completed connectPage. last connected host:", settings.lastConnectedHost) print("completed connectPage. last connected host:", tabSettings.lastConnectedHost)
if (settings.lastConnectedHost.length > 0) { if (tabSettings.lastConnectedHost.length > 0) {
discovery.resolveServerUuid(settings.lastConnectedHost) discovery.resolveServerUuid(tabSettings.lastConnectedHost)
} else {
PlatformHelper.hideSplashScreen();
} }
// if (settings.lastConnectedHost.length > 0 && Engine.connection.connect(tabSettings.lastConnectedHost)) { // if (settings.lastConnectedHost.length > 0 && Engine.connection.connect(tabSettings.lastConnectedHost)) {
@ -24,19 +26,23 @@ Page {
// pageStack.push(discoveryPage) // pageStack.push(discoveryPage)
// }) // })
// } else { // } else {
pageStack.push(discoveryPage) pageStack.push(discoveryPage, StackView.Immediate)
// } // }
} }
Connections { Connections {
target: discovery target: discovery
onServerUuidResolved: { onServerUuidResolved: {
connectToHost(url); print("** resolved", uuid, tabSettings.lastConnectedHost)
if (uuid == tabSettings.lastConnectedHost) {
print("yesss")
connectToHost(url, true);
}
} }
} }
function connectToHost(url) { function connectToHost(url, noAnimations) {
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml")) var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"), noAnimations ? StackView.Immediate : StackView.PushTransition)
page.cancel.connect(function() { page.cancel.connect(function() {
engine.connection.disconnect() engine.connection.disconnect()
pageStack.pop(root, StackView.Immediate); pageStack.pop(root, StackView.Immediate);
@ -124,10 +130,21 @@ Page {
} }
Timer { Timer {
id: startupTimer id: splashHideTimeout
interval: 5000 interval: 3000
repeat: false repeat: false
running: true running: true
onTriggered: {
PlatformHelper.hideSplashScreen()
startupTimer.start()
}
}
Timer {
id: startupTimer
interval: 10000
repeat: false
running: false
} }

View File

@ -2,7 +2,7 @@
<manifest package="io.guh.nymeaapp" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto"> <manifest package="io.guh.nymeaapp" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="nymea:app" android:icon="@mipmap/icon" android:roundIcon="@mipmap/round_icon"> <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="nymea:app" android:icon="@mipmap/icon" android:roundIcon="@mipmap/round_icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="io.guh.nymeaapp.NymeaAppActivity" android:label="nymea:app" android:screenOrientation="unspecified" android:launchMode="singleTop"> <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="io.guh.nymeaapp.NymeaAppActivity" android:label="nymea:app" android:screenOrientation="unspecified" android:launchMode="singleTop" android:theme="@style/SplashScreenTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>

View File

@ -2,11 +2,11 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item> <item>
<shape android:shape="rectangle" > <shape android:shape="rectangle" >
<solid android:color="#FFFFFFFF"/> <solid android:color="#303030"/>
</shape> </shape>
</item> </item>
<item> <item>
<bitmap android:src="@mipmap/icon" <bitmap android:src="@drawable/round_icon"
android:gravity="center" /> android:gravity="center" />
</item> </item>
</layer-list> </layer-list>