desktop-notifier 3.5.6__tar.gz → 3.5.7.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {desktop-notifier-3.5.6/src/desktop_notifier.egg-info → desktop_notifier-3.5.7.dev1}/PKG-INFO +23 -3
  2. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/README.md +1 -1
  3. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/pyproject.toml +11 -7
  4. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/__init__.py +1 -1
  5. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/base.py +20 -16
  6. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/dbus.py +29 -31
  7. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/dummy.py +2 -8
  8. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/macos.py +6 -4
  9. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/macos_legacy.py +3 -3
  10. desktop_notifier-3.5.7.dev1/src/desktop_notifier/py.typed +0 -0
  11. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/winrt.py +80 -58
  12. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1/src/desktop_notifier.egg-info}/PKG-INFO +23 -3
  13. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier.egg-info/SOURCES.txt +1 -0
  14. desktop_notifier-3.5.7.dev1/src/desktop_notifier.egg-info/requires.txt +30 -0
  15. desktop-notifier-3.5.6/src/desktop_notifier.egg-info/requires.txt +0 -26
  16. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/LICENSE +0 -0
  17. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/setup.cfg +0 -0
  18. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/macos_support.py +0 -0
  19. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/main.py +0 -0
  20. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/resources/__init__.py +0 -0
  21. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier/resources/python.png +0 -0
  22. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier.egg-info/dependency_links.txt +0 -0
  23. {desktop-notifier-3.5.6 → desktop_notifier-3.5.7.dev1}/src/desktop_notifier.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: desktop-notifier
3
- Version: 3.5.6
3
+ Version: 3.5.7.dev1
4
4
  Summary: Python library for cross-platform desktop notifications
5
5
  Author-email: Sam Schott <sam.schott@outlook.com>
6
6
  License: MIT
@@ -19,9 +19,29 @@ Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Requires-Python: >=3.7
21
21
  Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: packaging
24
+ Requires-Dist: dbus-next; sys_platform == "linux"
25
+ Requires-Dist: rubicon-objc; sys_platform == "darwin"
26
+ Requires-Dist: winrt-windows.applicationmodel.core; sys_platform == "win32"
27
+ Requires-Dist: winrt-windows.data.xml.dom; sys_platform == "win32"
28
+ Requires-Dist: winrt-windows.foundation; sys_platform == "win32"
29
+ Requires-Dist: winrt-windows.foundation.collections; sys_platform == "win32"
30
+ Requires-Dist: winrt-windows.foundation.interop; sys_platform == "win32"
31
+ Requires-Dist: winrt-windows.ui.notifications; sys_platform == "win32"
22
32
  Provides-Extra: dev
33
+ Requires-Dist: black; extra == "dev"
34
+ Requires-Dist: bump2version; extra == "dev"
35
+ Requires-Dist: flake8; extra == "dev"
36
+ Requires-Dist: flake8-pyproject; extra == "dev"
37
+ Requires-Dist: mypy; extra == "dev"
38
+ Requires-Dist: pytest; extra == "dev"
39
+ Requires-Dist: pytest-cov; extra == "dev"
23
40
  Provides-Extra: docs
24
- License-File: LICENSE
41
+ Requires-Dist: furo==2024.4.27; extra == "docs"
42
+ Requires-Dist: sphinx==7.3.7; extra == "docs"
43
+ Requires-Dist: sphinx-autoapi==3.0.0; extra == "docs"
44
+ Requires-Dist: sphinx-mdinclude==0.6.0; extra == "docs"
25
45
 
