mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 00:44:00 +01:00
OS X Notification fix
This commit is contained in:
+16
-7
@@ -732,23 +732,32 @@ class OSX_NOTIFY(object):
|
|||||||
self.objc = __import__("objc")
|
self.objc = __import__("objc")
|
||||||
self.AppKit = __import__("AppKit")
|
self.AppKit = __import__("AppKit")
|
||||||
except:
|
except:
|
||||||
|
logger.warn('OS X Notification: Cannot import objc or AppKit')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def swizzle(self, cls, SEL, func):
|
def swizzle(self, cls, SEL, func):
|
||||||
old_IMP = cls.instanceMethodForSelector_(SEL)
|
old_IMP = getattr(cls, SEL, None)
|
||||||
|
if old_IMP is None:
|
||||||
|
old_IMP = cls.instanceMethodForSelector_(SEL)
|
||||||
|
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
return func(self, old_IMP, *args, **kwargs)
|
return func(self, old_IMP, *args, **kwargs)
|
||||||
new_IMP = self.objc.selector(wrapper, selector=old_IMP.selector,
|
|
||||||
signature=old_IMP.signature)
|
new_IMP = self.objc.selector(
|
||||||
self.objc.classAddMethod(cls, SEL, new_IMP)
|
wrapper,
|
||||||
|
selector=old_IMP.selector,
|
||||||
|
signature=old_IMP.signature
|
||||||
|
)
|
||||||
|
self.objc.classAddMethod(cls, SEL.encode(), new_IMP)
|
||||||
|
|
||||||
def notify(self, title, subtitle=None, text=None, sound=True, image=None):
|
def notify(self, title, subtitle=None, text=None, sound=True, image=None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.swizzle(self.objc.lookUpClass('NSBundle'),
|
self.swizzle(
|
||||||
b'bundleIdentifier',
|
self.objc.lookUpClass('NSBundle'),
|
||||||
self.swizzled_bundleIdentifier)
|
'bundleIdentifier',
|
||||||
|
self.swizzled_bundleIdentifier
|
||||||
|
)
|
||||||
|
|
||||||
NSUserNotification = self.objc.lookUpClass('NSUserNotification')
|
NSUserNotification = self.objc.lookUpClass('NSUserNotification')
|
||||||
NSUserNotificationCenter = self.objc.lookUpClass('NSUserNotificationCenter')
|
NSUserNotificationCenter = self.objc.lookUpClass('NSUserNotificationCenter')
|
||||||
|
|||||||
Reference in New Issue
Block a user