Merge pull request #643 from therealFoxster/main

Update DontEatMyContent to work with YouTube's redesign (1.0.2 -> 1.0.3)
This commit is contained in:
Nguyễn Đạt 2022-11-03 10:27:07 +07:00 committed by GitHub
commit 9ebbda2671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 37 deletions

View file

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

View file

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