Merge pull request #61 from nevack/nevack/notifications

Show album art with UserNotification api.
CQTexperiment
Christopher Snowhill 2021-01-06 23:22:15 -08:00 committed by GitHub
commit 1aa9b5a01c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 4 deletions

View File

@ -174,6 +174,37 @@ 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];
NSURL *tmpSubFolderURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()]
URLByAppendingPathComponent:@"cog-artworks-cache" isDirectory:true];
if ([fileManager createDirectoryAtPath:[tmpSubFolderURL path]
withIntermediateDirectories:true
attributes:nil
error:&error]) {
NSString *tmpFileName = [[NSProcessInfo.processInfo globallyUniqueString] stringByAppendingString:@".jpg"];
NSURL *fileURL = [tmpSubFolderURL URLByAppendingPathComponent:tmpFileName];
NSImage *image = [pe albumArt];
CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
NSData *jpgData = [newRep representationUsingType:NSBitmapImageFileTypeJPEG
properties:@{NSImageCompressionFactor: @0.5f}];
[jpgData writeToURL:fileURL atomically:YES];
UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"art"
URL:fileURL
options:nil
error:&error];
if (error) {
// We have size limit of 10MB per image attachment.
NSLog(@"%@", error.localizedDescription);
} else {
content.attachments = @[icon];
}
}
}
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"PlayTrack" content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {

View File

@ -11,6 +11,7 @@
<outlet property="appearanceView" destination="CgN-sy-RmM" id="wvB-aW-Gfx"/>
<outlet property="growlView" destination="U4w-jw-ca5" id="IUJ-gB-jwT"/>
<outlet property="hotKeyPane" destination="6" id="14"/>
<outlet property="iTunesStyleCheck" destination="AIz-WH-Wqk" id="2n1-pY-cZR"/>
<outlet property="midiPane" destination="i5B-ga-Atm" id="rbe-uK-5n2"/>
<outlet property="outputPane" destination="57" id="75"/>
<outlet property="playlistView" destination="231" id="244"/>
@ -400,12 +401,12 @@
<point key="canvasLocation" x="-78" y="-31.5"/>
</customView>
<customView id="U4w-jw-ca5" userLabel="GrowlView">
<rect key="frame" x="0.0" y="0.0" width="500" height="114"/>
<rect key="frame" x="0.0" y="0.0" width="500" height="94"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="njn-Xl-9k9">
<rect key="frame" x="18" y="78" width="158" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<rect key="frame" x="18" y="58" width="158" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Enable notifications" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="hqT-nY-NoU">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -415,7 +416,7 @@
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AIz-WH-Wqk">
<rect key="frame" x="18" y="58" width="131" height="18"/>
<rect key="frame" x="18" y="18" width="131" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Use iTunes style" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="cOb-hQ-7K8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>

View File

@ -25,6 +25,8 @@
IBOutlet NSView *growlView;
IBOutlet NSView *appearanceView;
IBOutlet NSView *midiView;
__weak IBOutlet NSButton *iTunesStyleCheck;
}
- (HotKeyPane *)hotKeyPane;

View File

@ -71,6 +71,15 @@
- (GeneralPreferencePane *)growlPane
{
if (@available(macOS 10.14, *)) {
if (iTunesStyleCheck) {
iTunesStyleCheck.hidden = YES;
NSSize size = growlView.frame.size;
size.height -= 18;
[growlView setFrameSize:size];
}
}
return [GeneralPreferencePane preferencePaneWithView:growlView title:NSLocalizedStringFromTableInBundle(@"Growl", nil, [NSBundle bundleForClass:[self class]], @"") iconNamed:@"growl"];
}