Fix #8 by giving networkmanager some time to initialize
This commit is contained in:
parent
4cf414d180
commit
e00530e098
@ -105,29 +105,8 @@ void Core::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_mode) {
|
// Note: give network-manager more time to start and get online status
|
||||||
case ModeAlways:
|
QTimer::singleShot(5000, this, &Core::postRun);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Core(QObject *parent) :
|
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()
|
void Core::onAdvertisingTimeout()
|
||||||
{
|
{
|
||||||
if (m_mode != ModeStart)
|
if (m_mode != ModeStart)
|
||||||
@ -313,6 +321,11 @@ void Core::onNetworkManagerAvailableChanged(const bool &available)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_initRunning) {
|
||||||
|
qCDebug(dcApplication()) << "Init is running";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qCDebug(dcApplication()) << "Networkmanager is now available.";
|
qCDebug(dcApplication()) << "Networkmanager is now available.";
|
||||||
m_bluetoothServer->onNetworkManagerAvailableChanged(available);
|
m_bluetoothServer->onNetworkManagerAvailableChanged(available);
|
||||||
|
|
||||||
|
|||||||
@ -79,6 +79,7 @@ private:
|
|||||||
QString m_advertiseName;
|
QString m_advertiseName;
|
||||||
QString m_platformName;
|
QString m_platformName;
|
||||||
int m_advertisingTimeout = 60;
|
int m_advertisingTimeout = 60;
|
||||||
|
bool m_initRunning = true;
|
||||||
|
|
||||||
void evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state);
|
void evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state);
|
||||||
|
|
||||||
@ -86,6 +87,8 @@ private:
|
|||||||
void stopService();
|
void stopService();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void postRun();
|
||||||
|
|
||||||
void onAdvertisingTimeout();
|
void onAdvertisingTimeout();
|
||||||
|
|
||||||
void onBluetoothServerRunningChanged(bool running);
|
void onBluetoothServerRunningChanged(bool running);
|
||||||
|
|||||||
Reference in New Issue
Block a user