Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
Add option to disable ambient mode in landscape

The tweak now runs on all devices with firmware >= 14.0, though I wouldn't recommend enabling it if the notch doesn't cut into your content
  • Loading branch information
therealFoxster committed Dec 3, 2023
1 parent fe65d50 commit 70d47db
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 91 deletions.
31 changes: 26 additions & 5 deletions Settings.x
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ static const NSInteger sectionId = 517; // DontEatMyContent's section ID (just a
switchOn:IS_TWEAK_ENABLED
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:ENABLED_KEY];

YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"];
[settingsViewController.navigationController popViewControllerAnimated:YES];
DEMC_showSnackBar(LOCALIZED_STRING(@"CHANGES_SAVED"));
return YES;

YTAlertView *alert = [%c(YTAlertView) confirmationDialogWithAction:^
{
Expand All @@ -63,6 +68,20 @@ static const NSInteger sectionId = 517; // DontEatMyContent's section ID (just a
];
[sectionItems addObject:enabled];

// Disable ambient mode
YTSettingsSectionItem *disableAmbientMode = [%c(YTSettingsSectionItem) switchItemWithTitle:LOCALIZED_STRING(@"DISABLE_AMBIENT_MODE")
titleDescription:nil
accessibilityIdentifier:nil
switchOn:IS_DISABLE_AMBIENT_MODE_ENABLED
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:DISABLE_AMBIENT_MODE_KEY];
DEMC_showSnackBar(LOCALIZED_STRING(@"CHANGES_SAVED"));
return YES;
}
settingItemId:0
];
[sectionItems addObject:disableAmbientMode];