26
46
  [![PyPi Release](https://img.shields.io/pypi/v/desktop-notifier.svg)](https://pypi.org/project/desktop-notifier/)
27
47
  [![Pyversions](https://img.shields.io/pypi/pyversions/desktop-notifier.svg)](https://pypi.org/pypi/desktop-notifier/)
@@ -34,7 +54,7 @@ Currently supported platforms are:
34
54
 
35
55
  * Linux via the dbus service org.freedesktop.Notifications
36
56
  * macOS and iOS via the Notification Center framework
37
- * [**exprimental**] Windows via the WinRT / Python bridge.
57
+ * [**experimental**] Windows via the WinRT / Python bridge.
38
58
 
39
59
  ![gif](screenshots/macOS.gif)
40
60
 
@@ -9,7 +9,7 @@ Currently supported platforms are:
9
9
 
10
10
  * Linux via the dbus service org.freedesktop.Notifications
11
11
  * macOS and iOS via the Notification Center framework
12
- * [**exprimental**] Windows via the WinRT / Python bridge.
12
+ * [**experimental**] Windows via the WinRT / Python bridge.
13
13
 
14
14
  ![gif](screenshots/macOS.gif)
15
15
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "desktop-notifier"
7
- version = "3.5.6"
7
+ version = "3.5.7.dev1"
8
8
  authors = [{name = "Sam Schott", email = "sam.schott@outlook.com"}]
9
9
  license = {text = "MIT"}
10
10
  description = "Python library for cross-platform desktop notifications"
@@ -27,7 +27,12 @@ dependencies = [
27
27
  "packaging",
28
28
  "dbus-next;sys_platform=='linux'",
29
29
  "rubicon-objc;sys_platform=='darwin'",
30
- "winsdk==1.0.0b9;sys_platform=='win32'",
30
+ "winrt-windows.applicationmodel.core;sys_platform=='win32'",
31
+ "winrt-windows.data.xml.dom;sys_platform=='win32'",
32
+ "winrt-windows.foundation;sys_platform=='win32'",
33
+ "winrt-windows.foundation.collections;sys_platform=='win32'",
34
+ "winrt-windows.foundation.interop;sys_platform=='win32'",
35
+ "winrt-windows.ui.notifications;sys_platform=='win32'",
31
36
  ]
32
37
 
33
38
  [project.readme]
@@ -44,15 +49,14 @@ dev = [
44
49
  "flake8",
45
50
  "flake8-pyproject",
46
51
  "mypy",
47
- "pre-commit",
48
52
  "pytest",
49
53
  "pytest-cov",
50
54
  ]
51
55
  docs = [
52
- "furo==2023.5.20",
53
- "sphinx==7.0.1",
54
- "sphinx-autoapi==2.1.1",
55
- "sphinx-mdinclude==0.5.3",
56
+ "furo==2024.4.27",
57
+ "sphinx==7.3.7",
58
+ "sphinx-autoapi==3.0.0",
59
+ "sphinx-mdinclude==0.6.0",
56
60
  ]
57
61
 
58
62
  [tool.setuptools.package-data]
@@ -2,7 +2,7 @@
2
2
  from .main import DesktopNotifier, Button, ReplyField, Notification, Urgency
3
3
 
4
4
 
5
- __version__ = "3.5.6"
5
+ __version__ = "3.5.7.dev1"
6
6
  __author__ = "Sam Schott"
7
7
  __url__ = "https://github.com/samschott/desktop-notifier"
8
8
 
@@ -8,6 +8,7 @@ from __future__ import annotations
8
8
 
9
9
  # system imports
10
10
  import logging
11
+ import platform
11
12
  from enum import Enum
12
13
  from collections import deque
13
14
  from pathlib import Path
@@ -136,7 +137,10 @@ class Notification:
136
137
  thread: str | None = None,
137
138
  timeout: int = -1,
138
139
  ) -> None:
139
- self._identifier: str | int | None = None
140
+ self._winrt_identifier = ""
141
+ self._macos_identifier = ""
142
+ self._dbus_identifier = 0
143
+
140
144
  self.title = title
141
145
  self.message = message
142
146
  self.urgency = urgency
@@ -151,17 +155,18 @@ class Notification:
151
155
  self.timeout = timeout
152
156
 
153
157
  @property
154
- def identifier(self) -> str | int | None:
155
- """
156
- An platform identifier which gets assigned to the notification after it was
157
- sent. This may be a str or int.
158
- """
159
- return self._identifier
160
-
161
- @identifier.setter
162
- def identifier(self, value: str | int | None) -> None:
163
- """Setter: identifier"""
164
- self._identifier = value
158
+ def identifier(self) -> str:
159
+ if platform.system() == "Darwin":
160
+ return self._macos_identifier
161
+ elif platform.system() == "Linux":
162
+ if self._dbus_identifier == 0:
163
+ return ""
164
+ else:
165
+ return str(self._dbus_identifier)
166
+ elif platform.system() == "Windows":
167
+ return self._winrt_identifier
168
+ else:
169
+ raise RuntimeError(f"Unsupported platform {platform.system()}")
165
170
 
166
171
  def __repr__(self) -> str:
167
172
  return f"<{self.__class__.__name__}(title='{self.title}', message='{self.message}')>"
@@ -217,7 +222,7 @@ class DesktopNotifierBase:
217
222
  notification_to_replace = None
218
223
 
219
224
  try:
220
- platform_nid = await self._send(notification, notification_to_replace)
225
+ await self._send(notification, notification_to_replace)
221
226
  except Exception:
222
227
  # Notifications can fail for many reasons:
223
228
  # The dbus service may not be available, we might be in a headless session,
@@ -227,9 +232,8 @@ class DesktopNotifierBase:
227
232
  self._current_notifications.appendleft(notification_to_replace)
228
233
  logger.warning("Notification failed", exc_info=True)
229
234
  else:
230
- notification.identifier = platform_nid
231
235
  self._current_notifications.append(notification)
232
- self._notification_for_nid[platform_nid] = notification
236
+ self._notification_for_nid[notification.identifier] = notification
233
237
 
234
238
  def _clear_notification_from_cache(self, notification: Notification) -> None:
235
239
  """
@@ -251,7 +255,7 @@ class DesktopNotifierBase:
251
255
  self,
252
256
  notification: Notification,
253
257
  notification_to_replace: Notification | None,
254
- ) -> str | int:
258
+ ) -> None:
255
259
  """
256
260
  Method to send a notification via the platform. This should be implemented by
257
261
  subclasses.
@@ -9,11 +9,12 @@ from __future__ import annotations
9
9
 
10
10
  # system imports
11
11
  import logging
12
- from typing import TypeVar, cast
12
+ from typing import TypeVar
13
13
 
14
14
  # external imports
15
- from dbus_next import Variant
16
- from dbus_next.aio import MessageBus, ProxyInterface
15
+ from dbus_next.signature import Variant
16
+ from dbus_next.aio.message_bus import MessageBus
17
+ from dbus_next.aio.proxy_object import ProxyInterface
17
18
 
18
19
  # local imports
19
20
  from .base import Notification, DesktopNotifierBase, Urgency
@@ -39,9 +40,6 @@ class DBusDesktopNotifier(DesktopNotifierBase):
39
40
 
40
41
  :param app_name: The name of the app. If it matches the application name in an
41
42
  existing desktop entry, the icon from that entry will be used by default.
42
- :param app_icon: The default icon to use for notifications. Will take precedence
43
- over any icon from the desktop file. Should be a URI or a name in a
44
- freedesktop.org-compliant icon theme.
45
43
  :param notification_limit: Maximum number of notifications to keep in the system's
46
44
  notification center.
47
45
  """
@@ -89,7 +87,6 @@ class DBusDesktopNotifier(DesktopNotifierBase):
89
87
  )
90
88
 
91
89
  # Some older interfaces may not support notification actions.
92
-
93
90
  if hasattr(self.interface, "on_notification_closed"):
94
91
  self.interface.on_notification_closed(self._on_closed)
95
92
 
@@ -102,7 +99,7 @@ class DBusDesktopNotifier(DesktopNotifierBase):
102
99
  self,
103
100
  notification: Notification,
104
101
  notification_to_replace: Notification | None,
105
- ) -> int:
102
+ ) -> None:
106
103
  """
107
104
  Asynchronously sends a notification via the Dbus interface.
108
105
 
@@ -113,11 +110,10 @@ class DBusDesktopNotifier(DesktopNotifierBase):
113
110
  self.interface = await self._init_dbus()
114
111
 
115
112
  if notification_to_replace:
116
- replaces_nid = notification_to_replace.identifier
113
+ replaces_nid = notification_to_replace._dbus_identifier
117
114
  else:
118
115
  replaces_nid = 0
119
116
 
120
- # Create list of actions for a user interacting with the notification.
121
117
  actions = []
122
118
 
123
119
  if notification.on_clicked:
@@ -134,51 +130,53 @@ class DBusDesktopNotifier(DesktopNotifierBase):
134
130
 
135
131
  hints = {"urgency": self._to_native_urgency[notification.urgency]}
136
132
 
137
- # sound
138
133
  if notification.sound:
139
134
  hints["sound-name"] = Variant("s", "message-new-instant")
140
135
 
141
- # attachment
142
136
  if notification.attachment:
143
137
  hints["image-path"] = Variant("s", notification.attachment)
144
138
 
145
- # get the timeout in ms
146
139
  timeout = notification.timeout * 1000 if notification.timeout != -1 else -1
147
140
 
148
- # Post the new notification and record the platform ID assigned to it.
149
- platform_nid = await self.interface.call_notify(
150
- self.app_name, # app_name
151
- replaces_nid, # replaces_id
152
- notification.icon or "", # app_icon
153
- notification.title, # summary
154
- notification.message, # body
155
- actions, # actions
156
- hints, # hints
157
- timeout, # expire_timeout (-1 = default)
158
- )
159
-
160
- return cast(int, platform_nid)
141
+ # dbus_next proxy APIs are generated at runtime.
142
+ if hasattr(self.interface, "call_notify"):
143
+ platform_nid = await self.interface.call_notify(
144
+ self.app_name,
145
+ replaces_nid,
146
+ notification.icon or "",
147
+ notification.title,
148
+ notification.message,
149
+ actions,
150
+ hints,
151
+ timeout,
152
+ )
153
+
154
+ notification._dbus_identifier = platform_nid
161
155
 
162
156
  async def _clear(self, notification: Notification) -> None:
163
157
  """
164
158
  Asynchronously removes a notification from the notification center
165
159
  """
166
-
167
160
  if not self.interface:
168
161
  return
169
162
 
170
- await self.interface.call_close_notification(notification.identifier)
163
+ # dbus_next proxy APIs are generated at runtime.
164
+ if hasattr(self.interface, "call_close_notification"):
165
+ await self.interface.call_close_notification(notification._dbus_identifier)
171
166
 
172
167
  async def _clear_all(self) -> None:
173
168
  """
174
169
  Asynchronously clears all notifications from notification center
175
170
  """
176
-
177
171
  if not self.interface:
178
172
  return
179
173
 
180
- for notification in self.current_notifications:
181
- await self.interface.call_close_notification(notification.identifier)
174
+ # dbus_next proxy APIs are generated at runtime.
175
+ if hasattr(self.interface, "call_close_notification"):
176
+ for notification in self.current_notifications:
177
+ await self.interface.call_close_notification(
178
+ notification._dbus_identifier
179
+ )
182
180
 
183
181
  # Note that _on_action and _on_closed might be called for the same notification
184
182
  # with some notification servers. This is not a problem because the _on_action
@@ -5,9 +5,6 @@ Dummy backend for unsupported platforms.
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
- # system imports
9
- import uuid
10
-
11
8
  # local imports
12
9
  from .base import Notification, DesktopNotifierBase
13
10
 
@@ -40,11 +37,8 @@ class DummyNotificationCenter(DesktopNotifierBase):
40
37
  self,
41
38
  notification: Notification,
42
39
  notification_to_replace: Notification | None,
43
- ) -> str:
44
- if notification_to_replace:
45
- return str(notification_to_replace.identifier)
46
- else:
47
- return str(uuid.uuid4())
40
+ ) -> None:
41
+ pass
48
42
 
49
43
  async def _clear(self, notification: Notification) -> None:
50
44
  pass
@@ -227,7 +227,7 @@ class CocoaNotificationCenter(DesktopNotifierBase):
227
227
  self,
228
228
  notification: Notification,
229
229
  notification_to_replace: Optional[Notification],
230
- ) -> str:
230
+ ) -> None:
231
231
  """
232
232
  Uses UNUserNotificationCenter to schedule a notification.
233
233
 
@@ -236,7 +236,7 @@ class CocoaNotificationCenter(DesktopNotifierBase):
236
236
  """
