Fix #8 by giving networkmanager some time to initialize

This commit is contained in:
Simon Stürz 2019-01-10 20:46:43 +01:00
parent 4cf414d180
commit e00530e098
2 changed files with 39 additions and 23 deletions

View File

@ -105,29 +105,8 @@ void Core::run()
return;
}
switch (m_mode) {
case ModeAlways:
qCDebug(dcApplication()) << "Start the bluetooth service because of \"always\" mode.";
startService();
break;
case ModeStart:
qCDebug(dcApplication()) << "Start the bluetooth service because of \"start\" mode.";
startService();
m_advertisingTimer->start(m_advertisingTimeout * 1000);
break;
case ModeOffline:
evaluateNetworkManagerState(m_networkManager->state());
break;
case ModeOnce:
if (m_networkManager->networkSettings()->connections().isEmpty()) {
qCDebug(dcApplication()) << "Start the bluetooth service because of \"once\" mode and there is currenlty no network configured yet.";
startService();
} else {
qCDebug(dcApplication()) << "Not starting the bluetooth service because of \"once\" mode. There are" << m_networkManager->networkSettings()->connections().count() << "network configurations.";
}
break;
}
// Note: give network-manager more time to start and get online status
QTimer::singleShot(5000, this, &Core::postRun);
}
Core::Core(QObject *parent) :
@ -243,6 +222,35 @@ void Core::stopService()
}
}
void Core::postRun()
{
qCDebug(dcApplication()) << "Post run service";
m_initRunning = false;
switch (m_mode) {
case ModeAlways:
qCDebug(dcApplication()) << "Start the bluetooth service because of \"always\" mode.";
startService();
break;
case ModeStart:
qCDebug(dcApplication()) << "Start the bluetooth service because of \"start\" mode.";
startService();
m_advertisingTimer->start(m_advertisingTimeout * 1000);
break;
case ModeOffline:
evaluateNetworkManagerState(m_networkManager->state());
break;
case ModeOnce:
if (m_networkManager->networkSettings()->connections().isEmpty()) {
qCDebug(dcApplication()) << "Start the bluetooth service because of \"once\" mode and there is currenlty no network configured yet.";
startService();
} else {
qCDebug(dcApplication()) << "Not starting the bluetooth service because of \"once\" mode. There are" << m_networkManager->networkSettings()->connections().count() << "network configurations.";
}
break;
}
}
void Core::onAdvertisingTimeout()
{
if (m_mode != ModeStart)
@ -313,6 +321,11 @@ void Core::onNetworkManagerAvailableChanged(const bool &available)
return;
}
if (m_initRunning) {
qCDebug(dcApplication()) << "Init is running";
return;
}
qCDebug(dcApplication()) << "Networkmanager is now available.";
m_bluetoothServer->onNetworkManagerAvailableChanged(available);

View File

@ -79,6 +79,7 @@ private:
QString m_advertiseName;
QString m_platformName;
int m_advertisingTimeout = 60;
bool m_initRunning = true;
void evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state);
@ -86,6 +87,8 @@ private:
void stopService();
private slots:
void postRun();
void onAdvertisingTimeout();
void onBluetoothServerRunningChanged(bool running);