// Safe area constant
YTSettingsSectionItem *constraintConstant = [%c(YTSettingsSectionItem) itemWithTitle:LOCALIZED_STRING(@"SAFE_AREA_CONST")
titleDescription:LOCALIZED_STRING(@"SAFE_AREA_CONST_DESC")
Expand All @@ -75,7 +94,7 @@ static const NSInteger sectionId = 517; // DontEatMyContent's section ID (just a
NSMutableArray *rows = [NSMutableArray array];

float currentConstant = 20.0;
float storedConstant = [[NSUserDefaults standardUserDefaults] floatForKey:SAFE_AREA_CONSTANT_KEY];;
float storedConstant = [[NSUserDefaults standardUserDefaults] floatForKey:SAFE_AREA_CONSTANT_KEY];
UInt8 index = 0, selectedIndex = 0;
while (currentConstant <= 25.0) {
NSString *title = [NSString stringWithFormat:@"%.1f", currentConstant];
Expand Down Expand Up @@ -134,15 +153,17 @@ static const NSInteger sectionId = 517; // DontEatMyContent's section ID (just a
[sectionItems addObject:reportIssue];

// View source code
YTSettingsSectionItem *sourceCode = [%c(YTSettingsSectionItem) itemWithTitle:LOCALIZED_STRING(@"SOURCE_CODE")
YTSettingsSectionItem *version = [%c(YTSettingsSectionItem) itemWithTitle:LOCALIZED_STRING(@"VERSION")
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:nil
detailTextBlock:^NSString *() {
return VERSION;
}
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger sectionItemIndex) {
return [%c(YTUIUtils) openURL:[NSURL URLWithString:@"https://github.com/therealFoxster/DontEatMyContent"]];
return [%c(YTUIUtils) openURL:[NSURL URLWithString:@"https://github.com/therealFoxster/DontEatMyContent/releases/"]];
}
];
[sectionItems addObject:sourceCode];
[sectionItems addObject:version];

[delegate setSectionItems:sectionItems
forCategory:sectionId
Expand Down
8 changes: 8 additions & 0 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#import <UIKit/UIKit.h>

#define DEMC @"DontEatMyContent"
#define VERSION @"1.1.0"

// Keys
#define ENABLED_KEY @"DEMC_enabled"
#define COLOR_VIEWS_ENABLED_KEY @"DEMC_colorViewsEnabled"
#define SAFE_AREA_CONSTANT_KEY @"DEMC_safeAreaConstant"
#define DISABLE_AMBIENT_MODE_KEY @"DEMC_disableAmbientMode"
#define LIMIT_ZOOM_TO_FILL_KEY @"DEMC_limitZoomToFill"

#define DEFAULT_CONSTANT 22.0
#define IS_TWEAK_ENABLED [[NSUserDefaults standardUserDefaults] boolForKey:ENABLED_KEY]
#define IS_COLOR_VIEWS_ENABLED [[NSUserDefaults standardUserDefaults] boolForKey:COLOR_VIEWS_ENABLED_KEY]
#define IS_DISABLE_AMBIENT_MODE_ENABLED [[NSUserDefaults standardUserDefaults] boolForKey:DISABLE_AMBIENT_MODE_KEY]
#define IS_LIMIT_ZOOM_TO_FILL_ENABLED [[NSUserDefaults standardUserDefaults] boolForKey:LIMIT_ZOOM_TO_FILL_KEY]
#define LOCALIZED_STRING(s) [bundle localizedStringForKey:s value:nil table:nil]

@interface YTPlayerViewController : UIViewController
Expand All @@ -29,6 +34,9 @@
@interface MLHAMSBDLSampleBufferRenderingView : UIView
@end

@interface HAMSampleBufferDisplayLayerView : UIView
@end

@interface YTMainAppEngagementPanelViewController : UIViewController
- (BOOL)isLandscapeEngagementPanel;
- (BOOL)isPeekingSupported;
Expand Down
110 changes: 28 additions & 82 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#import <rootless.h>
#import "Tweak.h"

#define UNSUPPORTED_DEVICES @[@"iPhone14,3", @"iPhone14,6", @"iPhone14,8"]
#define THRESHOLD 1.99

CGFloat constant; // Makes rendering view a bit larger since constraining to safe area leaves a gap between the notch/Dynamic Island and video
Expand All @@ -14,7 +13,6 @@ static BOOL isRemoveEngagementPanelViewControllerWithIdentifierCalled = NO;
static MLHAMSBDLSampleBufferRenderingView *renderingView;
static NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *centerYConstraint;

static BOOL DEMC_isDeviceSupported();
static void DEMC_activateConstraints();
static void DEMC_deactivateConstraints();
static void DEMC_centerRenderingView();
Expand All @@ -37,27 +35,35 @@ NSBundle *DEMC_getTweakBundle();
UIView *renderingViewContainer = [playerView valueForKey:@"_renderingViewContainer"];
renderingView = [playerView renderingView];

widthConstraint = [renderingView.widthAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.widthAnchor constant:constant];
heightConstraint = [renderingView.heightAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.heightAnchor constant:constant];
centerXConstraint = [renderingView.centerXAnchor constraintEqualToAnchor:renderingViewContainer.centerXAnchor];
centerYConstraint = [renderingView.centerYAnchor constraintEqualToAnchor:renderingViewContainer.centerYAnchor];

if (IS_COLOR_VIEWS_ENABLED) {
playerView.backgroundColor = [UIColor blueColor];
renderingViewContainer.backgroundColor = [UIColor greenColor];
renderingView.backgroundColor = [UIColor redColor];
} else {
playerView.backgroundColor = nil;
if (IS_DISABLE_AMBIENT_MODE_ENABLED) {
playerView.backgroundColor = [UIColor blackColor];;
renderingViewContainer.backgroundColor = [UIColor blackColor];
renderingView.backgroundColor = [UIColor blackColor];
}

YTMainAppVideoPlayerOverlayViewController *activeVideoPlayerOverlay = [self activeVideoPlayerOverlay];
if (IS_TWEAK_ENABLED) {
widthConstraint = [renderingView.widthAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.widthAnchor constant:constant];
heightConstraint = [renderingView.heightAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.heightAnchor constant:constant];
centerXConstraint = [renderingView.centerXAnchor constraintEqualToAnchor:renderingViewContainer.centerXAnchor];
centerYConstraint = [renderingView.centerYAnchor constraintEqualToAnchor:renderingViewContainer.centerYAnchor];

if (IS_COLOR_VIEWS_ENABLED) {
playerView.backgroundColor = [UIColor blueColor];
renderingViewContainer.backgroundColor = [UIColor greenColor];
renderingView.backgroundColor = [UIColor redColor];
} else if (!IS_DISABLE_AMBIENT_MODE_ENABLED) {
playerView.backgroundColor = [UIColor blackColor];
renderingViewContainer.backgroundColor = nil;
renderingView.backgroundColor = nil;
}

// Must check class since YTInlineMutedPlaybackPlayerOverlayViewController doesn't have -(BOOL)isFullscreen
if ([activeVideoPlayerOverlay isKindOfClass:%c(YTMainAppVideoPlayerOverlayViewController)] &&
[activeVideoPlayerOverlay isFullscreen] && !isZoomedToFill && !isEngagementPanelVisible)
DEMC_activateConstraints();
YTMainAppVideoPlayerOverlayViewController *activeVideoPlayerOverlay = [self activeVideoPlayerOverlay];

// Must check class since YTInlineMutedPlaybackPlayerOverlayViewController doesn't have -(BOOL)isFullscreen
if ([activeVideoPlayerOverlay isKindOfClass:%c(YTMainAppVideoPlayerOverlayViewController)] &&
[activeVideoPlayerOverlay isFullscreen] && !isZoomedToFill && !isEngagementPanelVisible)
DEMC_activateConstraints();
}

%orig(animated);
}
Expand Down Expand Up @@ -166,78 +172,17 @@ NSBundle *DEMC_getTweakBundle();

%end // group DEMC_Tweak

%group DEMC_UnsupportedDevice

// Get tweak settings' index path & prevent it from being opened on unsupported devices
id settingsCollectionView;
NSIndexPath *tweakIndexPath;
%hook YTCollectionViewController
- (id)collectionView:(id)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
YTSettingsCell *cell = %orig;
if ([cell isKindOfClass:%c(YTSettingsCell)]) {
YTLabel *title = [cell valueForKey:@"_titleLabel"];
if ([title.text isEqualToString:DEMC]) {
settingsCollectionView = collectionView;
tweakIndexPath = indexPath;
}
}
return cell;
}
- (BOOL)collectionView:(id)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == settingsCollectionView && indexPath == tweakIndexPath) {
NSBundle *bundle = DEMC_getTweakBundle();
DEMC_showSnackBar(LOCALIZED_STRING(@"UNSUPPORTED_DEVICE"));
return NO;
}
return %orig;
}
%end