237
237
 
238
238
  if notification_to_replace:
239
- platform_nid = str(notification_to_replace.identifier)
239
+ platform_nid = notification_to_replace._macos_identifier
240
240
  else:
241
241
  platform_nid = str(uuid.uuid4())
242
242
 
@@ -307,7 +307,7 @@ class CocoaNotificationCenter(DesktopNotifierBase):
307
307
  else:
308
308
  raise RuntimeError(error.localizedDescription) # type:ignore
309
309
 
310
- return platform_nid
310
+ notification._macos_identifier = platform_nid
311
311
 
312
312
  async def _create_category_for_notification(
313
313
  self, notification: Notification
@@ -396,7 +396,9 @@ class CocoaNotificationCenter(DesktopNotifierBase):
396
396
 
397
397
  :param notification: Notification to clear.
398
398
  """
399
- self.nc.removeDeliveredNotificationsWithIdentifiers([notification.identifier])
399
+ self.nc.removeDeliveredNotificationsWithIdentifiers(
400
+ [notification._macos_identifier]
401
+ )
400
402
 
401
403
  async def _clear_all(self) -> None:
402
404
  """
@@ -114,7 +114,7 @@ class CocoaNotificationCenterLegacy(DesktopNotifierBase):
114
114
  self,
115
115
  notification: Notification,
116
116
  notification_to_replace: Optional[Notification],
117
- ) -> str:
117
+ ) -> None:
118
118
  """
119
119
  Uses NSUserNotificationCenter to schedule a notification.
120
120
 
@@ -122,7 +122,7 @@ class CocoaNotificationCenterLegacy(DesktopNotifierBase):
122
122
  :param notification_to_replace: Notification to replace, if any.
123
123
  """
