From 8fd3a0903afbeddbee1b47353829f05b61e4ca60 Mon Sep 17 00:00:00 2001 From: Adam Demasi Date: Sun, 18 Jun 2017 15:56:45 +0930 Subject: [PATCH] [tweak,prefs] implement settings sample notification thing --- HBCZNowPlayingController.x | 4 + Tweak.x | 12 +-- prefs/HBCZNotificationTableCell.x | 100 +++++++++++++++++++++-- prefs/Resources/Root.plist | 4 +- prefs/Resources/en.lproj/Root.strings | 6 +- prefs/Resources/en_AU.lproj/Root.strings | 6 +- prefs/Resources/en_GB.lproj/Root.strings | 6 +- 7 files changed, 114 insertions(+), 24 deletions(-) diff --git a/HBCZNowPlayingController.x b/HBCZNowPlayingController.x index 9a958fc..f167557 100644 --- a/HBCZNowPlayingController.x +++ b/HBCZNowPlayingController.x @@ -30,6 +30,10 @@ #pragma mark - NSObject - (instancetype)init { + if (!IN_SPRINGBOARD) { + return nil; + } + self = [super init]; if (self) { diff --git a/Tweak.x b/Tweak.x index 013c1c5..988d178 100644 --- a/Tweak.x +++ b/Tweak.x @@ -67,12 +67,14 @@ HBCZPreferences *preferences; // set up variables preferences = [HBCZPreferences sharedInstance]; - // get the controller rolling - [HBCZNowPlayingController sharedInstance]; + if (IN_SPRINGBOARD) { + // get the controller rolling + [HBCZNowPlayingController sharedInstance]; - %init; + %init; - if (IS_IOS_OR_NEWER(iOS_10_0)) { - %init(PhilSchiller); + if (IS_IOS_OR_NEWER(iOS_10_0)) { + %init(PhilSchiller); + } } } diff --git a/prefs/HBCZNotificationTableCell.x b/prefs/HBCZNotificationTableCell.x index fa3438a..414bebd 100644 --- a/prefs/HBCZNotificationTableCell.x +++ b/prefs/HBCZNotificationTableCell.x @@ -1,10 +1,55 @@ #import "HBCZNotificationTableCell.h" #import +#import #include -@interface NCNotificationRequest : NSObject +@interface NCNotificationContent : NSObject -+ (instancetype)notificationRequestWithSectionId:(NSString *)sectionID notificationId:(NSString *)notificationID threadId:(NSString *)threadID title:(NSString *)title message:(NSString *)message timestamp:(NSDate *)timestamp destinations:(NSSet *)destinations; +@property (nonatomic, readonly, copy) NSString *header; +@property (nonatomic, readonly, copy) NSString *title; +@property (nonatomic, readonly, copy) NSString *message; +@property (nonatomic, readonly, copy) NSString *subtitle; +@property (nonatomic, readonly, copy) NSString *topic; + +@property (nonatomic, readonly) NSDate *date; +@property (getter=isDateAllDay, nonatomic, readonly) BOOL dateAllDay; +@property (nonatomic, readonly) NSTimeZone *timeZone; + +@property (nonatomic, readonly) UIImage *icon; +@property (nonatomic, readonly) UIImage *attachmentImage; + +@end + +@interface NCMutableNotificationContent : NCNotificationContent + +@property (nonatomic, copy) NSString *header; +@property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *message; +@property (nonatomic, copy) NSString *subtitle; +@property (nonatomic, copy) NSString *topic; + +@property (nonatomic, retain) NSDate *date; +@property (getter=isDateAllDay, nonatomic) BOOL dateAllDay; +@property (nonatomic, retain) NSTimeZone *timeZone; + +@property (nonatomic, retain) UIImage *icon; +@property (nonatomic, retain) UIImage *attachmentImage; + +@end + +@interface NCNotificationRequest : NSObject + +@property (nonatomic, copy, readonly) NSString *sectionIdentifier; + +@property (nonatomic, retain, readonly) NCNotificationContent *content; + +@end + +@interface NCMutableNotificationRequest : NSObject + +@property (nonatomic, copy) NSString *sectionIdentifier; + +@property (nonatomic, retain) NCMutableNotificationContent *content; @end @@ -39,9 +84,10 @@ UIImageView *wallpaperView = [[UIImageView alloc] initWithFrame:self.contentView.bounds]; wallpaperView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - wallpaperView.image = [UIImage imageWithContentsOfFile:@"~/Library/SpringBoard/LockBackgroundThumbnail.jpg".stringByExpandingTildeInPath]; + wallpaperView.image = [UIImage imageWithContentsOfCPBitmapFile:@"~/Library/SpringBoard/LockBackground.cpbitmap".stringByExpandingTildeInPath flags:kNilOptions]; wallpaperView.contentMode = UIViewContentModeScaleAspectFill; wallpaperView.clipsToBounds = YES; + wallpaperView.layer.minificationFilter = kCAFilterTrilinear; [self.contentView addSubview:wallpaperView]; [self _setUpNotification]; @@ -51,24 +97,62 @@ } - (void)_setUpNotification { - dlopen("/Library/MobileSubstrate/DynamicLibraries/Canzone.dylib", RTLD_LAZY); + static NSArray *Songs; + static UIImage *CanzoneImage; + static UIImage *PlaceholderImage; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/UserNotificationsUIKit.framework"] load]; + dlopen("/Library/MobileSubstrate/DynamicLibraries/Canzone.dylib", RTLD_LAZY); + + Songs = @[ + @[ @"Take on Me", @"Hunting High and Low\na-ha" ], + @[ @"Get Lucky", @"Random Access Memories\nDaft Punk" ], + @[ @"Drop It Like It’s Hot", @"R&G (Rhythm & Gangsta): The Masterpiece\nSnoop Dogg ft. Pharrell" ], + @[ @"Every Teardrop is a Waterfall", @"Until Now\nColdplay vs Swedish House Mafia" ], + @[ @"Satellite", @"Sirens of the Sea\nOceanlab" ], + @[ @"What Is Love", @"The Album\nHaddaway" ], + @[ @"All Star", @"All Star Smash Hits\nSmash Mouth" ], + @[ @"Sandstorm", @"Before the Storm\nDarude" ], + @[ @"Secret Agent", @"Netsky\nNetsky" ], + @[ @"Strobe", @"For Lack Of A Better Name\ndeadmau5" ], + @[ @"Slam The Door", @"Slam The Door\nZedd" ], + @[ @"Till The Sky Falls Down", @"The New Daylight\nDash Berlin" ], + @[ @"Deep At Night (Adam K & Soha Remix)", @"Deep At Night\nErcola & Heikki L" ], + @[ @"Snowcone", @"W:/2016ALBUM/\ndeadmau5" ], + @[ @"Kyoto", @"Horsestep\nDJ Sn0w & DJ Horse" ] + ]; + + CanzoneImage = [UIImage _applicationIconImageForBundleIdentifier:@"ws.hbang.canzone.app" format:MIIconVariantDocumentSmall scale:[UIScreen mainScreen].scale]; // yeah the names are messed up + PlaceholderImage = [UIImage imageNamed:@"placeholder-artwork" inBundle:[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MedaPlayerUI.framework"]]; + }); if (_notificationCell) { [_notificationCell removeFromSuperview]; _notificationCell = nil; } - [[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/UserNotificationsUIKit.framework"] load]; + NSArray *song = Songs[arc4random_uniform(Songs.count)]; + + NCMutableNotificationRequest *request = [[%c(NCMutableNotificationRequest) alloc] init]; + request.sectionIdentifier = @"ws.hbang.canzone.app"; - NCNotificationRequest *request = [%c(NCNotificationRequest) notificationRequestWithSectionId:@"ws.hbang.canzone.app" notificationId:@"0" threadId:@"0" title:@"Now Playing" message:@"Take on Me\nHunting High and Low\na-ha" timestamp:[NSDate date] destinations:[NSSet set]]; + NCMutableNotificationContent *content = [[%c(NCMutableNotificationContent) alloc] init]; + content.title = NSLocalizedStringFromTableInBundle(@"NOW_PLAYING_TITLE", @"Localizable", [NSBundle bundleForClass:self.class], nil); + content.subtitle = song[0]; + content.message = song[1]; + content.date = [NSDate date]; + content.icon = CanzoneImage; + content.attachmentImage = PlaceholderImage; + request.content = [content copy]; _notificationCell = [[%c(NCNotificationListCell) alloc] initWithFrame:CGRectInset(self.contentView.bounds, 15.f, 15.f)]; _notificationCell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _notificationCell.contentViewController = [[%c(NCNotificationViewController) alloc] initWithNotificationRequest:request]; + _notificationCell.contentViewController = [[%c(NCNotificationViewController) alloc] initWithNotificationRequest:[request copy]]; _notificationCell.contentViewController.associatedView = _notificationCell; _notificationCell.insetMargins = UIEdgeInsetsMake(15.f, 15.f, 15.f, 15.f); _notificationCell.userInteractionEnabled = NO; - _notificationCell.adjustsFontForContentSizeCategory = YES; + _notificationCell.adjustsFontForContentSizeCategory = NO; _notificationCell.backgroundBlurred = YES; _notificationCell.configured = YES; [self.contentView addSubview:_notificationCell]; diff --git a/prefs/Resources/Root.plist b/prefs/Resources/Root.plist index 918e6c0..47fde06 100644 --- a/prefs/Resources/Root.plist +++ b/prefs/Resources/Root.plist @@ -40,13 +40,13 @@ cell PSGroupCell label - SAMPLE + PREVIEW cellClass HBCZNotificationTableCell height - 116 + 122 cell diff --git a/prefs/Resources/en.lproj/Root.strings b/prefs/Resources/en.lproj/Root.strings index 3500433..519ff68 100644 --- a/prefs/Resources/en.lproj/Root.strings +++ b/prefs/Resources/en.lproj/Root.strings @@ -10,9 +10,9 @@ WIDGET_EXPLANATION Enable the Now Playing widget via the Notification Center Today page. - - SAMPLE - Sample + + PREVIEW + Preview NOTIFICATIONS diff --git a/prefs/Resources/en_AU.lproj/Root.strings b/prefs/Resources/en_AU.lproj/Root.strings index 28197ae..1743c39 100644 --- a/prefs/Resources/en_AU.lproj/Root.strings +++ b/prefs/Resources/en_AU.lproj/Root.strings @@ -10,9 +10,9 @@ WIDGET_EXPLANATION Enable the Now Playing widget via the Notification Centre Today page. - - SAMPLE - Sample + + PREVIEW + Preview NOTIFICATIONS diff --git a/prefs/Resources/en_GB.lproj/Root.strings b/prefs/Resources/en_GB.lproj/Root.strings index f33fc21..1d4e2eb 100644 --- a/prefs/Resources/en_GB.lproj/Root.strings +++ b/prefs/Resources/en_GB.lproj/Root.strings @@ -10,9 +10,9 @@ WIDGET_EXPLANATION Enable the Now Playing widget via the Notification Centre Today page. - - SAMPLE - Sample + + PREVIEW + Preview NOTIFICATIONS