%end // group DEMC_UnsupportedDevice

%ctor {
if (!DEMC_isDeviceSupported()) {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:ENABLED_KEY];
%init(DEMC_UnsupportedDevice);
return;
}

constant = [[NSUserDefaults standardUserDefaults] floatForKey:SAFE_AREA_CONSTANT_KEY];
if (constant == 0) { // First launch probably
constant = DEFAULT_CONSTANT;
[[NSUserDefaults standardUserDefaults] setFloat:constant forKey:SAFE_AREA_CONSTANT_KEY];
}
if (IS_TWEAK_ENABLED) %init(DEMC_Tweak);
}

static BOOL DEMC_isDeviceSupported() {
// Get device model identifier (e.g. iPhone14,4)
// https://stackoverflow.com/a/11197770/19227228
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceModelId = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

NSArray *unsupportedModelIds = UNSUPPORTED_DEVICES;
for (NSString *identifier in unsupportedModelIds) {
if ([deviceModelId isEqualToString:identifier]) {
return NO;
}
}

if ([deviceModelId containsString:@"iPhone"]) {
if ([deviceModelId isEqualToString:@"iPhone13,1"]) {
// iPhone 12 mini
return YES;
}
NSString *modelNumber = [[deviceModelId stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] stringByReplacingOccurrencesOfString:@"," withString:@"."];
if ([modelNumber floatValue] >= 14.0) {
// iPhone 13 series and newer
return YES;
} else return NO;
} else return NO;
%init(DEMC_Tweak);
}

static void DEMC_activateConstraints() {
if (!IS_TWEAK_ENABLED) return;
if (videoAspectRatio < THRESHOLD) {
DEMC_deactivateConstraints();
return;
Expand All @@ -250,6 +195,7 @@ static void DEMC_activateConstraints() {
}

static void DEMC_deactivateConstraints() {
if (!IS_TWEAK_ENABLED) return;
// NSLog(@"deactivate");
renderingView.translatesAutoresizingMaskIntoConstraints = YES;
}
Expand All @@ -276,4 +222,4 @@ NSBundle *DEMC_getTweakBundle() {
bundle = [NSBundle bundleWithPath:ROOT_PATH_NS(@"/Library/Application Support/DontEatMyContent.bundle")];
});
return bundle;
}
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: me.foxster.donteatmycontent
Name: DontEatMyContent
Version: 1.0.12
Version: 1.1.0
Architecture: iphoneos-arm
Description: Prevent the notch/Dynamic Island from munching on 2:1 video content in YouTube
Maintainer: Foxster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"DEFAULT" = "default";
"SAFE_AREA_CONST_MESSAGE" = "Your changes were saved. If a video is currently playing, dismiss it for changes to take effect";

"COLOR_VIEWS" = "Colored views";
"COLOR_VIEWS_DESC" = "Sets a red background for the rendering view, green for the rendering view container, and blue for the player view; useful for debugging";
"COLOR_VIEWS" = "Color views for debugging";
"COLOR_VIEWS_DESC" = "Sets a red background for the rendering view, green for the rendering view container, and blue for the player view";

"REPORT_ISSUE" = "Report an issue";
"SOURCE_CODE" = "View source code";
Expand All @@ -18,4 +18,10 @@
"LATER" = "Later";
"EXIT_YT_DESC" = "Relaunch YouTube to apply changes";

"UNSUPPORTED_DEVICE" = "This device is not supported";
"UNSUPPORTED_DEVICE" = "This device is not supported";

"DISABLE_AMBIENT_MODE" = "Disable ambient mode in landscape";
"VERSION" = "Version";

"LIMIT_ZOOM_TO_FILL" = "Zoom to almost fill (experimental)";
"LIMIT_ZOOM_TO_FILL_DESC" = "Limits zoom to fill to the notch/Dynamic Island";

0 comments on commit 70d47db

Please sign in to comment.