Skip to content

Commit bbef3b3

Browse files
committed
fixed a bug where some notification tweaks have conflict like Glance
1 parent 96907c7 commit bbef3b3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Tweak.xm

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static BOOL isIndicatorEnabled;
2828
static BOOL isToastEnabled;
2929
static BOOL isLockIndicatorEnabled;
3030

31+
%group init
32+
3133
%hook SpringBoard
3234
- (void)frontDisplayDidChange:(id)arg1 {
3335
%orig;
@@ -142,7 +144,6 @@ static BOOL isLockIndicatorEnabled;
142144
}
143145
%end
144146

145-
146147
%hook FBScene
147148
-(void)updateSettings:(id)arg1 withTransitionContext:(id)arg2 completion:(id)arg3{
148149
FBProcess *process = self.clientProcess;
@@ -270,6 +271,8 @@ static BOOL isLockIndicatorEnabled;
270271
}
271272
%end
272273

274+
%end
275+
273276
static void prefsLockIndicatorChanged() {
274277
Immortalizer *immortalizer = [Immortalizer sharedInstance];
275278
NSArray *lockedBundleIDs = [[NSUserDefaults standardUserDefaults] arrayForKey:@"LockedBundleIDs"];
@@ -290,15 +293,15 @@ static void immortalizerPreferencesChanged() {
290293
}
291294

292295
static void prefsNotifsChanged() {
293-
Immortalizer *immortalizer = [Immortalizer sharedInstance];
294-
NSArray *immortalBundleIDs = [[NSUserDefaults standardUserDefaults] arrayForKey:@"ImmortalForegroundBundleIDs"];
295-
for (NSString * immortalApp in immortalBundleIDs) {
296-
if ([immortalizer isNotificationEnabledForBundleIdentifier:immortalApp]) {
297-
[[%c(UNSUserNotificationServer) sharedInstance] _didChangeApplicationState:4 forBundleIdentifier:immortalApp];
298-
} else {
299-
[[%c(UNSUserNotificationServer) sharedInstance] _didChangeApplicationState:8 forBundleIdentifier:immortalApp];
296+
Immortalizer *immortalizer = [Immortalizer sharedInstance];
297+
NSArray *immortalBundleIDs = [[NSUserDefaults standardUserDefaults] arrayForKey:@"ImmortalForegroundBundleIDs"];
298+
for (NSString * immortalApp in immortalBundleIDs) {
299+
if ([immortalizer isNotificationEnabledForBundleIdentifier:immortalApp]) {
300+
[[%c(UNSUserNotificationServer) sharedInstance] _didChangeApplicationState:4 forBundleIdentifier:immortalApp];
301+
} else {
302+
[[%c(UNSUserNotificationServer) sharedInstance] _didChangeApplicationState:8 forBundleIdentifier:immortalApp];
303+
}
300304
}
301-
}
302305
}
303306

304307
static void prefsIndicatorChanged() {
@@ -311,15 +314,20 @@ static void prefsToastChanged() {
311314
isToastEnabled = [toastPrefs objectForKey:@"isToastEnabled"] ? [toastPrefs boolForKey:@"isToastEnabled"] : YES;
312315
}
313316

317+
static id observer;
314318
static void loadAllImmortalizerPrefs() {
315-
immortalizerPreferencesChanged();
316-
prefsNotifsChanged();
317-
prefsIndicatorChanged();
318-
prefsToastChanged();
319-
prefsLockIndicatorChanged();
319+
observer = [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *_) {
320+
immortalizerPreferencesChanged();
321+
prefsNotifsChanged();
322+
prefsIndicatorChanged();
323+
prefsToastChanged();
324+
prefsLockIndicatorChanged();
325+
[NSNotificationCenter.defaultCenter removeObserver: observer];
326+
}];
320327
}
321328

322329
%ctor {
330+
%init(init);
323331
loadAllImmortalizerPrefs();
324332
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)immortalizerPreferencesChanged, CFSTR("com.sergy.immortalizer.preferenceschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
325333
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsNotifsChanged, CFSTR("com.sergy.immortalizer.preferenceschanged.notifs"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

0 commit comments

Comments
 (0)