Skip to content

Commit

Permalink
Fix server feature issue when displaying connection status
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Cheltuitor committed Apr 22, 2021
1 parent edf7ba1 commit 6e72d0d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion arch/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Proton Technologies AG <[email protected]>
pkgname=protonvpn-cli
pkgver=3.5.0
pkgrel=1
pkgrel=2
pkgdesc="Official ProtonVPN CLI."
arch=("any")
url="https://github.com/ProtonVPN/"
Expand Down
3 changes: 2 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
protonvpn-cli (3.5.0-1) unstable; urgency=low
protonvpn-cli (3.5.0-2) unstable; urgency=low

* Handle servers with multiple features
* Fix server feature issue when displaying connection status

-- Proton Technologies AG <[email protected]> Tue, 30 Mar 2021 12:20:00 +0100

Expand Down
19 changes: 16 additions & 3 deletions protonvpn_cli/cli_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import sys

from dialog import Dialog
Expand Down Expand Up @@ -110,9 +111,21 @@ def display_servers(self, country, countries):
servername
)
load = str(int(server.load)).rjust(3, " ")
features = ", ".join(
[self.SUPPORTED_FEATURES[feature] for feature in server.features]
)
_features = copy.copy(server.features)
try:
_features.pop(FeatureEnum.NORMAL)
except IndexError:
pass

if len(_features) > 1:
features = ", ".join(
[self.SUPPORTED_FEATURES[feature] for feature in _features]
)
elif len(_features) == 1:
features = self.SUPPORTED_FEATURES[_features[0]]
else:
features = ""

tier = self.SERVER_TIERS[ServerTierEnum(server.tier)]

choices.append(
Expand Down
34 changes: 22 additions & 12 deletions protonvpn_cli/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import time
from textwrap import dedent
import copy

from proton.constants import VERSION as proton_version
from protonvpn_nm_lib import exceptions
Expand Down Expand Up @@ -582,6 +583,12 @@ def status(self):
print("\nNo active ProtonVPN connection.")
return

# cache servers if needed
try:
self.protonvpn.get_session().servers
except: # noqa
pass

logger.info("Gathering connection information")
conn_status_dict = self.__transform_status_to_readable_format(
self.protonvpn.get_connection_status()
Expand All @@ -591,12 +598,21 @@ def status(self):
)

tier_enum = ServerTierEnum(server.tier)
_features = copy.copy(server.features)
try:
_features.pop(FeatureEnum.NORMAL)
except IndexError:
pass

features = ", ".join(
[self.SUPPORTED_FEATURES[feature] for feature in server.features]
)
if len(_features) > 1:
features = ", ".join(
[self.SUPPORTED_FEATURES[feature] for feature in _features]
)
elif len(_features) == 1:
features = self.SUPPORTED_FEATURES[_features[0]]
else:
features = "None"
features = "Server Features: " + features

entry_country = self.protonvpn.country.get_country_name(
server.entry_country
)
Expand Down Expand Up @@ -625,17 +641,11 @@ def status(self):
load=int(server.load),
server_tier=self.SERVER_TIERS[tier_enum],
features=""
if (
len(server.features) == 0
or (
len(server.features) == 1
and FeatureEnum.NORMAL in server.features
)
)
if len(_features) == 0
else features + "\n",
secure_core=(
"{} >> ".format(entry_country)
if FeatureEnum.SECURE_CORE in server.features
if FeatureEnum.SECURE_CORE in _features
else ""
),
killswitch_status=conn_status_dict[
Expand Down
5 changes: 3 additions & 2 deletions rpmbuild/SPECS/protonvpn-cli.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%define unmangled_name protonvpn-cli
%define version 3.5.0
%define release 1
%define release 2

Prefix: %{_prefix}

Expand Down Expand Up @@ -46,8 +46,9 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root)

%changelog
* Tue Mar 30 2021 Proton Technologies AG <[email protected]> 3.5.0-1
* Tue Mar 30 2021 Proton Technologies AG <[email protected]> 3.5.0-2
- Handle servers with multiple features
- Fix server feature issue when displaying connection status

* Tue Mar 30 2021 Proton Technologies AG <[email protected]> 3.4.1-4
- Fix dialog crash
Expand Down

0 comments on commit 6e72d0d

Please sign in to comment.