Skip to content

Commit

Permalink
Merge pull request #2 from dimitarnestorov/master
Browse files Browse the repository at this point in the history
Improving constructor
  • Loading branch information
YulkyTulky committed Jul 3, 2020
2 parents 4dfc1ac + 5c14530 commit 8f302c8
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,33 @@ static void loadPrefs() {

}

static id observer;

void removeObserver() {
if (observer) {
[[NSNotificationCenter defaultCenter] removeObserver:observer];
observer = nil;
}
}

%ctor {

// DEVELOPER'S NOTE: Hooking IGFeedItem did not work as the like would "half-happen" by then and crash Instagram

loadPrefs(); // Load preferences into variables
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.yulkytulky.instanotastalker/saved"), NULL, CFNotificationSuspensionBehaviorCoalesce); // Listen for preference changes

if (enabled) { // Thanks, Dimitar Nestorov
dispatch_async(dispatch_queue_create("InstaNotAStalker.wait", 0), ^{
dispatch_queue_t signal = dispatch_queue_create("InstaNotAStalker.signal", 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
while (!NSClassFromString(@"IGFeedItemPhotoCell") || !NSClassFromString(@"IGFeedItemVideoCell") || !NSClassFromString(@"IGFeedItemPageCell") || !NSClassFromString(@"IGFeedItemUFICell")) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), signal, ^{
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
%init;
});
}

}
if (enabled) {
NSBundle *bundle = [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] bundlePath], @"/Frameworks/InstagramAppCoreFramework.framework"]];
observer = [[NSNotificationCenter defaultCenter] addObserverForName:NSBundleDidLoadNotification object:bundle queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
%init;
removeObserver();
}];

[bundle load];
}
}

%dtor {
removeObserver();
}

0 comments on commit 8f302c8

Please sign in to comment.