@@ -1113,12 +1113,9 @@ void MozillaVPN::controllerStateChanged() {
11131113 }
11141114
11151115 if (!m_controllerInitialized && m_private->m_controller .isInitialized ()) {
1116+ logger.debug () << " Controller initialized" ;
11161117 m_controllerInitialized = true ;
1117-
1118- if (SettingsHolder::instance ()->startAtBoot ()) {
1119- logger.debug () << " Start on boot" ;
1120- activate ();
1121- }
1118+ maybeConnectOnStartup ();
11221119 }
11231120
11241121 if (m_updating && controllerState == Controller::StateOff) {
@@ -1127,6 +1124,16 @@ void MozillaVPN::controllerStateChanged() {
11271124 NetworkManager::instance ()->clearCache ();
11281125}
11291126
1127+ void MozillaVPN::maybeConnectOnStartup () {
1128+ if (m_controllerInitialized && m_locationInitialized) {
1129+ if (SettingsHolder::instance ()->startAtBoot ()) {
1130+ logger.debug ()
1131+ << " Both controller and location initialized. Starting on boot." ;
1132+ activate ();
1133+ }
1134+ }
1135+ }
1136+
11301137void MozillaVPN::heartbeatCompleted (bool success) {
11311138 logger.debug () << " Server-side check done:" << success;
11321139
@@ -1254,8 +1261,16 @@ void MozillaVPN::scheduleRefreshDataTasks() {
12541261 // https://mozilla-hub.atlassian.net/browse/VPN-3726 for more information.
12551262 if (!m_private->m_location .initialized () &&
12561263 !m_private->m_controller .isActive ()) {
1257- TaskScheduler::scheduleTask (
1258- new TaskGetLocation (ErrorHandler::PropagateError));
1264+ TaskGetLocation* locationTask =
1265+ new TaskGetLocation (ErrorHandler::PropagateError);
1266+ connect (locationTask, &TaskGetLocation::completed, [this ]() {
1267+ if (!m_locationInitialized) {
1268+ logger.debug () << " Location initialized" ;
1269+ m_locationInitialized = true ;
1270+ maybeConnectOnStartup ();
1271+ }
1272+ });
1273+ TaskScheduler::scheduleTask (locationTask);
12591274 }
12601275
12611276 TaskScheduler::scheduleTask (new TaskGroup (refreshTasks));
0 commit comments