124
124
  if notification_to_replace:
125
- platform_nid = str(notification_to_replace.identifier)
125
+ platform_nid = notification_to_replace._macos_identifier
126
126
  else:
127
127
  platform_nid = str(uuid.uuid4())
128
128
 
@@ -148,7 +148,7 @@ class CocoaNotificationCenterLegacy(DesktopNotifierBase):
148
148
 
149
149
  self.nc.scheduleNotification(n)
150
150
 
151
- return platform_nid
151
+ notification._macos_identifier = platform_nid
152
152
 
153
153
  async def _clear(self, notification: Notification) -> None:
154
154
  """
@@ -10,25 +10,28 @@ Microsoft (https://github.com/microsoft/xlang, https://pypi.org/project/winrt/).
10
10
  from __future__ import annotations
11
11
 
12
12
  # system imports
13
+ import sys
13
14
  import uuid
14
15
  import logging
15
16
  from xml.etree.ElementTree import Element, SubElement, tostring
16
- from typing import TypeVar, Any, cast
17
+ from typing import TypeVar
17
18
 
18
19
  # external imports
19
20
  import winreg
20
- from winsdk.windows.ui.notifications import (
21
+ from winrt.windows.foundation.interop import unbox
22
+ from winrt.windows.ui.notifications import (
21
23
  ToastNotificationManager,
22
24
  ToastNotificationPriority,
23
25
  NotificationSetting,
24
26
  ToastNotification,
25
27
  ToastActivatedEventArgs,
26
28
  ToastDismissalReason,
29
+ ToastDismissedEventArgs,
30
+ ToastFailedEventArgs,
27
31
  )
28
- from winsdk.windows.data.xml import dom
29
- from winsdk.windows.applicationmodel.core import CoreApplication
30
- from winsdk.windows.foundation import IPropertyValue, PropertyType
31
- import winsdk._winrt as _winrt
32
+ from winrt.windows.data.xml.dom import XmlDocument
33
+ from winrt.windows.applicationmodel.core import CoreApplication
34
+ from winrt.system import Object as WinRTObject
32
35
 
33
36
  # local imports
34
37
  from .base import Notification, DesktopNotifierBase, Urgency
@@ -42,14 +45,14 @@ T = TypeVar("T")
42
45
 
43
46
 
44
47
  def register_hkey(app_id: str, app_name: str) -> None:
45
- winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) # type:ignore
48
+ # mypy type guard
49
+ if not sys.platform == "win32":
50
+ return
51
+
52
+ winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
46
53
  key_path = f"SOFTWARE\\Classes\\AppUserModelId\\{app_id}"
47
- with winreg.CreateKeyEx( # type:ignore
48
- winreg.HKEY_CURRENT_USER, key_path # type:ignore
49
- ) as master_key:
50
- winreg.SetValueEx( # type:ignore
51
- master_key, "DisplayName", 0, winreg.REG_SZ, app_name # type:ignore
52
- )
54
+ with winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, key_path) as master_key:
55
+ winreg.SetValueEx(master_key, "DisplayName", 0, winreg.REG_SZ, app_name)
53
56
 
54
57
 
55
58
  class WinRTDesktopNotifier(DesktopNotifierBase):
@@ -78,7 +81,13 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
78
81
  notification_limit: int | None = None,
79
82
  ) -> None:
80
83
  super().__init__(app_name, notification_limit)
81
- self.manager = ToastNotificationManager.get_default()
84
+
85
+ manager = ToastNotificationManager.get_default()
86
+
87
+ if not manager:
88
+ raise RuntimeError("Could not get ToastNotificationManagerForUser")
89
+
90
+ self.manager = manager
82
91
 
83
92
  # Prefer using the real App ID if detected, fall back to user-provided name
84
93
  # and icon otherwise.
@@ -86,8 +95,14 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
86
95
  self.app_id = CoreApplication.id
87
96
  else:
88
97
  self.app_id = app_name
89
- register_hkey(app_name, app_name)
90
- self.notifier = self.manager.create_toast_notifier(self.app_id)
98
+ register_hkey(app_id=app_name, app_name=app_name)
99
+
100
+ notifier = self.manager.create_toast_notifier(self.app_id)
101
+
102
+ if not notifier:
103
+ raise RuntimeError(f"Could not get ToastNotifier for app_id: {self.app_id}")
104
+
105
+ self.notifier = notifier
91
106
 
92
107
  async def request_authorisation(self) -> bool:
93
108
  """
