Skip to content

Commit

Permalink
Merge pull request #27 from therealFoxster/use-yt-headers
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
therealFoxster committed Feb 19, 2024
2 parents 2253bc3 + 2f47269 commit e63fd11
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 127 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "YTHeaders"]
path = YTHeaders
url = https://github.com/therealFoxster/YTHeaders
18 changes: 18 additions & 0 deletions Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <YTHeaders/YTSettingsCell.h>
#import <YTHeaders/YTSettingsSectionItemManager.h>
#import <YTHeaders/YTSettingsPickerViewController.h>
#import <YTHeaders/YTSettingsSectionItem.h>
#import <YTHeaders/YTSettingsViewController.h>

#define DEMC @"DontEatMyContent"
#define VERSION @"1.1.3"
#define LOCALIZED_STRING(s) [bundle localizedStringForKey:s value:nil table:nil]

extern void DEMC_showSnackBar(NSString *text);
extern NSBundle *DEMC_getTweakBundle();
extern CGFloat constant;

// Category for additional functions
@interface YTSettingsSectionItemManager (DontEatMyContent)
- (void)updateDEMCSectionWithEntry:(id)entry;
@end
5 changes: 1 addition & 4 deletions Settings.x
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "Tweak.h"
#import "Settings.h"

// Adapted from
// https://github.com/PoomSmart/YouPiP/blob/bd04bf37be3d01540db418061164ae17a8f0298e/Settings.x
Expand All @@ -7,10 +8,6 @@
#define SECTION_HEADER(s) [sectionItems addObject:[%c(YTSettingsSectionItem) itemWithTitle:@"\t" titleDescription:[s uppercaseString] accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger sectionItemIndex) { return NO; }]]
#define SWITCH_ITEM(t, d, k) [sectionItems addObject:[%c(YTSettingsSectionItem) switchItemWithTitle:t titleDescription:d accessibilityIdentifier:nil switchOn:IS_ENABLED(k) switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:k];DEMC_showSnackBar(LOCALIZED_STRING(@"CHANGES_SAVED"));return YES;} settingItemId:0]]

extern void DEMC_showSnackBar(NSString *text);
extern NSBundle *DEMC_getTweakBundle();
extern CGFloat constant;

static const NSInteger sectionId = 517; // DontEatMyContent's section ID (just a random number)

%hook YTAppSettingsPresentationData
Expand Down
132 changes: 17 additions & 115 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#import <UIKit/UIKit.h>

#define DEMC @"DontEatMyContent"
#define VERSION @"1.1.3"
// #import <sys/utsname.h>
#import <rootless.h>
#import <YTHeaders/YTPlayerViewController.h>
#import <YTHeaders/YTPlayerView.h>
#import <YTHeaders/YTMainAppVideoPlayerOverlayViewController.h>
// #import <YTHeaders/MLHAMSBDLSampleBufferRenderingView.h>
#import <YTHeaders/YTMainAppEngagementPanelViewController.h>
#import <YTHeaders/YTEngagementPanelContainerViewController.h>
#import <YTHeaders/YTLabel.h>
#import <YTHeaders/YTAlertView.h>
#import <YTHeaders/YTHUDMessage.h>
#import <YTHeaders/GOOHUDManagerInternal.h>
#import <YTHeaders/YTUIUtils.h>

// Keys
#define kTweak @"DEMC_enabled"
Expand All @@ -11,117 +20,10 @@
#define kLimitZoomToFill @"DEMC_limitZoomToFill"
#define kEnableForAllVideos @"DEMC_enableForAllVideos"

#define THRESHOLD 1.97
#define DEFAULT_CONSTANT 21.5
#define IS_ENABLED(k) [[NSUserDefaults standardUserDefaults] boolForKey:k]
#define LOCALIZED_STRING(s) [bundle localizedStringForKey:s value:nil table:nil]

@interface YTPlayerViewController : UIViewController
- (id)activeVideoPlayerOverlay;
- (id)playerView;
- (BOOL)isCurrentVideoVertical;
@end

@interface YTPlayerView : UIView
- (id)renderingView;
@end

@interface YTMainAppVideoPlayerOverlayViewController : UIViewController
- (BOOL)isFullscreen;
@end

@interface MLHAMSBDLSampleBufferRenderingView : UIView
@end

@interface HAMSampleBufferDisplayLayerView : UIView
@end

@interface YTMainAppEngagementPanelViewController : UIViewController
- (BOOL)isLandscapeEngagementPanel;
- (BOOL)isPeekingSupported;
@end

@interface YTEngagementPanelContainerViewController : UIViewController
- (BOOL)isLandscapeEngagementPanel;
- (BOOL)isPeekingSupported;
@end

