Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
ccaa27ec by wurstsalat at 2024-09-29T11:01:17+02:00
fix: Windows: Fix detecting MS Store version
- - - - -
5d3a7304 by wurstsalat at 2024-09-29T11:01:17+02:00
fix: Windows: Fix Notification AUMID for MS Store install
Fixes #11965
- - - - -
2 changed files:
- gajim/__init__.py
- gajim/gtk/notification.py
Changes:
=====================================
gajim/__init__.py
=====================================
@@ -13,7 +13,7 @@
has_ms_appinfo = False
try:
from winrt.windows.applicationmodel import AppInfo
- _current_appinfo = AppInfo.current() # type: ignore
+ _current_appinfo = AppInfo.current # type: ignore
has_ms_appinfo = True
except Exception:
pass
=====================================
gajim/gtk/notification.py
=====================================
@@ -17,6 +17,7 @@
from __future__ import annotations
from typing import Any
+from typing import cast
from typing import TYPE_CHECKING
import hashlib
@@ -63,8 +64,6 @@
int(platform.version().split('.')[2]) >=
MIN_WINDOWS_TOASTS_WIN_VERSION) or
TYPE_CHECKING):
# Importing windows_toasts on an unsupported Windows version will throw an
Exception
- import winreg
-
from windows_toasts import InteractableWindowsToaster
from windows_toasts import Toast
from windows_toasts import ToastActivatedEventArgs
@@ -73,9 +72,6 @@
from windows_toasts import ToastImage
from windows_toasts import ToastImagePosition
-
-WINDOWS_TOAST_NOTIFIER_AUMID = 'Gajim.ToastNotification'
-
log = logging.getLogger('gajim.gtk.notification')
NOTIFICATION_ICONS: dict[str, str] = {
@@ -293,19 +289,26 @@ def _on_destroy(self, _widget: Gtk.Window) -> None:
class WindowsToastNotification(NotificationBackend):
def __init__(self):
NotificationBackend.__init__(self)
- self._register_notifier_aumid()
+
+ if app.is_ms_store():
+ from winrt.windows.applicationmodel import AppInfo
+ aumid = cast(str, AppInfo.current.app_user_model_id) # type:
ignore
+ else:
+ # Non MS Store version has to register an AUMID manually
+ aumid = 'Gajim.ToastNotification'
+ self._register_notifier_aumid(aumid)
self._toaster = InteractableWindowsToaster(
applicationText='Gajim',
- notifierAUMID=WINDOWS_TOAST_NOTIFIER_AUMID
+ notifierAUMID=aumid
)
- def _register_notifier_aumid(self) -> None:
+ def _register_notifier_aumid(self, aumid: str) -> None:
'''Register an AUMID for Gajim's toast notifications.
This allows notifications issued by Gajim to have the right icon and
title.
Code taken from:
https://github.com/DatGuy1/Windows-Toasts/blob/main/scripts/register_hkey_aumid.py
'''
- key_path =
f'SOFTWARE\\Classes\\AppUserModelId\\{WINDOWS_TOAST_NOTIFIER_AUMID}'
+ key_path = f'SOFTWARE\\Classes\\AppUserModelId\\{aumid}'
image_path = (
Path(sys.executable).parent.parent
@@ -316,6 +319,8 @@ def _register_notifier_aumid(self) -> None:
/ 'apps'
/ 'gajim.png'
)
+
+ import winreg
winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
with winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, key_path) as
master_key:
winreg.SetValueEx(master_key, 'DisplayName', 0, winreg.REG_SZ,
'Gajim')
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/643e4d0275f13850ace561d674923df14a57ca84...5d3a7304be1505f864eafd1c35f41beeec0cce12
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/643e4d0275f13850ace561d674923df14a57ca84...5d3a7304be1505f864eafd1c35f41beeec0cce12
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]