From 15240ea1e0dc4fc86a3f36cffe5b9c14ff0b2c93 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Mon, 27 Dec 2021 01:08:28 -0500 Subject: I lost track of all the changes --- QuickActions/Tweak.x | 184 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 165 insertions(+), 19 deletions(-) (limited to 'QuickActions/Tweak.x') diff --git a/QuickActions/Tweak.x b/QuickActions/Tweak.x index f5f4e39..64b69eb 100644 --- a/QuickActions/Tweak.x +++ b/QuickActions/Tweak.x @@ -46,6 +46,7 @@ void openApplication(NSString *bundleID) %property (nonatomic) BOOL rightOpen; %property (nonatomic) BOOL collapseLeft; %property (nonatomic) BOOL collapseRight; +%property (nonatomic,retain) DNDStateService *stateService; -(id)initWithFrame:(CGRect)arg1 delegate:(id)arg2 { @@ -53,8 +54,12 @@ void openApplication(NSString *bundleID) NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.cameronkatri.quickactions"]; - NSArray *leftButtons = (NSArray*)[defaults objectForKey:@"leftButtons"]; - NSArray *rightButtons = (NSArray*)[defaults objectForKey:@"rightButtons"]; + NSArray *leftButtons = [defaults arrayForKey:@"leftButtons"]; + if (leftButtons == nil) + leftButtons = @[@"com.apple.flashlight"]; + NSArray *rightButtons = [defaults arrayForKey:@"rightButtons"]; + if (rightButtons == nil) + rightButtons = @[@"com.apple.camera"]; self.leftButtons = [[NSMutableArray alloc] init]; self.rightButtons = [[NSMutableArray alloc] init]; @@ -62,7 +67,9 @@ void openApplication(NSString *bundleID) self.collapseLeft = [leftButtons count] > 1 ? true : false; self.leftOpen = !self.collapseLeft; - if ([leftButtons count] == 1) { + if ([leftButtons count] == 0) { + [self.flashlightButton setHidden:1]; + } else if ([leftButtons count] == 1) { [self.flashlightButton setBundleID:leftButtons[0]]; } else if ([leftButtons count] > 1) { [self.flashlightButton setImage:nil]; @@ -83,7 +90,9 @@ void openApplication(NSString *bundleID) self.collapseRight = [rightButtons count] > 1 ? true : false; self.rightOpen = !self.collapseRight; - if ([rightButtons count] == 1) { + if ([rightButtons count] == 0) { + [self.cameraButton setHidden:1]; + } else if ([rightButtons count] == 1) { [self.cameraButton setBundleID:rightButtons[0]]; } else if ([rightButtons count] > 1) { [self.cameraButton setImage:nil]; @@ -101,6 +110,11 @@ void openApplication(NSString *bundleID) } } + // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDND:) name:@"SBQuietModeStatusChangedNotification" object:nil]; + // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDND:) name:@"QuickActionsUpdateDND" object:nil]; + self.stateService = (DNDStateService *)[objc_getClass("DNDStateService") serviceForClientIdentifier:@"com.apple.donotdisturb.control-center.module"]; + [self.stateService addStateUpdateListener:self withCompletionHandler:nil]; + return o; } @@ -110,7 +124,7 @@ void openApplication(NSString *bundleID) CGRect cameraFrame = [[self cameraButton] frame]; if (self.rightOpen) { return CGRectMake(cameraFrame.origin.x, - cameraFrame.origin.y - ((cameraFrame.size.height * 3/4) * ((button.type + 1) / 2)), + cameraFrame.origin.y - ((cameraFrame.size.height * 3/4) * (button.type - 1)), cameraFrame.size.width, cameraFrame.size.height); } else { return cameraFrame; @@ -163,6 +177,18 @@ void openApplication(NSString *bundleID) buttonWidth, buttonHeight); } + NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.cameronkatri.quickactions"]; + + CGRect frame = self.flashlightButton.frame; + frame.origin.x += [defaults floatForKey:@"LeftOffsetX"]; + frame.origin.y -= [defaults floatForKey:@"LeftOffsetY"]; + self.flashlightButton.frame = frame; + + frame = self.cameraButton.frame; + frame.origin.x -= [defaults floatForKey:@"RightOffsetX"]; + frame.origin.y -= [defaults floatForKey:@"RightOffsetY"]; + self.cameraButton.frame = frame; + UIImageSymbolConfiguration *imageConfig = [UIImageSymbolConfiguration configurationWithTextStyle:UIFontTextStyleTitle1]; UIImage *image = [UIImage systemImageNamed:@"ellipsis" withConfiguration:imageConfig]; if ([self.leftButtons count] > 1) { @@ -177,11 +203,15 @@ void openApplication(NSString *bundleID) for (CSQuickActionsButton *button in [self leftButtons]) { [button setEdgeInsets:insets]; button.frame = [self leftFrameForButton:button]; + [button setHidden:!self.rightOpen]; } for (CSQuickActionsButton *button in [self rightButtons]) { [button setEdgeInsets:insets]; button.frame = [self rightFrameForButton:button]; + [button setHidden:!self.rightOpen]; } + + [self updateDND:nil]; } -(void)handleButtonPress:(CSQuickActionsButton *)button @@ -189,31 +219,54 @@ void openApplication(NSString *bundleID) [button setSelected:false]; if (button.type == 0 && self.collapseRight) { + self.rightOpen = !self.rightOpen; [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^(void){ - for (CSQuickActionsButton *button in [self rightButtons]) { - button.frame = [self rightFrameForButton:button]; - } + for (CSQuickActionsButton *button in [self rightButtons]) { + button.frame = [self rightFrameForButton:button]; + if (self.rightOpen) + [button setHidden:0]; + } } - completion:NULL]; - self.rightOpen = !self.rightOpen; + completion:^(BOOL finished) { + for (CSQuickActionsButton *button in [self rightButtons]) + [button setHidden:!self.rightOpen]; + }]; } else if (button.type == 1 && self.collapseLeft) { + self.leftOpen = !self.leftOpen; [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut - animations:^(void){ - for (CSQuickActionsButton *button in [self leftButtons]) { - button.frame = [self leftFrameForButton:button]; - } + animations:^(void) { + for (CSQuickActionsButton *button in [self leftButtons]) { + button.frame = [self leftFrameForButton:button]; + if (self.leftOpen) + [button setHidden:0]; + } } - completion:NULL]; - self.leftOpen = !self.leftOpen; - } else if (button.bundleID) { + completion:^(BOOL finished) { + for (CSQuickActionsButton *button in [self leftButtons]) + [button setHidden:!self.leftOpen]; + }]; + } else if ([button.bundleID isEqualToString:@"com.apple.flashlight"]) { + [self.delegate _toggleFlashlight]; + } else if ([button.bundleID isEqualToString:@"com.apple.camera"]) { + [self.delegate _launchCamera]; + } else if ([button.bundleID isEqualToString:@"com.apple.donotdisturb"]) { + [self setDoNotDisturb:!self.isDNDActive]; + } else if (button.bundleID) openApplication(button.bundleID); - } else + else { %orig; + return; + } + + /* This will make the CC module be correct */ + [self.delegate _resetIdleTimer]; + [self.delegate sendAction:[CSAction actionWithType:5]]; + return; } @@ -235,6 +288,68 @@ void openApplication(NSString *bundleID) %orig; } +-(void)setFlashlightOn:(BOOL)arg +{ + if ([self.flashlightButton.bundleID isEqualToString:@"com.apple.flashlight"]) + [self.flashlightButton setSelected:arg]; + if ([self.cameraButton.bundleID isEqualToString:@"com.apple.flashlight"]) + [self.cameraButton setSelected:arg]; + for (CSQuickActionsButton *button in [self leftButtons]) + if ([button.bundleID isEqualToString:@"com.apple.flashlight"]) + [button setSelected:arg]; + for (CSQuickActionsButton *button in [self rightButtons]) + if ([button.bundleID isEqualToString:@"com.apple.flashlight"]) + [button setSelected:arg]; +} + +%new +-(void)setDoNotDisturb:(BOOL)state +{ + DNDModeAssertionService *assertionService = (DNDModeAssertionService *)[objc_getClass("DNDModeAssertionService") serviceForClientIdentifier:@"com.apple.donotdisturb.control-center.module"]; + + if (state) { + DNDModeAssertionDetails *newAssertion = [objc_getClass("DNDModeAssertionDetails") userRequestedAssertionDetailsWithIdentifier:@"com.apple.control-center.manual-toggle" modeIdentifier:@"com.apple.donotdisturb.mode.default" lifetime:nil]; + [assertionService takeModeAssertionWithDetails:newAssertion error:NULL]; + } else { + [assertionService invalidateAllActiveModeAssertionsWithError:NULL]; + } + + [[NSNotificationCenter defaultCenter] postNotificationName:@"SBQuietModeStatusChangedNotification" object:nil]; +} + +%new +-(BOOL)isDNDActive +{ + + // DNDStateService *stateService = (DNDStateService *)[objc_getClass("DNDStateService") serviceForClientIdentifier:@"com.apple.donotdisturb.control-center.module"]; + return [[self.stateService queryCurrentStateWithError:nil] isActive]; +} + +%new +-(void)updateDND:(NSNotification *)notif +{ + BOOL active = [self isDNDActive]; + + if ([self.flashlightButton.bundleID isEqualToString:@"com.apple.donotdisturb"]) + [self.flashlightButton setSelected:active]; + if ([self.cameraButton.bundleID isEqualToString:@"com.apple.donotdisturb"]) + [self.cameraButton setSelected:active]; + for (CSQuickActionsButton *button in [self leftButtons]) + if ([button.bundleID isEqualToString:@"com.apple.donotdisturb"]) + [button setSelected:active]; + for (CSQuickActionsButton *button in [self rightButtons]) + if ([button.bundleID isEqualToString:@"com.apple.donotdisturb"]) + [button setSelected:active]; +} + +%new +-(void)stateService:(id)arg1 didReceiveDoNotDisturbStateUpdate:(id)arg2 +{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateDND:nil]; + }); +} + %end %hook CSQuickActionsButton @@ -250,7 +365,28 @@ void openApplication(NSString *bundleID) -(void)setBundleID:(NSString*)bundleID { %orig; - [self setImage:[UIImage _applicationIconImageForBundleIdentifier:bundleID format:0 scale:[UIScreen mainScreen].scale]]; + if ([bundleID isEqualToString:@"com.apple.camera"]) { + [self setImage:[self _imageWithName:@"OrbCamera"]]; + [self setLatching:FALSE]; + } else if ([bundleID isEqualToString:@"com.apple.flashlight"]) { + [self setImage:[self _imageWithName:@"OrbFlashlightOff"]]; + [self setSelectedImage:[self _imageWithName:@"OrbFlashlightOff"]]; + [self setLatching:TRUE]; + } else if (([bundleID isEqualToString:@"com.apple.donotdisturb"])) { + UIImageSymbolConfiguration *imageConfig = [UIImageSymbolConfiguration configurationWithTextStyle:UIFontTextStyleTitle2]; + [self setImage:[UIImage systemImageNamed:@"moon.fill" withConfiguration:imageConfig]]; + [self setSelectedImage:[UIImage systemImageNamed:@"moon.fill" withConfiguration:imageConfig]]; + ((UIImageView *)[self valueForKey:@"_contentView"]).contentMode = UIViewContentModeScaleAspectFit; + [self setLatching:TRUE]; + } else { + [self setImage:[UIImage _applicationIconImageForBundleIdentifier:bundleID format:0 scale:[UIScreen mainScreen].scale]]; + [self setLatching:FALSE]; + } +} + +-(void)setPermitted:(BOOL)permitted +{ + %orig(YES); } %end @@ -274,4 +410,14 @@ void openApplication(NSString *bundleID) %end +// %hook DNDNotificationsService + +// -(void)stateService:(id)arg1 didReceiveDoNotDisturbStateUpdate:(id)arg2{ +// %orig; + +// [[NSNotificationCenter defaultCenter] postNotificationName:@"QuickActionsUpdateDND" object:nil]; +// } + +// %end + // vim: filetype=logos -- cgit v1.2.3-56-ge451