@@ -95,19 +110,23 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
95
110
 
96
111
  :returns: Whether authorisation has been granted.
97
112
  """
98
- return bool(self.notifier.setting == NotificationSetting.ENABLED)
113
+ return await self.has_authorisation()
99
114
 
100
115
  async def has_authorisation(self) -> bool:
101
116
  """
102
117
  Whether we have authorisation to send notifications.
103
118
  """
104
- return bool(self.notifier.setting == NotificationSetting.ENABLED)
119
+ try:
120
+ return bool(self.notifier.setting == NotificationSetting.ENABLED)
121
+ except OSError:
122
+ # See https://github.com/samschott/desktop-notifier/issues/95.
123
+ return True
105
124
 
106
125
  async def _send(
107
126
  self,
108
127
  notification: Notification,
109
128
  notification_to_replace: Notification | None,
110
- ) -> str:
129
+ ) -> None:
111
130
  """
112
131
  Asynchronously sends a notification.
113
132
 
@@ -115,7 +134,7 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
115
134
  :param notification_to_replace: Notification to replace, if any.
116
135
  """
117
136
  if notification_to_replace:
118
- platform_nid = cast(str, notification_to_replace.identifier)
137
+ platform_nid = notification_to_replace._winrt_identifier
119
138
  else:
120
139
  platform_nid = str(uuid.uuid4())
121
140
 
@@ -197,26 +216,39 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
197
216
  else:
198
217
  SubElement(toast_xml, "audio", {"silent": "true"})
199
218
 
200
- xml_document = dom.XmlDocument()
219
+ xml_document = XmlDocument()
201
220
  xml_document.load_xml(tostring(toast_xml, encoding="unicode"))
202
221
 
203
222
  native = ToastNotification(xml_document)
204
223
  native.tag = platform_nid
205
224
  native.priority = self._to_native_urgency[notification.urgency]
206
225
 
207
- def on_activated(sender, boxed_activated_args) -> None: # type:ignore
208
- activated_args = ToastActivatedEventArgs._from(boxed_activated_args)
209
- action_id = cast(str, activated_args.arguments)
226
+ def on_activated(
227
+ sender: ToastNotification | None, boxed_activated_args: WinRTObject | None
228
+ ) -> None:
229
+ if not sender or not boxed_activated_args:
230
+ return
231
+
232
+ try:
233
+ activated_args = ToastActivatedEventArgs._from(boxed_activated_args)
234
+ except Exception:
235
+ return
236
+
237
+ action_id = activated_args.arguments
210
238
 
211
239
  if action_id == WinRTDesktopNotifier.DEFAULT_ACTION:
212
240
  if notification.on_clicked:
213
241
  notification.on_clicked()
214
242
  elif action_id == WinRTDesktopNotifier.REPLY_ACTION:
215
- if notification.reply_field and notification.reply_field.on_replied:
243
+ if (
244
+ notification.reply_field
245
+ and notification.reply_field.on_replied
246
+ and activated_args.user_input
247
+ ):
216
248
  boxed_text = activated_args.user_input[
217
249
  WinRTDesktopNotifier.REPLY_TEXTBOX_NAME
218
250
  ]
219
- text = unbox_winrt(boxed_text)
251
+ text = unbox(boxed_text)
220
252
  notification.reply_field.on_replied(text)
221
253
  elif action_id.startswith(WinRTDesktopNotifier.BUTTON_ACTION_PREFIX):
222
254
  action_number_str = action_id.replace(
@@ -227,17 +259,28 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
227
259
  if callback:
228
260
  callback()
229
261
 
230
- def on_dismissed(sender, dismissed_args) -> None: # type:ignore
262
+ def on_dismissed(
263
+ sender: ToastNotification | None,
264
+ dismissed_args: ToastDismissedEventArgs | None,
265
+ ) -> None:
231
266
  self._clear_notification_from_cache(notification)
232
267
 
233
- if dismissed_args.reason == ToastDismissalReason.USER_CANCELED:
268
+ if (
269
+ dismissed_args
270
+ and dismissed_args.reason == ToastDismissalReason.USER_CANCELED
271
+ ):
234
272
  if notification.on_dismissed:
235
273
  notification.on_dismissed()
236
274
 
237
- def on_failed(sender, failed_args) -> None: # type:ignore
238
- logger.warning(
239
- f"Notification failed (error code {failed_args.error_code.value})"
240
- )
275
+ def on_failed(
276
+ sender: ToastNotification | None, failed_args: ToastFailedEventArgs | None
277
+ ) -> None:
278
+ if failed_args:
279
+ logger.warning(
280
+ f"Notification failed (error code {failed_args.error_code.value})"
281
+ )
282
+ else:
283
+ logger.warning("Notification failed (unknown error code)")
241
284
 
242
285
  native.add_activated(on_activated)
243
286
  native.add_dismissed(on_dismissed)
@@ -245,39 +288,18 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
245
288
 
246
289
  self.notifier.show(native)
247
290
 
248
- return platform_nid
291
+ notification._winrt_identifier = platform_nid
249
292
 
250
293
  async def _clear(self, notification: Notification) -> None:
251
294
  """