@interface YTLabel : UILabel
@property (nonatomic, copy, readwrite) NSString *text;
@end

@interface YTSettingsCell : UICollectionViewCell
@end

@interface YTSettingsSectionItemManager : NSObject
- (id)parentResponder;
@end

// Category for additional functions
@interface YTSettingsSectionItemManager (DontEatMyContent)
- (void)updateDEMCSectionWithEntry:(id)entry;
@end

@interface YTSettingsPickerViewController : UIViewController
- (instancetype)initWithNavTitle:(NSString *)navTitle
pickerSectionTitle:(NSString *)pickerSectionTitle
rows:(NSArray *)rows
selectedItemIndex:(NSUInteger)selectedItemIndex
parentResponder:(id)parentResponder;
@end

@interface YTSettingsSectionItem : NSObject
+ (instancetype)switchItemWithTitle:(NSString *)title
titleDescription:(NSString *)titleDescription
accessibilityIdentifier:(NSString *)accessibilityIdentifier
switchOn:(BOOL)switchOn
switchBlock:(BOOL (^)(YTSettingsCell *, BOOL))switchBlock
settingItemId:(int)settingItemId;
+ (instancetype)itemWithTitle:(NSString *)title
titleDescription:(NSString *)titleDescription
accessibilityIdentifier:(NSString *)accessibilityIdentifier
detailTextBlock:(id)detailTextBlock
selectBlock:(BOOL (^)(YTSettingsCell *, NSUInteger))selectBlock;
+ (instancetype)checkmarkItemWithTitle:(NSString *)title
selectBlock:(BOOL (^)(YTSettingsCell *, NSUInteger))selectBlock;
@end

@interface YTSettingsViewController : UIViewController
- (void)setSectionItems:(NSMutableArray <YTSettingsSectionItem *> *)sectionItems
forCategory:(NSInteger)category
title:(NSString *)title
titleDescription:(NSString *)titleDescription
headerHidden:(BOOL)headerHidden;
- (void)setSectionItems:(NSMutableArray <YTSettingsSectionItem *> *)sectionItems
forCategory:(NSInteger)category
title:(NSString *)title
icon:(id)icon
titleDescription:(NSString *)titleDescription
headerHidden:(BOOL)headerHidden;
- (void)pushViewController:(UIViewController *)viewController;
- (void)reloadData;
- (id)accountID;
- (id)initWithAccountID:(id)accountID parentResponder:(id)parentResponder;
@end

// Alert
@interface YTAlertView : UIView
@property (nonatomic, copy, readwrite) NSString *title;
@property (nonatomic, copy, readwrite) NSString *subtitle;
+ (instancetype)confirmationDialogWithAction:(void (^)(void))action
actionTitle:(NSString *)actionTitle
cancelTitle:(NSString *)cancelTitle;
- (void)show;
@end

// Snack bar
@interface YTHUDMessage : NSObject
+ (id)messageWithText:(id)text;
@end
@interface GOOHUDManagerInternal : NSObject
- (void)showMessageMainThread:(id)message;
+ (id)sharedInstance;
@end

@interface YTUIUtils : NSObject
+ (BOOL)openURL:(NSURL *)url;
@end
void DEMC_showSnackBar(NSString *text);
NSBundle *DEMC_getTweakBundle();
CGFloat constant; // Makes rendering view a bit larger since constraining to safe area leaves a gap between the notch/Dynamic Island and video
9 changes: 1 addition & 8 deletions Tweak.x
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#import <sys/utsname.h>
#import <rootless.h>
#import "Tweak.h"

#define THRESHOLD 1.97

CGFloat constant; // Makes rendering view a bit larger since constraining to safe area leaves a gap between the notch/Dynamic Island and video
static CGFloat videoAspectRatio = 16/9;
static BOOL isZoomedToFill = NO;
static BOOL isEngagementPanelVisible = NO;
static BOOL isEngagementPanelViewControllerRemoved = NO;
static MLHAMSBDLSampleBufferRenderingView *renderingView;
static UIView *renderingView; // MLHAMSBDLSampleBufferRenderingView *
static NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *centerYConstraint;

static void DEMC_activateConstraints();
static void DEMC_deactivateConstraints();
static void DEMC_centerRenderingView();
void DEMC_showSnackBar(NSString *text);
NSBundle *DEMC_getTweakBundle();

%hook YTPlayerViewController
- (void)viewDidAppear:(BOOL)animated {
Expand Down
1 change: 1 addition & 0 deletions YTHeaders
Submodule YTHeaders added at 256f8c

0 comments on commit e63fd11

Please sign in to comment.