Skip to content

Commit

Permalink
Rootless support
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelomer committed Apr 2, 2024
1 parent 3024184 commit 55c4348
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
packages
.theos
obj
**/.DS_Store
**/.DS_Store
/layout/DEBIAN/
/layout/DEBIAN/*
12 changes: 9 additions & 3 deletions ExampleMods/colorfulgoose/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
INSTALL_TARGET_PROCESSES = SpringBoard
TARGET = iphone:11.2:8.0
ARCHS = arm64e arm64 armv7

ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
ARCHS = arm64 arm64e
TARGET = iphone:13.3:15.0
else
ARCHS = arm64 arm64e armv7
TARGET = iphone:13.3:8.0
endif

include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = ColorfulGoose
ColorfulGoose_FILES = PXColorfulGoose.m
ColorfulGoose_CFLAGS = -fobjc-arc
ColorfulGoose_CFLAGS = -I../../Template -fobjc-arc
ColorfulGoose_INSTALL_PATH = /Library/MobileGoose/Mods
ColorfulGoose_FRAMEWORKS = UIKit Foundation

Expand Down
4 changes: 2 additions & 2 deletions ExampleMods/colorfulgoose/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Priority: optional
Section: Tweaks
Architecture: iphoneos-arm
Depends: com.pixelomer.mobilegoose (>=1.2)
Maintainer: PixelOmer
Author: PixelOmer
Maintainer: pixelomer
Author: pixelomer
12 changes: 9 additions & 3 deletions ExampleMods/joethegoose/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
INSTALL_TARGET_PROCESSES = SpringBoard
TARGET = iphone:11.2:8.0
ARCHS = arm64e arm64 armv7

ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
ARCHS = arm64 arm64e
TARGET = iphone:13.3:15.0
else
ARCHS = arm64 arm64e armv7
TARGET = iphone:13.3:8.0
endif

include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = JoeTheGoose
JoeTheGoose_FILES = PXJoeTheGooseMod.m
JoeTheGoose_CFLAGS = -fobjc-arc
JoeTheGoose_CFLAGS = -I../../Template -fobjc-arc
JoeTheGoose_INSTALL_PATH = /Library/MobileGoose/Mods
JoeTheGoose_FRAMEWORKS = UIKit Foundation

Expand Down
2 changes: 1 addition & 1 deletion ExampleMods/joethegoose/PXJoeTheGooseMod.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (void)setEnabled:(BOOL)enabled {
}

- (void)preferenceWithKey:(NSString *)key didChangeToValue:(id)value {
if (!value) value = PrefValue(key);
if (!value) value = PrefValue(key) ?: @"";
if (![key isEqualToString:@"Name"] || ![value isKindOfClass:[NSString class]]) return;
nameLabel.text = ((NSString *)value).length ? value : @"Joe";
}
Expand Down
4 changes: 2 additions & 2 deletions ExampleMods/joethegoose/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Priority: optional
Section: Tweaks
Architecture: iphoneos-arm
Depends: com.pixelomer.mobilegoose (>=1.2)
Maintainer: PixelOmer
Author: PixelOmer
Maintainer: pixelomer
Author: pixelomer
3 changes: 2 additions & 1 deletion Goose/MGGooseController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "MGViewController.h"
#import "MGGooseController.h"
#import "NSPointerArray+FixedCompact.h"
#import <rootless.h>

#pragma GCC diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
Expand All @@ -23,7 +24,7 @@ + (void)load {
- (void)loadMeme {
BOOL isImage = [imageContainer isKindOfClass:[MGImageContainerView class]];
NSString *path = [NSString
stringWithFormat:@"/Library/MobileGoose/%@",
stringWithFormat:ROOT_PATH_NS(@"/Library/MobileGoose/%@"),
isImage ? @"Memes" : @"Notes"
];
NSArray *files = [NSFileManager.defaultManager contentsOfDirectoryAtPath:path error:nil];
Expand Down
35 changes: 32 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
INSTALL_TARGET_PROCESSES = SpringBoard
TARGET = iphone:11.2:8.0
ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
ARCHS = arm64 arm64e
TARGET = iphone:13.3:15.0
# setWindow:, openURL:, etc. are required for rootful iOS 8.0
# but rootless works on iOS 15.0 and higher
CFLAGS = -Wno-deprecated-declarations
else
ARCHS = arm64 arm64e armv7
export TARGET ARCHS
TARGET = iphone:13.3:8.0
CFLAGS =
# UIWindowScene
Tweak.xm_CFLAGS = -Wno-unguarded-availability-new
endif

INSTALL_TARGET_PROCESSES = SpringBoard
export TARGET ARCHS CFLAGS

include $(THEOS)/makefiles/common.mk

Expand All @@ -12,5 +24,22 @@ MobileGoose_FILES = Tweak.xm $(wildcard Goose/*.mm)
MobileGoose_CFLAGS = -fobjc-arc -I. -include macros.h -ferror-limit=0

include $(THEOS_MAKE_PATH)/tweak.mk

ifeq ($(THEOS_PACKAGE_SCHEME),rootless)

internal-stage::
mkdir -p layout/DEBIAN
echo "interest /var/jb/Library/MobileGoose/Mods" > layout/DEBIAN/triggers
cp -pv postinst.rootless layout/DEBIAN/postinst

else

internal-stage::
mkdir -p layout/DEBIAN
echo "interest /Library/MobileGoose/Mods" > layout/DEBIAN/triggers
cp -pv postinst.rootful layout/DEBIAN/postinst

endif

SUBPROJECTS += Prefs
include $(THEOS_MAKE_PATH)/aggregate.mk
3 changes: 2 additions & 1 deletion Prefs/PXMGPModListController.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#import "PXMGPModListController.h"
#import "PXMGPModDetailsController.h"
#import <rootless.h>
#import <Preferences/PSSpecifier.h>

@implementation PXMGPModListController

- (NSArray *)specifiers {
if (!_specifiers) {
NSMutableArray *mutableSpecifiers = [NSMutableArray new];
NSString *modRoot = @"/Library/MobileGoose/Mods";
NSString *modRoot = ROOT_PATH_NS(@"/Library/MobileGoose/Mods");
NSError *error = nil;
NSArray *modNames = [NSFileManager.defaultManager
contentsOfDirectoryAtPath:modRoot
Expand Down
4 changes: 3 additions & 1 deletion Prefs/PXMGPRootListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ - (UIViewController *)_viewControllerForAncestor;
static void (*MobileGoose$UILabel$setText$orig)(id,SEL,id) = nil;
static void MobileGoose$UILabel$setText$hook(UILabel *self, SEL _cmd, NSString *text) {
if ([self._viewControllerForAncestor isKindOfClass:[PXMGPRootListController class]]) {
if ([self.superview isKindOfClass:[UISlider class]]) {
if (self.superview != nil && [NSStringFromClass(self.superview.class)
containsString:@"UISlider"])
{
text = [text componentsSeparatedByString:@"."].firstObject;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Prefs/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<key>label</key>
<string>Gift Count</string>
<key>footerText</key>
<string>You can tap the gifts to dismiss them.</string>
<string>You can tap gifts to dismiss them.</string>
</dict>
<dict>
<key>cell</key>
Expand Down Expand Up @@ -152,7 +152,7 @@
<key>label</key>
<string>Credits</string>
<key>footerText</key>
<string>MobileGoose was inspired by Desktop Goose, which was made by Samperson. Thanks to him for making an interesting program like that which lead to the creation of MobileGoose.</string>
<string>Thanks to Samperson for creating Desktop Goose, which inspired me to make MobileGoose for Apple devices.</string>
</dict>
<dict>
<key>cell</key>
Expand Down
12 changes: 10 additions & 2 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#import <Goose/MGGooseView.h>
#import <Goose/MGViewController.h>
#import <Goose/MGGooseController.h>
#import <rootless.h>

@interface MGWindow : UIWindow
@end

@interface SpringBoard : NSObject
- (BOOL)isLocked;
- (NSSet<UIWindowScene *> *)connectedScenes;
@end

static CGAffineTransform transform;
Expand Down Expand Up @@ -59,7 +61,13 @@ CGAffineTransform MGGetTransform(void) {
viewController = [MGViewController new];
transform = [viewController transformForOrientation:UIInterfaceOrientationPortrait];
gooseWindow = (UIWindow *)[[%c(MGWindow) alloc] initWithFrame:UIScreen.mainScreen.bounds];
gooseWindow.screen = [UIScreen mainScreen];
if (@available(iOS 13.0, *)) {
UIWindowScene *scene = self.connectedScenes.allObjects[0];
gooseWindow.windowScene = scene;
}
else {
gooseWindow.screen = [UIScreen mainScreen];
}
gooseWindow.rootViewController = viewController;
gooseWindow.userInteractionEnabled = YES;
gooseWindow.opaque = NO;
Expand Down Expand Up @@ -222,7 +230,7 @@ static void MGHandleExitNotification(
NULL,
0
);
NSString *dir = @"/Library/MobileGoose/Mods";
NSString *dir = ROOT_PATH_NS(@"/Library/MobileGoose/Mods");
NSArray *mods = [NSFileManager.defaultManager
contentsOfDirectoryAtPath:dir
error:nil
Expand Down
1 change: 0 additions & 1 deletion layout/DEBIAN/triggers

This file was deleted.

2 changes: 1 addition & 1 deletion layout/DEBIAN/postinst → postinst.rootful
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ finish() {
action="${1}"

# No control fd: bail out
[ -z "${action}" || -z "${CYDIA}" ] && return
[ -z "${action}" -o -z "${CYDIA}" ] && return

fd_version=
fd=
Expand Down
33 changes: 33 additions & 0 deletions postinst.rootless
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

finish() {
action="${1}"

# No control fd: bail out
[ -z "${action}" -o -z "${CYDIA}" ] && return

fd_version=
fd=
i=0
for item in ${CYDIA}; do
case "${i}" in
0) fd="${item}";;
1) fd_version="${item}";;
esac
i=$((i+1))
done

# Cydia control fd version != 1: bail out
[ "${fd_version}" -eq 1 ] || return

echo "finish:${action}" >&${fd}
}

case "$1" in

triggered)
echo "MobileGoose mods were changed, requesting a respring..."
finish reload
;;

esac

0 comments on commit 55c4348

Please sign in to comment.