Skip to content

Commit

Permalink
Add a switch for landscape home screen (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Mar 3, 2024
1 parent 8922770 commit 3000974
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TPPrefsObserver.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>

@interface TPPrefsObserver : NSObject
@property(nonatomic, assign) BOOL useiPadAppSwitchingAnimation;
@property(nonatomic, assign) BOOL allowLandscapeHomeScreen, useiPadAppSwitchingAnimation;
@end
5 changes: 4 additions & 1 deletion TPPrefsObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@implementation TPPrefsObserver
- (instancetype)init {
self = [super init];
[self observeKey:@"TPAllowLandscapeHomeScreen"];
[self observeKey:@"TPUseiPadAppSwitchingAnimation"];
// Fetch keys
[self observeValueForKeyPath:nil ofObject:nil change:nil context:nil];
Expand All @@ -18,6 +19,8 @@ - (void)observeKey:(NSString *)key {

- (void)observeValueForKeyPath:(NSString *)
keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
self.useiPadAppSwitchingAnimation = [NSUserDefaults.standardUserDefaults boolForKey:@"TPUseiPadAppSwitchingAnimation"];
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
self.allowLandscapeHomeScreen = [defaults boolForKey:@"TPAllowLandscapeHomeScreen"];
self.useiPadAppSwitchingAnimation = [defaults boolForKey:@"TPUseiPadAppSwitchingAnimation"];
}
@end
12 changes: 12 additions & 0 deletions TrollPadPrefs/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
<key>label</key>
<string>iPadOS app switching animation</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.apple.springboard</string>
<key>key</key>
<string>TPAllowLandscapeHomeScreen</string>
<key>label</key>
<string>Allow landscape Home Screen</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
Expand Down
10 changes: 10 additions & 0 deletions TrollPadPrefs/TPPRootListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
@interface TPPRootListController : PSListController

@end

// Respring
@interface SBSRelaunchAction : NSObject
+ (SBSRelaunchAction *)actionWithReason:(NSString *)reason options:(NSUInteger)options targetURL:(NSURL *)url;
@end

@interface FBSSystemService : NSObject
+ (FBSSystemService *)sharedService;
- (void)sendActions:(NSSet *)actions withResult:(id *)result;
@end
8 changes: 7 additions & 1 deletion TrollPadPrefs/TPPRootListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ @implementation TPPRootListController
- (NSArray *)specifiers {
if (!_specifiers) {
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Respring" style:UIBarButtonItemStylePlain target:self action:@selector(respring)];
}
return _specifiers;
}
Expand All @@ -26,4 +26,10 @@ - (void)openTwitter {
[UIApplication.sharedApplication openURL:[NSURL URLWithString:@"https://twitter.com/TranKha50277352"] options:@{} completionHandler:nil];
}

- (void)respring {
NSURL *returnURL = [NSURL URLWithString:@"prefs:root=TrollPad"];
SBSRelaunchAction *action = [NSClassFromString(@"SBSRelaunchAction") actionWithReason:@"RestartRenderServer" options:0 targetURL:returnURL];
[[NSClassFromString(@"FBSSystemService") sharedService] sendActions:[NSSet setWithObject:action] withResult:nil];
}

@end
2 changes: 1 addition & 1 deletion Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static uint16_t forcePadIdiom = 0;
// The following hooks are taken from various sources, please refer to tweaks that enable Slide Over.
%hook SpringBoard
- (NSInteger)homeScreenRotationStyle {
return 1;
return pref.allowLandscapeHomeScreen ? 1 : %orig;
}
%end

Expand Down

0 comments on commit 3000974

Please sign in to comment.