Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape music info to avoid syntax error #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static bool firstLoad = false;
static int lastWeatherUpdate = 1;
//static NSMutableArray* signedInfo = [[NSMutableArray alloc] init];

static NSString* escape(NSString* original) {
return [original stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
}

static void update(NSString* values, NSString* type){
for (WKWebView* webview in _webviews) {
if([[NSString stringWithFormat:@"%@", webview.URL] isEqualToString:@"about:blank"]){
Expand Down Expand Up @@ -748,7 +752,7 @@ static void getBattery(){
// }

static void getMusic(){
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 1.0);
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.3);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
NSDictionary *info = [objc_getClass("MPUNowPlayingController") _xeninfo_currentNowPlayingInfo];
NSString *artist = [NSString stringWithFormat:@"%@",[info objectForKey:@"kMRMediaRemoteNowPlayingInfoArtist"]];
Expand All @@ -775,7 +779,7 @@ static void getMusic(){
[UIImagePNGRepresentation(uiimage) writeToFile:@"var/mobile/Documents/Artwork.jpg" atomically:YES];
}

NSString* music = [NSString stringWithFormat:@"var artist = '%@', album = '%@', title = '%@', isplaying = %d;", artist, album, title, isplaying];
NSString* music = [NSString stringWithFormat:@"var artist = '%@', album = '%@', title = '%@', isplaying = %d;", escape(artist), escape(album), escape(title), isplaying];
update(music, @"music");

info = nil;
Expand Down Expand Up @@ -838,16 +842,16 @@ static void getMusic(){

%hook SBMediaController
- (void)_nowPlayingInfoChanged{
%orig;
if(loaded && deviceON && hasWebview){
getMusic();
}
return %orig;
}
- (void)_mediaRemoteNowPlayingInfoDidChange:(id)arg1{
%orig;
if(loaded && deviceON && hasWebview){
getMusic();
}
%orig;
}
%end

Expand Down