Skip to content

Commit

Permalink
Improve workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
dayanch96 committed Apr 1, 2024
1 parent cf133a7 commit 16fc395
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Sideloading.xm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <rootless.h>
#import "Source/Prefs/Localization.h"
#import "Source/Headers/YTAlertView.h"
#import "Source/Headers/Localization.h"

#define YT_BUNDLE_ID @"com.google.ios.youtubemusic"
#define YT_BUNDLE_NAME @"YouTubeMusic"
Expand Down Expand Up @@ -216,6 +217,7 @@ NSDictionary *replaceInfoDict(id self, SEL _cmd) {
BOOL isFirstTime = YES;

@interface InitWorkaround : UIViewController
@property (nonatomic, copy) void (^completion)(void);
@end

@implementation InitWorkaround
Expand All @@ -233,46 +235,45 @@ BOOL isFirstTime = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
MSHookMessageEx(objc_getClass("NSBundle"), @selector(infoDictionary), (IMP)replaceInfoDict, (IMP *)&orig_infoDictionary);

[self dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:^{
if (self.completion) {
self.completion();
}
}];
});
}

@end

@interface SFAuthenticationViewController : UIViewController
- (void)remoteViewControllerWillDismiss:(id)remoteVC;
@end

%hook SFAuthenticationViewController
- (void)viewDidAppear:(BOOL)animated {
%orig;

if (isFirstTime) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
MSHookMessageEx(objc_getClass("NSBundle"), @selector(infoDictionary), (IMP)replaceInfoDict, (IMP *)&orig_infoDictionary);

InitWorkaround *workaround = [[InitWorkaround alloc] init];
workaround.completion = ^{
[self dismissViewControllerAnimated:YES completion:^{
isFirstTime = NO;
if ([self respondsToSelector:@selector(remoteViewControllerWillDismiss:)]) {
[self performSelector:@selector(remoteViewControllerWillDismiss:)];
}

YTAlertView *alertView = [%c(YTAlertView) infoDialog];
alertView.title = LOC(@"WARNING");
alertView.subtitle = LOC(@"RETRY_LOGIN");
[alertView show];
}];
});
};

[self presentViewController:workaround animated:YES completion:nil];
}
}
%end

@interface YTMFirstTimeSignInViewController : UIViewController
@end

%hook YTMFirstTimeSignInViewController
- (void)viewDidAppear:(bool)arg1 {
%orig;

InitWorkaround *workaround = [[InitWorkaround alloc] init];
[self presentViewController:workaround animated:YES completion:nil];
}

- (void)viewDidDisappear:(bool)arg1 {
%orig;

Expand Down

0 comments on commit 16fc395

Please sign in to comment.