From 2a8ddccc99aee88c8aabfc89e6cf56651e385663 Mon Sep 17 00:00:00 2001 From: elParaguayo Date: Thu, 21 Jul 2022 07:57:27 +0500 Subject: [PATCH] GithubNotifications: fix blocking web call The API call can block causing the system to appear unresponsive. Run the call in a thread instead. Fixes #80 --- CHANGELOG | 1 + qtile_extras/widget/githubnotifications.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 92c4d83b..433fb065 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +2022-07-21: [BUGFIX] Fix blocking API calls in Snapcast and GithubNotification widgets 2022-07-07: [BUGFIX] Fix UPowerWidget not showing text on click when fontsize is None 2022-07-03: [PACKAGING] Use git versioning details 2022-07-03: [BUGFIX] Fix scaling on CurrentLayoutIcon and disable `use_mask=True` default diff --git a/qtile_extras/widget/githubnotifications.py b/qtile_extras/widget/githubnotifications.py index a0a7b7b6..465da9c7 100644 --- a/qtile_extras/widget/githubnotifications.py +++ b/qtile_extras/widget/githubnotifications.py @@ -118,12 +118,18 @@ def update(self): logger.error("No access token provided.") return + future = self.qtile.run_in_executor(self._get_data) + future.add_done_callback(self._read_data) + + def _get_data(self): headers = { "Accept": "application/vnd.github.v3+json", "Authorization": f"token {self.token}", } + return requests.get(NOTIFICATIONS, headers=headers) - r = requests.get(NOTIFICATIONS, headers=headers) + def _read_data(self, reply): + r = reply.result() if r.status_code != 200: self.error = True