Skip to content

Commit 6fb3aba

Browse files
authored
VPN-5290 - Add a 'never' option to reccomended serverlist (#11261)
1 parent e4e70ec commit 6fb3aba

6 files changed

Lines changed: 58 additions & 14 deletions

File tree

scripts/utils/generate_strings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ def parseYAMLTranslationStrings(yamlfile):
9494
value = [obj]
9595

9696
elif type(obj) is dict:
97+
allowed_keys = {"value", "comment"}
98+
unknown_keys = set(obj.keys()) - allowed_keys
99+
if unknown_keys:
100+
exit(
101+
f"The key {string_id} contains unknown field(s) "
102+
f"{sorted(unknown_keys)}. Allowed fields: "
103+
f"{sorted(allowed_keys)}"
104+
)
105+
97106
if not ("value" in obj):
98107
exit(
99108
f"The key {string_id} must contain a `value` string or an array of strings"

src/models/recommendedlocationmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ QVariant RecommendedLocationModel::data(const QModelIndex& index,
159159
}
160160

161161
void RecommendedLocationModel::maybeRefreshModel() {
162-
if (!MozillaVPN::instance()->serverLatency()->isActive()) {
162+
if (MozillaVPN::instance()->serverLatency()->state() !=
163+
ServerLatency::Loading) {
163164
if (m_timer.isActive()) {
164165
m_timer.stop();
165166
refreshModel();

src/qmlengineholder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "qmlengineholder.h"
66

7+
#include <QApplication>
78
#include <QNetworkAccessManager>
89
#include <QQmlApplicationEngine>
910
#include <QQmlNetworkAccessManagerFactory>

src/serverlatency.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ServerLatency final : public QObject {
2121
Q_PROPERTY(
2222
QDateTime lastUpdateTime READ lastUpdateTime NOTIFY progressChanged)
2323
Q_PROPERTY(qint64 avgLatency READ avgLatency NOTIFY progressChanged)
24-
Q_PROPERTY(bool isActive READ isActive NOTIFY progressChanged)
24+
Q_PROPERTY(State state READ state NOTIFY progressChanged)
2525
Q_PROPERTY(double progress READ progress NOTIFY progressChanged)
2626

2727
public:
@@ -38,8 +38,19 @@ class ServerLatency final : public QObject {
3838
};
3939
Q_ENUM(ConnectionScores);
4040

41+
enum State {
42+
Initial,
43+
Loading,
44+
Loaded,
45+
};
46+
Q_ENUM(State);
47+
4148
const QDateTime& lastUpdateTime() const { return m_lastUpdateTime; }
42-
bool isActive() const { return m_pingSender != nullptr; }
49+
State state() const {
50+
if (m_pingSender != nullptr) return Loading;
51+
if (m_lastUpdateTime.isValid()) return Loaded;
52+
return Initial;
53+
}
4354
double progress() const;
4455

4556
qint64 avgLatency() const;

src/translations/strings.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ serversView:
9494
value: "Last updated: %1. To update this list please disconnect from the VPN."
9595
comment: The time (or in extremely rare circumstances, the date, day of the week, or "yesterday") which the recommended servers list was last updated and instructions to re-enable the refresh button. Argument is the time or date/day
9696
recommendedRefreshLastUpdatedLabelYesterday: yesterday
97+
recommendedRefreshNoUpdateLabel:
98+
value: Tap to update
99+
comment: Label next to the refresh button shown when the recommended list has never been updated yet. The whole row is clickable and tapping triggers an update.
100+
recommendedRefreshNoUpdateDisabledLabel:
101+
value: Disconnect from the VPN to update this list.
102+
comment: Label next to the refresh button shown when the recommended list has never been updated yet but the user is connected to the VPN, so cannot update yet.
97103
serverCityWithGoodConnection:
98104
value: "%1. Good connectivity"
99105
comment: Button label that reads out a city name whose connection is good. Argument is the city name.
@@ -463,7 +469,7 @@ connectionInfo:
463469
comment: Label for the upload benchmark shown in the speed test view.
464470
unitPing:
465471
value: ms
466-
commnent: milliseconds
472+
comment: milliseconds
467473
loadingIndicatorLabel:
468474
value: Testing speed…
469475
comment: Shown to the user while waiting for the connection speed test results

src/ui/screens/home/servers/ServerList.qml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ FocusScope {
112112
Loader {
113113
id: serverListRecommendedEmptyLoader
114114

115-
active: VPNRecommendedLocationModel.rowCount() === 0 && !VPNServerLatency.isActive
115+
active: VPNRecommendedLocationModel.rowCount() === 0 && VPNServerLatency.state !== VPNServerLatency.Loading
116116
anchors.fill: parent
117117
sourceComponent: ColumnLayout {
118118

@@ -157,7 +157,7 @@ FocusScope {
157157

158158
anchors.fill: parent
159159

160-
active: VPNRecommendedLocationModel.rowCount() > 0 || VPNServerLatency.isActive
160+
active: VPNRecommendedLocationModel.rowCount() > 0 || VPNServerLatency.state === VPNServerLatency.Loading
161161
sourceComponent: Column {
162162
objectName: "serverListRecommended"
163163

@@ -183,7 +183,7 @@ FocusScope {
183183
accessibleName: statusTitle.text + '. ' + MZI18n.ServersViewRecommendedRefreshLabel
184184
canGrowVertical: true
185185
height: statusTitle.implicitHeight + MZTheme.theme.vSpacingSmall
186-
rowShouldBeDisabled: !(VPNController.state === VPNController.StateOff) || VPNServerLatency.isActive
186+
rowShouldBeDisabled: !(VPNController.state === VPNController.StateOff) || VPNServerLatency.state === VPNServerLatency.Loading
187187
opacity: 1.0
188188

189189
onClicked: {
@@ -214,13 +214,29 @@ FocusScope {
214214
Layout.maximumWidth: parent.width
215215

216216
horizontalAlignment: Text.AlignLeft
217-
// TODO: Replace placeholder strings and generate
218-
// values that will be set instead of `%1`
219-
text: VPNServerLatency.isActive
220-
? MZI18n.ServersViewRecommendedRefreshlLoadingLabel.arg(Math.round(VPNServerLatency.progress * 100))
221-
: (VPNController.state === VPNController.StateOff)
222-
? MZI18n.ServersViewRecommendedRefreshLastUpdatedLabel.arg(MZLocalizer.formatDate(new Date(), VPNServerLatency.lastUpdateTime, MZI18n.ServersViewRecommendedRefreshLastUpdatedLabelYesterday))
223-
: MZI18n.ServersViewRecommendedRefreshLastUpdatedDisabledLabel.arg(MZLocalizer.formatDate(new Date(), VPNServerLatency.lastUpdateTime, MZI18n.ServersViewRecommendedRefreshLastUpdatedLabelYesterday))
217+
text: {
218+
switch (VPNServerLatency.state) {
219+
case VPNServerLatency.Loading:
220+
return MZI18n.ServersViewRecommendedRefreshlLoadingLabel.arg(
221+
Math.round(VPNServerLatency.progress * 100));
222+
223+
case VPNServerLatency.Initial:
224+
return (VPNController.state === VPNController.StateOff)
225+
? MZI18n.ServersViewRecommendedRefreshNoUpdateLabel
226+
: MZI18n.ServersViewRecommendedRefreshNoUpdateDisabledLabel;
227+
228+
case VPNServerLatency.Loaded:
229+
default:
230+
const formatted = MZLocalizer.formatDate(
231+
new Date(),
232+
VPNServerLatency.lastUpdateTime,
233+
MZI18n.ServersViewRecommendedRefreshLastUpdatedLabelYesterday);
234+
const template = (VPNController.state === VPNController.StateOff)
235+
? MZI18n.ServersViewRecommendedRefreshLastUpdatedLabel
236+
: MZI18n.ServersViewRecommendedRefreshLastUpdatedDisabledLabel;
237+
return template.arg(formatted);
238+
}
239+
}
224240
wrapMode: Text.WordWrap
225241
}
226242

0 commit comments

Comments
 (0)