From 05f66d40f36a9f0050e65817e3c390b6e613bbf4 Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Sat, 26 Dec 2020 16:42:56 +0300 Subject: [PATCH 1/3] Show Album Art with UserNotification. --- Application/PlaybackEventController.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Application/PlaybackEventController.m b/Application/PlaybackEventController.m index 64f02741e..06c0e79a9 100644 --- a/Application/PlaybackEventController.m +++ b/Application/PlaybackEventController.m @@ -174,6 +174,32 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response content.sound = nil; content.categoryIdentifier = @"play"; + if ([defaults boolForKey:@"notifications.show-album-art"] && [pe albumArtInternal]) { + NSError *error = nil; + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *tmpSubFolderName = [NSProcessInfo.processInfo globallyUniqueString]; + NSURL *tmpSubFolderURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] + URLByAppendingPathComponent:tmpSubFolderName isDirectory:true]; + if ([fileManager createDirectoryAtPath:[tmpSubFolderURL path] + withIntermediateDirectories:true + attributes:nil + error:&error]) { + NSURL *fileURL = [tmpSubFolderURL URLByAppendingPathComponent:@"art.png"]; + NSImage *image = [pe albumArt]; + CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil]; + NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef]; + [newRep setSize:[image size]]; + NSData *pngData = [newRep representationUsingType:NSBitmapImageFileTypePNG properties:@{}]; + [pngData writeToURL:fileURL atomically:YES]; + + UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"art" + URL:fileURL + options:nil + error:&error]; + content.attachments = @[icon]; + } + } + UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"PlayTrack" content:content trigger:nil]; [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { From bd4e64c029fa62754cb6dee3dc860c45dd35a775 Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Sat, 26 Dec 2020 16:44:08 +0300 Subject: [PATCH 2/3] Do not show iTunes Style option with UserNotification. --- Preferences/General/Base.lproj/Preferences.xib | 9 +++++---- Preferences/General/GeneralPreferencesPlugin.h | 2 ++ Preferences/General/GeneralPreferencesPlugin.m | 9 +++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Preferences/General/Base.lproj/Preferences.xib b/Preferences/General/Base.lproj/Preferences.xib index 2b9a6c667..59a8d00b3 100644 --- a/Preferences/General/Base.lproj/Preferences.xib +++ b/Preferences/General/Base.lproj/Preferences.xib @@ -11,6 +11,7 @@ + @@ -400,12 +401,12 @@ - +