252
295
  Asynchronously removes a notification from the notification center.
253
296
  """
254
- self.manager.history.remove(notification.identifier)
297
+ if self.manager.history:
298
+ self.manager.history.remove(notification._winrt_identifier)
255
299
 
256
300
  async def _clear_all(self) -> None:
257
301
  """
258
302
  Asynchronously clears all notifications from notification center.
259
303
  """
260
- self.manager.history.clear(self.app_id)
261
-
262
-
263
- def unbox_winrt(boxed_value: _winrt.Object) -> Any:
264
- """
265
- Unbox winrt object. See https://github.com/pywinrt/pywinrt/issues/8.
266
- """
267
- if boxed_value is None:
268
- return boxed_value
269
-
270
- value = IPropertyValue._from(boxed_value)
271
-
272
- if value.type is PropertyType.EMPTY:
273
- return None
274
- elif value.type is PropertyType.UINT8:
275
- return value.get_uint8()
276
- elif value.type is PropertyType.INT16:
277
- return value.get_int16()
278
- elif value.type is PropertyType.UINT16:
279
- return value.get_uint16()
280
- elif value.type is PropertyType.STRING:
281
- return value.get_string()
282
- else:
283
- raise NotImplementedError(f"Unboxing {value.type} is not yet supported")
304
+ if self.manager.history:
305
+ self.manager.history.clear(self.app_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: desktop-notifier
3
- Version: 3.5.6
3
+ Version: 3.5.7.dev1
4
4
  Summary: Python library for cross-platform desktop notifications
5
5
  Author-email: Sam Schott <sam.schott@outlook.com>
6
6
  License: MIT
@@ -19,9 +19,29 @@ Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Requires-Python: >=3.7
21
21
  Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: packaging
24
+ Requires-Dist: dbus-next; sys_platform == "linux"
25
+ Requires-Dist: rubicon-objc; sys_platform == "darwin"
26
+ Requires-Dist: winrt-windows.applicationmodel.core; sys_platform == "win32"
27
+ Requires-Dist: winrt-windows.data.xml.dom; sys_platform == "win32"
28
+ Requires-Dist: winrt-windows.foundation; sys_platform == "win32"
29
+ Requires-Dist: winrt-windows.foundation.collections; sys_platform == "win32"
30
+ Requires-Dist: winrt-windows.foundation.interop; sys_platform == "win32"
31
+ Requires-Dist: winrt-windows.ui.notifications; sys_platform == "win32"
22
32
  Provides-Extra: dev
33
+ Requires-Dist: black; extra == "dev"
34
+ Requires-Dist: bump2version; extra == "dev"
35
+ Requires-Dist: flake8; extra == "dev"
36
+ Requires-Dist: flake8-pyproject; extra == "dev"
37
+ Requires-Dist: mypy; extra == "dev"
38
+ Requires-Dist: pytest; extra == "dev"
39
+ Requires-Dist: pytest-cov; extra == "dev"
23
40
  Provides-Extra: docs
24
- License-File: LICENSE
41
+ Requires-Dist: furo==2024.4.27; extra == "docs"
42
+ Requires-Dist: sphinx==7.3.7; extra == "docs"
43
+ Requires-Dist: sphinx-autoapi==3.0.0; extra == "docs"
44
+ Requires-Dist: sphinx-mdinclude==0.6.0; extra == "docs"
25
45
 
26
46
  [![PyPi Release](https://img.shields.io/pypi/v/desktop-notifier.svg)](https://pypi.org/project/desktop-notifier/)
27
47
  [![Pyversions](https://img.shields.io/pypi/pyversions/desktop-notifier.svg)](https://pypi.org/pypi/desktop-notifier/)
@@ -34,7 +54,7 @@ Currently supported platforms are:
34
54
 
35
55
  * Linux via the dbus service org.freedesktop.Notifications
36
56
  * macOS and iOS via the Notification Center framework
37
- * [**exprimental**] Windows via the WinRT / Python bridge.
57
+ * [**experimental**] Windows via the WinRT / Python bridge.
38
58
 
39
59
  ![gif](screenshots/macOS.gif)
40
60
 
@@ -9,6 +9,7 @@ src/desktop_notifier/macos.py
9
9
  src/desktop_notifier/macos_legacy.py
10
10
  src/desktop_notifier/macos_support.py
11
11
  src/desktop_notifier/main.py
12
+ src/desktop_notifier/py.typed
12
13
  src/desktop_notifier/winrt.py
13
14
  src/desktop_notifier.egg-info/PKG-INFO
14
15
  src/desktop_notifier.egg-info/SOURCES.txt
@@ -0,0 +1,30 @@
1
+ packaging
2
+
3
+ [:sys_platform == "darwin"]
4
+ rubicon-objc
5
+
6
+ [:sys_platform == "linux"]
7
+ dbus-next
8
+
9
+ [:sys_platform == "win32"]
10
+ winrt-windows.applicationmodel.core
11
+ winrt-windows.data.xml.dom
12
+ winrt-windows.foundation
13
+ winrt-windows.foundation.collections
14
+ winrt-windows.foundation.interop
15
+ winrt-windows.ui.notifications
16
+
17
+ [dev]
18
+ black
19
+ bump2version
20
+ flake8
21
+ flake8-pyproject
22
+ mypy
23
+ pytest
24
+ pytest-cov
25
+
26
+ [docs]
27
+ furo==2024.4.27
28
+ sphinx==7.3.7
29
+ sphinx-autoapi==3.0.0
30
+ sphinx-mdinclude==0.6.0
@@ -1,26 +0,0 @@
1
- packaging
2
-
3
- [:sys_platform == "darwin"]
4
- rubicon-objc
5
-
6
- [:sys_platform == "linux"]
7
- dbus-next
8
-
9
- [:sys_platform == "win32"]
10
- winsdk==1.0.0b9
11
-
12
- [dev]
13
- black
14
- bump2version
15
- flake8
16
- flake8-pyproject
17
- mypy
18
- pre-commit
19
- pytest
20
- pytest-cov
21
-
22
- [docs]
23
- furo==2023.5.20
24
- sphinx==7.0.1
25
- sphinx-autoapi==2.1.1
26
- sphinx-mdinclude==0.5.3