summaryrefslogtreecommitdiffstats
path: root/QuickActions/Tweak.x
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-08-16 16:09:37 -0400
committerCameron Katri <me@cameronkatri.com>2021-08-16 16:10:54 -0400
commit615b0aefe92fb5d7b1fae821f91eb98e3f403bfe (patch)
treecc157ab8b0684f1b85b6645fe6198ae62dcbbe53 /QuickActions/Tweak.x
parent4d2aa96bbce1edc066b3bfc197d1e2e968e4aa5d (diff)
downloadtweaks-615b0aefe92fb5d7b1fae821f91eb98e3f403bfe.tar.gz
tweaks-615b0aefe92fb5d7b1fae821f91eb98e3f403bfe.tar.zst
tweaks-615b0aefe92fb5d7b1fae821f91eb98e3f403bfe.zip
QuickActions: Add new tweak
Diffstat (limited to 'QuickActions/Tweak.x')
-rw-r--r--QuickActions/Tweak.x116
1 files changed, 116 insertions, 0 deletions
diff --git a/QuickActions/Tweak.x b/QuickActions/Tweak.x
new file mode 100644
index 0000000..61d6a65
--- /dev/null
+++ b/QuickActions/Tweak.x
@@ -0,0 +1,116 @@
+#import <Foundation/NSUserDefaults.h>
+
+#import "Tweak.h"
+
+static bool leftOn;
+static NSString *leftApp;
+static bool rightOn;
+static NSString *rightApp;
+
+void openApplication(NSString *bundleID)
+{
+ FBSOpenApplicationOptions* opts = [%c(FBSOpenApplicationOptions) optionsWithDictionary:@{
+ @"__LaunchOrigin" : @"BulletinDestinationCoverSheet",
+ @"__PromptUnlockDevice" : @YES,
+ @"__UnlockDevice" : @YES,
+ @"__LaunchImage" : @"",
+ @"__Actions" : @[]
+ }];
+ FBSystemServiceOpenApplicationRequest* request = [%c(FBSystemServiceOpenApplicationRequest) request];
+ request.options = opts;
+ request.bundleIdentifier = bundleID;
+ request.trusted = YES;
+ request.clientProcess = [[%c(FBProcessManager) sharedInstance] systemApplicationProcess];
+
+ [[%c(SBMainWorkspace) sharedInstance] systemService:[%c(FBSystemService) sharedInstance] handleOpenApplicationRequest:request withCompletion:^{}];
+}
+
+%hook CSQuickActionsView
+
+-(void)handleButtonPress:(CSQuickActionsButton *)button
+{
+ [button setSelected:false];
+ if (leftOn && button.type == 1)
+ openApplication(leftApp);
+ else if (rightOn && button.type == 0)
+ openApplication(rightApp);
+ else
+ %orig;
+ return;
+}
+
+-(void)handleButtonTouchBegan:(CSQuickActionsButton *)button
+{
+ if ((leftOn && button.type == 1) ||
+ (rightOn && button.type == 0))
+ return;
+ else
+ %orig;
+}
+
+-(void)handleButtonTouchEnded:(CSQuickActionsButton *)button
+{
+ if ((leftOn && button.type == 1) ||
+ (rightOn && button.type == 0))
+ return;
+ else
+ %orig;
+}
+
+%end
+
+%hook CSQuickActionsButton
+
+%property (nonatomic, retain) UIImage *originalImage;
+
+-(id)initWithType:(long long)type
+{
+ id o = %orig;
+ if (!self.originalImage)
+ self.originalImage = [self image];
+ [self loadImage];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadImage) name:@"com.cameronkatri.quickactions/ReloadImages" object:nil];
+ return o;
+}
+
+-(void)setImage:(UIImage *)img
+{
+ %orig;
+ [[self valueForKey:@"_contentView"] setImage:img];
+}
+
+%new
+-(void)loadImage
+{
+ if (self.type == 1 && leftOn)
+ [self setImage:[UIImage _applicationIconImageForBundleIdentifier:leftApp format:0 scale:[UIScreen mainScreen].scale]];
+ else if (self.type == 0 && rightOn)
+ [self setImage:[UIImage _applicationIconImageForBundleIdentifier:rightApp format:0 scale:[UIScreen mainScreen].scale]];
+ else
+ [self setImage:self.originalImage];
+}
+
+%end
+
+static void updatePrefs(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userinfo)
+{
+ NSNumber *leftOnValue = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"leftOn" inDomain:@"com.cameronkatri.quickactions"];
+ NSNumber *rightOnValue = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"rightOn" inDomain:@"com.cameronkatri.quickactions"];
+ leftApp = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"leftApp" inDomain:@"com.cameronkatri.quickactions"];
+ rightApp = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"rightApp" inDomain:@"com.cameronkatri.quickactions"];
+ leftOn = leftOnValue ? [leftOnValue boolValue] : false;
+ rightOn = leftOnValue ? [rightOnValue boolValue] : false;
+ if ([leftApp isEqual:@""] || [leftApp length] == 0)
+ leftOn = false;
+ if ([rightApp isEqual:@""] || [rightApp length] == 0)
+ rightOn = false;
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"com.cameronkatri.quickactions/ReloadImages" object:nil];
+}
+
+%ctor
+{
+ updatePrefs(NULL, NULL, NULL, NULL, NULL);
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, updatePrefs, (CFStringRef)@"com.cameronkatri.quickactions/ReloadPrefs", NULL, CFNotificationSuspensionBehaviorCoalesce);
+}
+
+// vim: filetype=logos