Skip to content

Commit

Permalink
toast - Added mac support (#1642)
Browse files Browse the repository at this point in the history
* [add] toast - Added mac support

* Added url support

* Fixed message order
  • Loading branch information
liiight committed Jan 20, 2017
1 parent b168635 commit 1bffe7c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions flexget/plugins/notifiers/toast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals, division, absolute_import
import logging
import sys
import os

from flexget import plugin
from flexget.event import event
Expand All @@ -19,6 +20,7 @@ class NotifyToast(object):
'type': 'object',
'properties': {
'timeout': {'type': 'integer'},
'url': {'type': 'string'},
},
'additionalProperties': False
}
Expand All @@ -32,8 +34,30 @@ def prepare_config(self, config):
if not isinstance(config, dict):
config = {}
config.setdefault('timeout', 4)
config.setdefault('url', '')
return config

def mac_notify(self, title, message, config):
config = self.prepare_config(config)
try:
from pync import Notifier
except ImportError as e:
log.debug('Error importing pync: %s', e)
raise DependencyError(__name__, 'pync', 'pync module required. ImportError: %s' % e)

icon_path = None
try:
import flexget.ui
icon_path = os.path.join(flexget.ui.__path__[0], 'src', 'favicon.ico')
except Exception as e:
log.debug('Error trying to get flexget icon from webui folder: %s', e)

try:
Notifier.notify(message, subtitle=title, title='FlexGet Notification', appIcon=icon_path,
timeout=config['timeout'], open=config.get('url'))
except Exception as e:
raise PluginWarning('Cannot send a notification: %s' % e)

def linux_notify(self, title, message, config):
config = self.prepare_config(config)
try:
Expand Down Expand Up @@ -81,10 +105,10 @@ def windows_notify(self, title, message, config):
icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
try:
import flexget.ui
icon_path = flexget.ui.__path__[0] + '\\src\\favicon.ico'
icon_path = os.path.join(flexget.ui.__path__[0], 'src', 'favicon.ico')
hicon = LoadImage(hinst, icon_path, IMAGE_ICON, 0, 0, icon_flags)
except Exception as e:
logging.debug('Error trying to get flexget icon from webui folder: %s', e)
log.debug('Error trying to get flexget icon from webui folder: %s', e)

# Taskbar icon
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO
Expand All @@ -93,6 +117,8 @@ def windows_notify(self, title, message, config):

if sys.platform.startswith('win'):
notify = windows_notify
elif sys.platform == 'darwin':
notify = mac_notify
else:
notify = linux_notify

Expand Down

0 comments on commit 1bffe7c

Please sign in to comment.