Skip to content

Commit

Permalink
Add ControlCenter module, make it safer not to save real values
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Feb 6, 2024
1 parent bd3c0c3 commit d084e93
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ARCHS := arm64
ARCHS := arm64 arm64e
TARGET := iphone:clang:latest:15.0
INSTALL_TARGET_PROCESSES = SpringBoard
THEOS_PACKAGE_SCHEME := rootless

include $(THEOS)/makefiles/common.mk
# TARGET_CODESIGN = fastPathSign
TARGET_CODESIGN = fastPathSign

TWEAK_NAME = TrollPad

Expand Down
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,20 @@ Troll SpringBoard into thinking it's running on iPadOS
- Stage Manager
+ Requires iOS 16 or later
+ External display support is untested
+ Additional steps required
- Floating keyboard
+ Only works inside SpringBoard

### Enabling Stage Manager
> [!CAUTION]
> This is experimental and may be prone to bootloop. It is not recommended for everyone. Please carefully read the following reminders if you're going to use this.
> - When uninstalling this tweak with Stage Manager still enabled, do not remove MobileGestalt key. Doing so can cause bootloop. It's best to keep MobileGestalt key there.
> - [#4](https://github.com/khanhduytran0/TrollPad/issues/4): DO NOT disable `Show Dock`. Doing so may cause respring loop when rotating device to landscape. In case your device has fallen to bootloop, please enter recovery mode and exit.
> [!WARNING]
> It is recommended to enable Stage Manager using Control Center module only, so that there will be no risk of bootloop.
#### Modifying MobileGestalt cache
#### Modifying MobileGestalt cache (optional, may be useful later for external display support?)
- Open `/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist` in plist editor
- Open `CacheExtra`
- Add a key named `qeaj75wk3HF4DwQ8qbIi7g`, type `Number` and set value to `1`.

#### Creating toggle shortcut
- Open Shortcuts app
- Create an empty shortcut
- Add `Toggle Stage Manager` action
- Enable both `Show Dock` and `Show Recent Apps`
- Save and run the shortcut
Deprecated. Please use Control Center instead.

## Side effects
- Status bar has the style of iPadOS.
Expand Down
87 changes: 53 additions & 34 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,96 @@
#include <dispatch/dispatch.h>
#import <objc/runtime.h>

// Hook this to avoid real keys from being set
%hook NSUserDefaults
- (void)setBool:(BOOL)value forKey:(NSString *)key {
if ([key isEqualToString:@"SBChamoisHideDock"]) {
// Never ever set this to YES, as it is known to respring loop
%orig(NO, key);
} else if ([key hasPrefix:@"SBChamois"]) {
%orig(value, [NSString stringWithFormat:@"TrollPad_%@", key]);
} else {
%orig;
}
}

- (BOOL)boolForKey:(NSString *)key {
if ([key hasPrefix:@"SBChamois"]) {
return %orig([NSString stringWithFormat:@"TrollPad_%@", key]);
} else {
return %orig;
}
}

- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)key options:(NSKeyValueObservingOptions)options context:(void *)context {
if ([key hasPrefix:@"SBChamois"]) {
return %orig(observer, [NSString stringWithFormat:@"TrollPad_%@", key], options, context);
} else {
return %orig;
}
}

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)key context:(void *)context {
if ([key hasPrefix:@"SBChamois"]) {
return %orig(observer, [NSString stringWithFormat:@"TrollPad_%@", key], context);
} else {
return %orig;
}
}
%end

// Do this to pass most iPad checks
//UIUserInterfaceIdiom userInterfaceIdiom = UIUserInterfaceIdiomPad;
@implementation UIDevice(hook)
%hook UIDevice
- (UIUserInterfaceIdiom)userInterfaceIdiom {
return UIUserInterfaceIdiomPad;
}
@end
%end

/*
%hook _UIStatusBarVisualProvider_iOS
+ (Class)class {
static BOOL called = NO;
called = !called;
if (called) {
return NSClassFromString(@"_UIStatusBarVisualProvider_Split58");
} else {
return %orig;
}
return %c(_UIStatusBarVisualProvider_Split58);
}
%end
*/

// The following hooks are taken from various sources, please refer to tweaks that enable Slide Over.
@interface SpringBoard : NSObject
@end
@implementation SpringBoard(hook)
%hook SpringBoard
- (NSInteger)homeScreenRotationStyle {
return 2;
}
@end
%end

@interface SBMedusaConfigurationUsageMetric : NSObject
@end
@implementation SBMedusaConfigurationUsageMetric(hook)
%hook SBMedusaConfigurationUsageMetric
- (BOOL)_isFloatingActive {
return YES;
}
@end
%end

@interface SBPlatformController : NSObject
@end
@implementation SBPlatformController(hook)
%hook SBPlatformController
-(NSInteger)medusaCapabilities {
return 2;
}
@end
%end

@interface SBApplication : NSObject
@end
@implementation SBApplication(hook)
%hook SBApplication
-(BOOL)isMedusaCapable {
return YES;
}

- (BOOL)_supportsApplicationType:(int)arg1 {
return YES;
}
@end
%end

@interface SBMainWorkspace : NSObject
@end
@implementation SBMainWorkspace(hook)
%hook SBMainWorkspace
- (BOOL)isMedusaEnabled {
return YES;
}
@end
%end

@interface SBFloatingDockController : NSObject
@end
@implementation SBFloatingDockController(hook)
%hook SBFloatingDockController
+ (BOOL)isFloatingDockSupported {
return YES;
}
@end
%end
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Description: Troll SpringBoard into thinking it's running on iPadOS.
Maintainer: khanhduytran0
Author: khanhduytran0
Section: Tweaks
Depends: mobilesubstrate (>= 0.9.5000)
Depends: mobilesubstrate (>= 0.9.5000), firmware (>= 15.0), plistbuddy
30 changes: 30 additions & 0 deletions layout/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

set -e
bundle_system=/System/Library/ControlCenter/Bundles/ContinuousExposeModule.bundle
# FIXME: use $JB_ROOT_PATH instead?
bundle_jb=/var/jb/Library/ControlCenter/Bundles/ContinuousExposeModule.bundle
plistbuddy=/var/jb/usr/libexec/PlistBuddy

case "$1" in
(configure)
if [ -d $bundle_system ] ; then
# Copy Stage Manager CC module
ln -sf $bundle_system/* $bundle_jb/
rm $bundle_jb/Info.plist
cp $bundle_system/Info.plist $bundle_jb/Info.plist
$plistbuddy -c "Delete :SBIconVisibilityDefaultVisible" $bundle_jb/Info.plist
$plistbuddy -c "Delete :SBIconVisibilitySetByAppPreference" $bundle_jb/Info.plist
$plistbuddy -c "Add :UIDeviceFamily:0 integer 1" $bundle_jb/Info.plist
fi
;;
(abort-upgrade|abort-remove|abort-deconfigure)
exit 0
;;
(*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac

exit 0
13 changes: 13 additions & 0 deletions layout/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -e
# FIXME: use $JB_ROOT_PATH instead?
bundle_jb=/var/jb/Library/ControlCenter/Bundles/ContinuousExposeModule.bundle

case "$1" in
(remove)
rm -rf $bundle_jb
;;
esac

exit 0
Empty file.

0 comments on commit d084e93

Please sign in to comment.