Philipp Hörist pushed to branch master at gajim / gajim
Commits:
b3ac4828 by lovetox at 2022-04-29T22:13:40+02:00
feat: Improve finding proxy logic
- - - - -
c00a248d by lovetox at 2022-04-29T22:13:53+02:00
refactor: Application: Use helper method for version check
- - - - -
3 changed files:
- gajim/common/application.py
- gajim/common/helpers.py
- gajim/gtk/exception.py
Changes:
=====================================
gajim/common/application.py
=====================================
@@ -36,6 +36,7 @@
from gajim.common.events import AllowGajimUpdateCheck
from gajim.common.events import GajimUpdateAvailable
from gajim.common.client import Client
+from gajim.common.helpers import make_http_request
from gajim.common.task_manager import TaskManager
from gajim.common.settings import Settings
from gajim.common.settings import LegacyConfig
@@ -169,11 +170,8 @@ def _check_for_updates(self) -> None:
def check_for_gajim_updates(self) -> None:
self._log.info('Checking for Gajim updates')
- session = Soup.Session()
- session.props.user_agent = f'Gajim {app.version}'
- message = Soup.Message.new(
- 'GET', 'https://gajim.org/current-version.json')
- session.queue_message(message, self._on_update_response)
+ make_http_request('https://gajim.org/current-version.json',
+ self._on_update_response)
def _on_update_response(self,
_session: Soup.Session,
=====================================
gajim/common/helpers.py
=====================================
@@ -759,16 +759,24 @@ def get_proxy(proxy_name: str) -> Optional[ProxyData]:
password=password)
-def is_proxy_in_use() -> bool:
- return get_global_proxy() is not None or is_account_proxy_in_use()
+def determine_proxy() -> Optional[ProxyData]:
+ # Use this method to find a proxy for non-account related http requests
+ # When there is no global proxy and at least one active account does
+ # not use a proxy, we assume no proxy is necessary.
+ global_proxy = get_global_proxy()
+ if global_proxy is not None:
+ return global_proxy
-def is_account_proxy_in_use() -> bool:
+ proxies: list[ProxyData] = []
for client in app.get_clients():
account_proxy = get_account_proxy(client.account, fallback=False)
- if account_proxy is not None:
- return True
- return False
+ if account_proxy is None:
+ return None
+
+ proxies.append(account_proxy)
+
+ return proxies[0]
def version_condition(current_version: str, required_version: str) -> bool:
@@ -1508,11 +1516,8 @@ def make_path_from_jid(base_path: Path, jid: JID) ->
Path:
def make_http_request(uri: str, callback: Any) -> None:
- proxy = get_global_proxy()
+ proxy = determine_proxy()
if proxy is None:
- if is_account_proxy_in_use():
- raise ValueError('No global proxy found, '
- 'but account proxies are in use')
resolver = None
else:
=====================================
gajim/gtk/exception.py
=====================================
@@ -44,7 +44,7 @@
from gajim.common.helpers import get_gobject_version
from gajim.common.helpers import get_os_name
from gajim.common.helpers import get_os_version
-from gajim.common.helpers import is_proxy_in_use
+from gajim.common.helpers import determine_proxy
from gajim.common.helpers import make_http_request
from gajim.common.i18n import _
@@ -132,7 +132,7 @@ def __init__(self,
self._ui.user_feedback_entry.grab_focus()
def _on_report_clicked(self, _button: Gtk.Button) -> None:
- if self._sentry_available and not is_proxy_in_use():
+ if self._sentry_available and determine_proxy() is not None:
# sentry-sdk supports a http-proxy arg but for now only use
# sentry when no proxy is set, because we never tested if this
# works. It's not worth it to potentially leak users identity just
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/f6bcc2ed9ea956ef16798a475f570ec4426108e2...c00a248dc00218632f3618c497c25946c58a3bc1
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/f6bcc2ed9ea956ef16798a475f570ec4426108e2...c00a248dc00218632f3618c497c25946c58a3bc1
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits