Support -open arg with terminal-notifier (macosx://) (#789)

pull/792/head
Chris Caron 2022-12-15 17:02:36 -05:00 committed by GitHub
parent 5e8a2d2f02
commit 48dd88df75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -121,9 +121,13 @@ class NotifyMacOSX(NotifyBase):
'name': _('Sound'),
'type': 'string',
},
'click': {
'name': _('Open/Click URL'),
'type': 'string',
},
})
def __init__(self, sound=None, include_image=True, **kwargs):
def __init__(self, sound=None, include_image=True, click=None, **kwargs):
"""
Initialize MacOSX Object
"""
@ -137,6 +141,10 @@ class NotifyMacOSX(NotifyBase):
self.notify_path = next( # pragma: no branch
(p for p in self.notify_paths if os.access(p, os.X_OK)), None)
# Click URL
# Allow user to provide the `--open` argument on the notify wrapper
self.click = click
# Set sound object (no q/a for now)
self.sound = sound
@ -162,6 +170,9 @@ class NotifyMacOSX(NotifyBase):
if title:
cmd.extend(['-title', title])
if self.click:
cmd.extend(['-open', self.click])
# The sound to play
if self.sound:
cmd.extend(['-sound', self.sound])
@ -203,6 +214,9 @@ class NotifyMacOSX(NotifyBase):
'image': 'yes' if self.include_image else 'no',
}
if self.click:
params['click'] = self.click
# Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
@ -230,6 +244,10 @@ class NotifyMacOSX(NotifyBase):
results['include_image'] = \
parse_bool(results['qsd'].get('image', True))
# Support 'click'
if 'click' in results['qsd'] and len(results['qsd']['click']):
results['click'] = NotifyMacOSX.unquote(results['qsd']['click'])
# Support 'sound'
if 'sound' in results['qsd'] and len(results['qsd']['sound']):
results['sound'] = NotifyMacOSX.unquote(results['qsd']['sound'])

View File

@ -126,6 +126,15 @@ def test_plugin_macosx_general_success(macos_notify_environment):
assert obj.notify(title='title', body='body',
notify_type=apprise.NotifyType.INFO) is True
# Test Click (-open support)
obj = apprise.Apprise.instantiate(
'macosx://_/?click=http://google.com', suppress_exceptions=False)
assert isinstance(obj, NotifyMacOSX) is True
assert obj.click == 'http://google.com'
assert isinstance(obj.url(), str) is True
assert obj.notify(title='title', body='body',
notify_type=apprise.NotifyType.INFO) is True
def test_plugin_macosx_terminal_notifier_not_executable(
pretend_macos, terminal_notifier):