improve startup and connection
This commit is contained in:
parent
8335be43a3
commit
8091cbb8c6
@ -14,24 +14,24 @@ NymeaDiscovery::NymeaDiscovery(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_discoveryModel = new DiscoveryModel(this);
|
||||
connect(m_discoveryModel, &DiscoveryModel::deviceAdded, this, [this](DiscoveryDevice *device) {
|
||||
if (device->uuid() != m_pendingHostResolution) {
|
||||
if (!m_pendingHostResolutions.contains(device->uuid())) {
|
||||
return;
|
||||
}
|
||||
Connection *c = device->connections()->bestMatch();
|
||||
if (!c) {
|
||||
qDebug() << "Host found but there isn't a valid candidate yet?";
|
||||
connect(device->connections(), &Connections::connectionAdded, this, [this, device](Connection *connection) {
|
||||
if (device->uuid() == m_pendingHostResolution) {
|
||||
qDebug() << "Host" << m_pendingHostResolution << "resolved to" << connection->url().toString();
|
||||
m_pendingHostResolution = QUuid();
|
||||
emit serverUuidResolved(connection->url().toString());
|
||||
if (m_pendingHostResolutions.contains(device->uuid())) {
|
||||
qDebug() << "Host" << device->uuid() << "resolved to" << connection->url().toString();
|
||||
m_pendingHostResolutions.removeAll(device->uuid());
|
||||
emit serverUuidResolved(device->uuid(), connection->url().toString());
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
qDebug() << "Host" << m_pendingHostResolution << "appeared! Best match is" << c->url();
|
||||
m_pendingHostResolution = QUuid();
|
||||
emit serverUuidResolved(c->url().toString());
|
||||
qDebug() << "Host" << device->uuid() << "appeared! Best match is" << c->url();
|
||||
m_pendingHostResolutions.removeAll(device->uuid());
|
||||
emit serverUuidResolved(device->uuid(), c->url().toString());
|
||||
});
|
||||
|
||||
m_upnp = new UpnpDiscovery(m_discoveryModel, this);
|
||||
@ -133,6 +133,7 @@ void NymeaDiscovery::setAwsClient(AWSClient *awsClient)
|
||||
}
|
||||
|
||||
if (m_awsClient) {
|
||||
m_awsClient->fetchDevices();
|
||||
connect(m_awsClient, &AWSClient::devicesFetched, this, &NymeaDiscovery::syncCloudDevices);
|
||||
syncCloudDevices();
|
||||
}
|
||||
@ -144,17 +145,17 @@ void NymeaDiscovery::resolveServerUuid(const QUuid &uuid)
|
||||
DiscoveryDevice *dev = m_discoveryModel->find(uuid);
|
||||
if (!dev) {
|
||||
qDebug() << "Host" << uuid << "not known yet...";
|
||||
m_pendingHostResolution = uuid;
|
||||
m_pendingHostResolutions.append(uuid);
|
||||
return;
|
||||
}
|
||||
Connection *c = dev->connections()->bestMatch();
|
||||
if (!c) {
|
||||
qDebug() << "Host" << uuid << "is known but doesn't have a usable connection option yet.";
|
||||
m_pendingHostResolution = uuid;
|
||||
m_pendingHostResolutions.append(uuid);
|
||||
return;
|
||||
}
|
||||
qDebug() << "Host" << uuid << "is known. Best match is" << c->url();
|
||||
emit serverUuidResolved(c->url().toString());
|
||||
emit serverUuidResolved(uuid, c->url().toString());
|
||||
}
|
||||
|
||||
void NymeaDiscovery::syncCloudDevices()
|
||||
|
||||
@ -38,7 +38,7 @@ signals:
|
||||
void discoveringChanged();
|
||||
void awsClientChanged();
|
||||
|
||||
void serverUuidResolved(const QString &url);
|
||||
void serverUuidResolved(const QUuid &uuid, const QString &url);
|
||||
|
||||
private slots:
|
||||
void syncCloudDevices();
|
||||
@ -54,7 +54,7 @@ private:
|
||||
|
||||
QTimer m_cloudPollTimer;
|
||||
|
||||
QUuid m_pendingHostResolution;
|
||||
QList<QUuid> m_pendingHostResolutions;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -119,8 +119,5 @@ int main(int argc, char *argv[])
|
||||
|
||||
engine->load(QUrl(QLatin1String("qrc:/ui/Nymea.qml")));
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
QtAndroid::hideSplashScreen(250);
|
||||
#endif
|
||||
return application.exec();
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ public:
|
||||
|
||||
Q_INVOKABLE virtual void requestPermissions() = 0;
|
||||
|
||||
Q_INVOKABLE virtual void hideSplashScreen() = 0;
|
||||
|
||||
virtual bool hasPermissions() const = 0;
|
||||
virtual QString machineHostname() const = 0;
|
||||
virtual QString deviceSerial() const = 0;
|
||||
|
||||
@ -16,6 +16,16 @@ void PlatformHelperAndroid::requestPermissions()
|
||||
// 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
|
||||
{
|
||||
// Not using any fancy permissions in android yet...
|
||||
|
||||
@ -13,6 +13,8 @@ public:
|
||||
|
||||
Q_INVOKABLE void requestPermissions() override;
|
||||
|
||||
Q_INVOKABLE void hideSplashScreen() override;
|
||||
|
||||
bool hasPermissions() const override;
|
||||
QString machineHostname() const override;
|
||||
QString deviceSerial() const override;
|
||||
|
||||
@ -10,6 +10,11 @@ void PlatformHelperGeneric::requestPermissions()
|
||||
emit permissionsRequestFinished();
|
||||
}
|
||||
|
||||
void PlatformHelperGeneric::hideSplashScreen()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool PlatformHelperGeneric::hasPermissions() const
|
||||
{
|
||||
return true;
|
||||
|
||||
@ -12,6 +12,8 @@ public:
|
||||
|
||||
Q_INVOKABLE virtual void requestPermissions() override;
|
||||
|
||||
Q_INVOKABLE virtual void hideSplashScreen() override;
|
||||
|
||||
virtual bool hasPermissions() const override;
|
||||
virtual QString machineHostname() const override;
|
||||
virtual QString deviceSerial() const override;
|
||||
|
||||
@ -38,7 +38,6 @@ ApplicationWindow {
|
||||
property alias windowWidth: app.width
|
||||
property alias windowHeight: app.height
|
||||
property bool returnToHome: false
|
||||
property bool darkTheme: false
|
||||
property string graphStyle: "bars"
|
||||
property string style: "light"
|
||||
property bool showHiddenOptions: false
|
||||
@ -56,7 +55,7 @@ ApplicationWindow {
|
||||
id: discovery
|
||||
objectName: "discovery"
|
||||
awsClient: AWSClient
|
||||
discovering: pageStack.currentItem.objectName === "discoveryPage"
|
||||
// discovering: pageStack.currentItem.objectName === "discoveryPage"
|
||||
}
|
||||
|
||||
onClosing: {
|
||||
|
||||
@ -35,6 +35,14 @@ Item {
|
||||
tabbar.currentIndex = swipeView.currentIndex
|
||||
}
|
||||
function removeTab(index) {
|
||||
if (swipeView.currentIndex === index) {
|
||||
if (swipeView.currentIndex > 0) {
|
||||
swipeView.currentIndex--;
|
||||
} else {
|
||||
swipeView.currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
remove(index);
|
||||
settings.tabCount--;
|
||||
tabbar.currentIndex = swipeView.currentIndex
|
||||
@ -89,7 +97,7 @@ Item {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"), StackView.Immediate)
|
||||
setupPushNotifications();
|
||||
}
|
||||
|
||||
@ -98,6 +106,7 @@ Item {
|
||||
pageStack.clear()
|
||||
if (!engine.connection.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
PlatformHelper.hideSplashScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -118,11 +127,10 @@ Item {
|
||||
init();
|
||||
})
|
||||
}
|
||||
} else if (engine.jsonRpcClient.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
|
||||
} else {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
|
||||
}
|
||||
PlatformHelper.hideSplashScreen();
|
||||
}
|
||||
|
||||
function handleCloseEvent(close) {
|
||||
@ -135,7 +143,7 @@ Item {
|
||||
pageStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setupPushNotifications(askForPermissions) {
|
||||
if (askForPermissions === undefined) {
|
||||
@ -166,7 +174,7 @@ Item {
|
||||
onConnectedChanged: {
|
||||
print("json client connected changed", engine.jsonRpcClient.connected)
|
||||
if (engine.jsonRpcClient.connected) {
|
||||
tabSettings.lastConnectedHost = engine.connection.url
|
||||
tabSettings.lastConnectedHost = engine.jsonRpcClient.serverUuid
|
||||
}
|
||||
init();
|
||||
}
|
||||
@ -271,15 +279,23 @@ Item {
|
||||
id: tabbar
|
||||
Layout.fillWidth: true
|
||||
Material.elevation: 2
|
||||
position: TabBar.Footer
|
||||
|
||||
Repeater {
|
||||
model: mainRepeater.count
|
||||
model: tabModel.count
|
||||
|
||||
delegate: TabButton {
|
||||
id: hostTabButton
|
||||
property var engine: mainRepeater.itemAt(index)._engine
|
||||
property string serverName: engine.nymeaConfiguration.serverName
|
||||
Material.elevation: index
|
||||
width: Math.max(150, tabbar.width / tabbar.count)
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Material.foreground
|
||||
opacity: 0.06
|
||||
}
|
||||
|
||||
contentItem: RowLayout {
|
||||
Label {
|
||||
@ -324,7 +340,6 @@ Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,9 +11,11 @@ Page {
|
||||
readonly property bool haveHosts: discovery.discoveryModel.count > 0
|
||||
|
||||
Component.onCompleted: {
|
||||
print("completed connectPage. last connected host:", settings.lastConnectedHost)
|
||||
if (settings.lastConnectedHost.length > 0) {
|
||||
discovery.resolveServerUuid(settings.lastConnectedHost)
|
||||
print("completed connectPage. last connected host:", tabSettings.lastConnectedHost)
|
||||
if (tabSettings.lastConnectedHost.length > 0) {
|
||||
discovery.resolveServerUuid(tabSettings.lastConnectedHost)
|
||||
} else {
|
||||
PlatformHelper.hideSplashScreen();
|
||||
}
|
||||
|
||||
// if (settings.lastConnectedHost.length > 0 && Engine.connection.connect(tabSettings.lastConnectedHost)) {
|
||||
@ -24,19 +26,23 @@ Page {
|
||||
// pageStack.push(discoveryPage)
|
||||
// })
|
||||
// } else {
|
||||
pageStack.push(discoveryPage)
|
||||
pageStack.push(discoveryPage, StackView.Immediate)
|
||||
// }
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: discovery
|
||||
onServerUuidResolved: {
|
||||
connectToHost(url);
|
||||
print("** resolved", uuid, tabSettings.lastConnectedHost)
|
||||
if (uuid == tabSettings.lastConnectedHost) {
|
||||
print("yesss")
|
||||
connectToHost(url, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function connectToHost(url) {
|
||||
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
|
||||
function connectToHost(url, noAnimations) {
|
||||
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"), noAnimations ? StackView.Immediate : StackView.PushTransition)
|
||||
page.cancel.connect(function() {
|
||||
engine.connection.disconnect()
|
||||
pageStack.pop(root, StackView.Immediate);
|
||||
@ -124,10 +130,21 @@ Page {
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: startupTimer
|
||||
interval: 5000
|
||||
id: splashHideTimeout
|
||||
interval: 3000
|
||||
repeat: false
|
||||
running: true
|
||||
onTriggered: {
|
||||
PlatformHelper.hideSplashScreen()
|
||||
startupTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: startupTimer
|
||||
interval: 10000
|
||||
repeat: false
|
||||
running: false
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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">
|
||||
|
||||
<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>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="rectangle" >
|
||||
<solid android:color="#FFFFFFFF"/>
|
||||
<solid android:color="#303030"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:src="@mipmap/icon"
|
||||
<bitmap android:src="@drawable/round_icon"
|
||||
android:gravity="center" />
|
||||
</item>
|
||||
</layer-list>
|
||||
Reference in New Issue
Block a user