Skip to content

Commit

Permalink
Don't show album cover on macOS Catalina (10.15)
Browse files Browse the repository at this point in the history
Buffer allocation currently results in a segmentation fault.
  • Loading branch information
PhilipTrauner committed Oct 13, 2019
1 parent 1ef5bf3 commit 269b316
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions cmus_osx/payload/notify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from io import BytesIO
from os.path import isfile
from platform import mac_ver
from subprocess import call

from AppKit import NSBitmapImageRep
Expand Down Expand Up @@ -103,27 +104,31 @@ def exception_hook(exc_type, exc_value, exc_traceback):
notification.setSubtitle_(subtitle)
notification.setInformativeText_(message)

if cover is not None: # the song has an embedded cover image
data = NSData.alloc().initWithBytes_length_(cover, len(cover))
image_rep = NSBitmapImageRep.alloc().initWithData_(data)

# CGImageGetWidth started returning bogus values in macOS 10.14 ->
# Use Pillow to extract the image dimensions
size = NSMakeSize(*Image.open(BytesIO(cover)).size)

image = NSImage.alloc().initWithSize_(size)
image.addRepresentation_(image_rep)
if env.itunes_style_notification:
notification.setValue_forKey_(image, "_identityImage")
else:
# To-Do: Data allocation currently doesn't work in Catalina
if mac_ver()[0] != "10.15":
if cover is not None: # the song has an embedded cover image
data = NSData.alloc().initWithBytes_length_(cover, len(cover))
image_rep = NSBitmapImageRep.alloc().initWithData_(data)

# CGImageGetWidth started returning bogus values in macOS 10.14 ->
# Use Pillow to extract the image dimensions
size = NSMakeSize(*Image.open(BytesIO(cover)).size)

image = NSImage.alloc().initWithSize_(size)
image.addRepresentation_(image_rep)
if env.itunes_style_notification:

notification.setValue_forKey_(image, "_identityImage")
else:
notification.setValue_forKey_(
NSImage.alloc().initByReferencingFile_(str(env.app_icon)),
"_identityImage",
)
notification.setContentImage_(image)
else: # song has no cover image, show an icon
notification.setValue_forKey_(
NSImage.alloc().initByReferencingFile_(str(env.app_icon)), "_identityImage"
)
notification.setContentImage_(image)
else: # song has no cover image, show an icon
notification.setValue_forKey_(
NSImage.alloc().initByReferencingFile_(str(env.app_icon)), "_identityImage"
)

center.removeAllDeliveredNotifications()

Expand Down

0 comments on commit 269b316

Please sign in to comment.