Update DontEatMyContent (1.0.2 -> 1.0.3)

Update to work with YouTube's redesign

Add another method to get video aspect ratio

Add another method to detect pinch gesture
This commit is contained in:
foxster-mp4 2022-11-02 20:13:19 -07:00
parent 6efdf519f4
commit 6b62aca494
2 changed files with 51 additions and 37 deletions

View file

@ -43,7 +43,8 @@
// DontEatMyContent
NSString* deviceName();
BOOL isDeviceSupported();
void aspectRatioChanged(CGFloat arg);
BOOL deviceIsSupported();
void activate();
void deactivate();
void center();

View file

@ -940,7 +940,6 @@ NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *cen
}
- (void)didPressToggleFullscreen {
YTMainAppVideoPlayerOverlayViewController *activeVideoPlayerOverlay = [self activeVideoPlayerOverlay];
if (![activeVideoPlayerOverlay isFullscreen]) // Entering fullscreen
activate();
else // Exiting fullscreen
@ -948,26 +947,34 @@ NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *cen
%orig;
}
- (void)didSwipeToEnterFullscreen {
%orig; activate();
}
- (void)didSwipeToExitFullscreen {
%orig; deactivate();
}
// Get video aspect ratio; doesn't work for some users; see -(void)resetForVideoWithAspectRatio:(double)
- (void)didSwipeToEnterFullscreen { %orig; activate(); }
- (void)didSwipeToExitFullscreen { %orig; deactivate(); }
// Retrieve video aspect ratio (1) (no longer works but kept for backwards compatibility)
- (void)singleVideo:(id)arg1 aspectRatioDidChange:(CGFloat)arg2 {
aspectRatio = arg2;
if (aspectRatio == 0.0) {
// App backgrounded
} else if (aspectRatio < THRESHOLD) {
deactivate();
} else {
activate();
}
%orig(arg1, arg2);
aspectRatioChanged(arg2);
}
%end
// Retrieve video aspect ratio (2) (no longer works but kept for backwards compatibility)
%hook YTVideoZoomOverlayController
- (void)resetForVideoWithAspectRatio:(double)arg1 {
%orig(arg1);
aspectRatioChanged(arg1);
}
%end
// Retrieve video aspect ratio (3)
%hook YTPlayerView
- (void)setAspectRatio:(CGFloat)arg1 {
%orig(arg1);
aspectRatioChanged(arg1);
// %log((CGFloat) aspectRatio);
}
%end
// Detect pinch gesture (1) (no longer works but kept for backwards compatibility)
%hook YTVideoZoomOverlayView
- (void)didRecognizePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
// %log((CGFloat) [pinchGestureRecognizer scale], (CGFloat) [pinchGestureRecognizer velocity]);
@ -980,27 +987,22 @@ NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *cen
}
%orig(pinchGestureRecognizer);
}
- (void)flashAndHideSnapIndicator {}
// https://github.com/lgariv/UniZoom/blob/master/Tweak.xm
- (void)setSnapIndicatorVisible:(bool)arg1 {
%orig(NO);
%end
// Detect pinch gesture (2)
%hook YTVideoFreeZoomOverlayView
- (void)didRecognizePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
if ([pinchGestureRecognizer velocity] <= 0.0) { // >>Zoom out<<
zoomedToFill = false;
activate();
} else if ([pinchGestureRecognizer velocity] > 0.0) { // <<Zoom in>>
zoomedToFill = true;
deactivate();
}
%orig(pinchGestureRecognizer);
}
%end
%hook YTVideoZoomOverlayController
// Get video aspect ratio; fallback for -(void)singleVideo:(id)aspectRatioDidChange:(CGFloat)
- (void)resetForVideoWithAspectRatio:(double)arg1 {
aspectRatio = arg1;
%log;
if (aspectRatio == 0.0) {}
else if (aspectRatio < THRESHOLD) {
deactivate();
} else {
activate();
}
%orig(arg1);
}
%end
%end // gDontEatMyContent
// DontEatMycontent - detecting device model
@ -1011,7 +1013,7 @@ NSString* deviceName() {
return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}
BOOL isDeviceSupported() {
BOOL deviceIsSupported() {
NSString *identifier = deviceName();
NSArray *unsupportedDevices = UNSUPPORTED_DEVICES;
@ -1032,6 +1034,17 @@ BOOL isDeviceSupported() {
} else return NO;
}
void aspectRatioChanged(CGFloat arg) {
aspectRatio = arg;
if (aspectRatio == 0.0) {
// App backgrounded or something went wrong
} else if (aspectRatio < THRESHOLD) {
deactivate();
} else {
activate();
}
}
void activate() {
if (aspectRatio < THRESHOLD || zoomedToFill) return;
// NSLog(@"activate");
@ -1159,7 +1172,7 @@ static BOOL didFinishLaunching;
if (replacePreviousAndNextButton()) {
%init(gReplacePreviousAndNextButton);
}
if (dontEatMyContent() && isDeviceSupported()) {
if (dontEatMyContent() && deviceIsSupported()) {
%init(gDontEatMyContent);
}
if (@available(iOS 16, *)) {