Skip to content

Commit 43a100a

Browse files
authored
VPN-7002 fix - always load location (#10589) (#10590)
1 parent 9be1845 commit 43a100a

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

addons/message_upgrade_to_bundle_1/conditions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ api.connectSignal(api.subscriptionData, 'changed', () => computeCondition());
2020
api.connectSignal(
2121
api.subscriptionData, 'initialized', () => computeCondition());
2222

23+
// Run on app launch after getting current location
24+
api.connectSignal(api.location, 'changed', () => computeCondition());
25+
2326
// This is for already-running clients that receive this addon while the client
2427
// is launched and signed in. (These users may not see a change in
2528
// subscriptionData for a long time.)

addons/message_upgrade_to_bundle_2/conditions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ api.connectSignal(api.subscriptionData, 'changed', () => computeCondition());
2020
api.connectSignal(
2121
api.subscriptionData, 'initialized', () => computeCondition());
2222

23+
// Run on app launch after getting current location
24+
api.connectSignal(api.location, 'changed', () => computeCondition());
25+
2326
// This is for already-running clients that receive this addon while the client
2427
// is launched and signed in. (These users may not see a change in
2528
// subscriptionData for a long time.)

addons/message_upgrade_to_bundle_3/conditions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ api.connectSignal(api.subscriptionData, 'changed', () => computeCondition());
2020
api.connectSignal(
2121
api.subscriptionData, 'initialized', () => computeCondition());
2222

23+
// Run on app launch after getting current location
24+
api.connectSignal(api.location, 'changed', () => computeCondition());
25+
2326
// This is for already-running clients that receive this addon while the client
2427
// is launched and signed in. (These users may not see a change in
2528
// subscriptionData for a long time.)

src/mozillavpn.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
11301137
void 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));

src/mozillavpn.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class MozillaVPN final : public App {
222222

223223
void controllerStateChanged();
224224

225+
void maybeConnectOnStartup();
226+
225227
void maybeRegenerateDeviceKey();
226228

227229
bool checkCurrentDevice();
@@ -275,6 +277,7 @@ class MozillaVPN final : public App {
275277
bool m_startMinimized = false;
276278
bool m_updating = false;
277279
bool m_controllerInitialized = false;
280+
bool m_locationInitialized = false;
278281
};
279282

280283
#endif // MOZILLAVPN_H

0 commit comments

Comments
 (0)