diff --git a/Makefile b/Makefile index 0dec3e6..e23ca7b 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ ARCHS = armv7 arm64 VALID_ARCHS = armv7 armv7s arm64 -include theos/makefiles/common.mk +include $(THEOS)/makefiles/common.mk TWEAK_NAME = NotifyMusic NotifyMusic_FILES = Tweak.xm -NotifyMusic_FRAMEWORKS = UIKit +NotifyMusic_FRAMEWORKS = UIKit MediaPlayer NotifyMusic_LIBRARIES = bulletin include $(THEOS_MAKE_PATH)/tweak.mk after-install:: install.exec "killall -9 SpringBoard" +SUBPROJECTS += notifymusicprefs +include $(THEOS_MAKE_PATH)/aggregate.mk diff --git a/Tweak.xm b/Tweak.xm index 672b8f5..c661b50 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -1,8 +1,22 @@ #import +@interface SBApplication +@end + +@interface SpringBoard ++(SpringBoard *)sharedApplication; +-(SBApplication *)_accessibilityFrontMostApplication; +@end + +@interface SBLockScreenManager ++(SBLockScreenManager *)sharedInstance; +-(BOOL)isUILocked; +@end + @interface MPUNowPlayingMetadata @property (nonatomic,readonly) NSString * title; @property (nonatomic,readonly) NSString * artist; + @property (nonatomic,readonly) NSString * album; @end @interface MPUNowPlayingController @@ -10,6 +24,7 @@ @property (nonatomic,readonly) NSString * nowPlayingAppDisplayID; @property (nonatomic,readonly) MPUNowPlayingMetadata * currentNowPlayingMetadata; @property (nonatomic,readonly) UIImage * currentNowPlayingArtwork; + @property (nonatomic,readonly) NSDictionary * currentNowPlayingInfo; @end @interface JBBulletinManager : NSObject @@ -26,22 +41,31 @@ %hook MPUNowPlayingController static NSString *cachedTitle; static NSString *artist; + static NSString *album; -(void)_updateCurrentNowPlaying{ %orig; + NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.notifymusicprefs.plist"; + NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath]; + BOOL enablewhilelocked = [[prefs objectForKey:@"enablewhilelocked"] boolValue]; + BOOL showalbumname = [[prefs objectForKey:@"showalbumname"] boolValue]; double delayInSeconds = 0.5; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ - if(self.isPlaying && ([self.nowPlayingAppDisplayID isEqualToString:@"com.apple.Music"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.spotify.client"]) && ![cachedTitle isEqualToString:self.currentNowPlayingMetadata.title]){ - cachedTitle = [self.currentNowPlayingMetadata.title copy]; - if([self.currentNowPlayingMetadata.artist length] > 1){ - artist = [NSString stringWithFormat: @"\nBy: %@", self.currentNowPlayingMetadata.artist]; - }else{ - artist = @""; - } - if(self.currentNowPlayingArtwork != nil){ - [[objc_getClass("JBBulletinManager") sharedInstance] showBulletinWithTitle:@"Now Playing" message:[NSString stringWithFormat: @"%@%@", self.currentNowPlayingMetadata.title, artist] bundleID:self.nowPlayingAppDisplayID hasSound:false soundID:0 vibrateMode:0 soundPath:@"" attachmentImage:self.currentNowPlayingArtwork overrideBundleImage:nil]; - }else{ - [[objc_getClass("JBBulletinManager") sharedInstance] showBulletinWithTitle:@"Now Playing" message:[NSString stringWithFormat: @"%@%@", self.currentNowPlayingMetadata.title, artist] bundleID:self.nowPlayingAppDisplayID]; + if(![cachedTitle isEqualToString:self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoTitle"]]){ + cachedTitle = [self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoTitle"] copy]; + if((enablewhilelocked || (![[%c(SBLockScreenManager) sharedInstance] isUILocked])) && self.isPlaying && ([self.nowPlayingAppDisplayID isEqualToString:@"com.aspiro.TIDAL"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.ondalabs.doppi"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.coppertino.VoxMobile"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.soundcloud.TouchApp"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.Saavn.Saavn"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.apple.Music"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.spotify.client"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.pandora"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.rhapsody.iphone.Rhapsody3"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.google.PlayMusic"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.deezer.Deezer"] || [self.nowPlayingAppDisplayID isEqualToString:@"com.michaelclay.Cesium"])){ + artist = [NSString stringWithFormat: @"\n%@", self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoArtist"]]; + + if([self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoAlbum"] length] > 1 && showalbumname){ + album = self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoAlbum"]; + }else{ + album = @"Now Playing"; + } + if(self.currentNowPlayingArtwork != nil){ + [[objc_getClass("JBBulletinManager") sharedInstance] showBulletinWithTitle:album message:[NSString stringWithFormat: @"%@%@", self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoTitle"], artist] bundleID:self.nowPlayingAppDisplayID hasSound:false soundID:0 vibrateMode:0 soundPath:@"" attachmentImage:self.currentNowPlayingArtwork overrideBundleImage:nil]; + }else{ + [[objc_getClass("JBBulletinManager") sharedInstance] showBulletinWithTitle:album message:[NSString stringWithFormat: @"%@%@", self.currentNowPlayingInfo[@"kMRMediaRemoteNowPlayingInfoTitle"], artist] bundleID:self.nowPlayingAppDisplayID]; + } } } }); diff --git a/control b/control index 4025208..5d20b4b 100644 --- a/control +++ b/control @@ -1,7 +1,7 @@ Package: com.gilshahar7.notifymusic Name: NotifyMusic Depends: mobilesubstrate, net.limneos.libbulletin -Version: 1.0 +Version: 1.2 Architecture: iphoneos-arm Description: Creates a banner notification with song metadata when song is changed. Maintainer: gilshahar7 diff --git a/notifymusicprefs/Makefile b/notifymusicprefs/Makefile new file mode 100644 index 0000000..2ea0301 --- /dev/null +++ b/notifymusicprefs/Makefile @@ -0,0 +1,14 @@ +ARCHS = armv7 arm64 +include $(THEOS)/makefiles/common.mk + +BUNDLE_NAME = notifymusicprefs +notifymusicprefs_FILES = nmpRootListController.m +notifymusicprefs_INSTALL_PATH = /Library/PreferenceBundles +notifymusicprefs_FRAMEWORKS = UIKit +notifymusicprefs_PRIVATE_FRAMEWORKS = Preferences + +include $(THEOS_MAKE_PATH)/bundle.mk + +internal-stage:: + $(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END) + $(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/notifymusicprefs.plist$(ECHO_END) diff --git a/notifymusicprefs/Resources/Info.plist b/notifymusicprefs/Resources/Info.plist new file mode 100644 index 0000000..9bfa5e0 --- /dev/null +++ b/notifymusicprefs/Resources/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + notifymusicprefs + CFBundleIdentifier + com.gilshahar7.notifymusicprefs + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSPrincipalClass + nmpRootListController + + diff --git a/notifymusicprefs/Resources/NotifyMusic@2x.png b/notifymusicprefs/Resources/NotifyMusic@2x.png new file mode 100644 index 0000000..fde9da8 Binary files /dev/null and b/notifymusicprefs/Resources/NotifyMusic@2x.png differ diff --git a/notifymusicprefs/Resources/Root.plist b/notifymusicprefs/Resources/Root.plist new file mode 100644 index 0000000..6abf357 --- /dev/null +++ b/notifymusicprefs/Resources/Root.plist @@ -0,0 +1,41 @@ + + + + + items + + + cell + PSGroupCell + label + NotifyMusic + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.notifymusicprefs + key + enablewhilelocked + label + Enable while locked + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.notifymusicprefs + key + showalbumname + label + Show album name in title + + + title + NotifyMusic + + diff --git a/notifymusicprefs/entry.plist b/notifymusicprefs/entry.plist new file mode 100644 index 0000000..4354057 --- /dev/null +++ b/notifymusicprefs/entry.plist @@ -0,0 +1,21 @@ + + + + + entry + + bundle + notifymusicprefs + cell + PSLinkCell + detail + nmpRootListController + icon + NotifyMusic.png + isController + + label + NotifyMusic + + + diff --git a/notifymusicprefs/nmpRootListController.h b/notifymusicprefs/nmpRootListController.h new file mode 100644 index 0000000..53a1403 --- /dev/null +++ b/notifymusicprefs/nmpRootListController.h @@ -0,0 +1,5 @@ +#import + +@interface nmpRootListController : PSListController + +@end diff --git a/notifymusicprefs/nmpRootListController.m b/notifymusicprefs/nmpRootListController.m new file mode 100644 index 0000000..f9ddd0e --- /dev/null +++ b/notifymusicprefs/nmpRootListController.m @@ -0,0 +1,13 @@ +#include "nmpRootListController.h" + +@implementation nmpRootListController + +- (NSArray *)specifiers { + if (!_specifiers) { + _specifiers = [[self loadSpecifiersFromPlistName:@"Root" target:self] retain]; + } + + return _specifiers; +} + +@end