mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-10 00:01:44 +00:00
Cherry-pick various fixes
This commit is contained in:
parent
33ebbaa114
commit
b931e6a642
@ -95,7 +95,7 @@ final class CameraDeviceContext {
|
||||
return 30.0
|
||||
}
|
||||
switch DeviceModel.current {
|
||||
case .iPhone14ProMax, .iPhone13ProMax:
|
||||
case .iPhone15ProMax, .iPhone14ProMax, .iPhone13ProMax:
|
||||
return 60.0
|
||||
default:
|
||||
return 30.0
|
||||
|
||||
@ -152,6 +152,10 @@ final class CameraDevice {
|
||||
if device.isLowLightBoostSupported {
|
||||
device.automaticallyEnablesLowLightBoostWhenAvailable = true
|
||||
}
|
||||
|
||||
if device.isExposureModeSupported(.continuousAutoExposure) {
|
||||
device.exposureMode = .continuousAutoExposure
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,10 @@ public extension Camera {
|
||||
case iPhone14Plus
|
||||
case iPhone14Pro
|
||||
case iPhone14ProMax
|
||||
case iPhone15
|
||||
case iPhone15Plus
|
||||
case iPhone15Pro
|
||||
case iPhone15ProMax
|
||||
case unknown
|
||||
|
||||
init(model: DeviceModel) {
|
||||
@ -21,6 +25,14 @@ public extension Camera {
|
||||
self = .iPhone14Pro
|
||||
case .iPhone14ProMax:
|
||||
self = .iPhone14ProMax
|
||||
case .iPhone15:
|
||||
self = .iPhone15
|
||||
case .iPhone15Plus:
|
||||
self = .iPhone15Plus
|
||||
case .iPhone15Pro:
|
||||
self = .iPhone15Pro
|
||||
case .iPhone15ProMax:
|
||||
self = .iPhone15ProMax
|
||||
case .unknown:
|
||||
self = .unknown
|
||||
default:
|
||||
@ -32,13 +44,9 @@ public extension Camera {
|
||||
switch self {
|
||||
case .singleCamera:
|
||||
return [1.0]
|
||||
case .iPhone14:
|
||||
case .iPhone14, .iPhone14Plus, .iPhone15, .iPhone15Plus:
|
||||
return [0.5, 1.0, 2.0]
|
||||
case .iPhone14Plus:
|
||||
return [0.5, 1.0, 2.0]
|
||||
case .iPhone14Pro:
|
||||
return [0.5, 1.0, 2.0, 3.0]
|
||||
case .iPhone14ProMax:
|
||||
case .iPhone14Pro, .iPhone14ProMax, .iPhone15Pro, .iPhone15ProMax:
|
||||
return [0.5, 1.0, 2.0, 3.0]
|
||||
case .unknown:
|
||||
return [1.0, 2.0]
|
||||
@ -91,7 +99,11 @@ enum DeviceModel: CaseIterable, Equatable {
|
||||
.iPhone14,
|
||||
.iPhone14Plus,
|
||||
.iPhone14Pro,
|
||||
.iPhone14ProMax
|
||||
.iPhone14ProMax,
|
||||
.iPhone15,
|
||||
.iPhone15Plus,
|
||||
.iPhone15Pro,
|
||||
.iPhone15ProMax
|
||||
]
|
||||
}
|
||||
|
||||
@ -154,6 +166,11 @@ enum DeviceModel: CaseIterable, Equatable {
|
||||
case iPhone14Pro
|
||||
case iPhone14ProMax
|
||||
|
||||
case iPhone15
|
||||
case iPhone15Plus
|
||||
case iPhone15Pro
|
||||
case iPhone15ProMax
|
||||
|
||||
case unknown(String)
|
||||
|
||||
var modelId: [String] {
|
||||
@ -248,6 +265,14 @@ enum DeviceModel: CaseIterable, Equatable {
|
||||
return ["iPhone15,2"]
|
||||
case .iPhone14ProMax:
|
||||
return ["iPhone15,3"]
|
||||
case .iPhone15:
|
||||
return ["iPhone15,4"]
|
||||
case .iPhone15Plus:
|
||||
return ["iPhone15,5"]
|
||||
case .iPhone15Pro:
|
||||
return ["iPhone16,1"]
|
||||
case .iPhone15ProMax:
|
||||
return ["iPhone16,2"]
|
||||
case let .unknown(modelId):
|
||||
return [modelId]
|
||||
}
|
||||
@ -345,6 +370,14 @@ enum DeviceModel: CaseIterable, Equatable {
|
||||
return "iPhone 14 Pro"
|
||||
case .iPhone14ProMax:
|
||||
return "iPhone 14 Pro Max"
|
||||
case .iPhone15:
|
||||
return "iPhone 15"
|
||||
case .iPhone15Plus:
|
||||
return "iPhone 15 Plus"
|
||||
case .iPhone15Pro:
|
||||
return "iPhone 15 Pro"
|
||||
case .iPhone15ProMax:
|
||||
return "iPhone 15 Pro Max"
|
||||
case let .unknown(modelId):
|
||||
if modelId.hasPrefix("iPhone") {
|
||||
return "Unknown iPhone"
|
||||
|
||||
@ -48,7 +48,7 @@ typedef enum
|
||||
@class PGCameraDeviceAngleSampler;
|
||||
@class TGCameraPreviewView;
|
||||
|
||||
@interface PGCamera : NSObject
|
||||
@interface PGCamera : NSObject <AVCapturePhotoCaptureDelegate>
|
||||
|
||||
@property (readonly, nonatomic) PGCameraCaptureSession *captureSession;
|
||||
@property (readonly, nonatomic) PGCameraDeviceAngleSampler *deviceAngleSampler;
|
||||
|
||||
@ -9,10 +9,8 @@
|
||||
@interface PGCameraCaptureSession : AVCaptureSession
|
||||
|
||||
@property (nonatomic, readonly) AVCaptureDevice *videoDevice;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
@property (nonatomic, readonly) AVCaptureStillImageOutput *imageOutput;
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@property (nonatomic, readonly) AVCapturePhotoOutput *imageOutput;
|
||||
@property (nonatomic, readonly) AVCaptureVideoDataOutput *videoOutput;
|
||||
@property (nonatomic, readonly) AVCaptureAudioDataOutput *audioOutput;
|
||||
@property (nonatomic, readonly) AVCaptureMetadataOutput *metadataOutput;
|
||||
|
||||
@ -37,8 +37,13 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
|
||||
|
||||
TGCameraPreviewView *_previewView;
|
||||
|
||||
UIInterfaceOrientation _currentPhotoOrientation;
|
||||
|
||||
NSTimeInterval _captureStartTime;
|
||||
}
|
||||
|
||||
@property (nonatomic, copy) void(^photoCaptureCompletionBlock)(UIImage *image, PGCameraShotMetadata *metadata);
|
||||
|
||||
@end
|
||||
|
||||
@implementation PGCamera
|
||||
@ -367,48 +372,26 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
|
||||
{
|
||||
bool videoMirrored = !self.disableResultMirroring ? _previewView.captureConnection.videoMirrored : false;
|
||||
|
||||
[[PGCameraCaptureSession cameraQueue] dispatch:^
|
||||
{
|
||||
if (!self.captureSession.isRunning || self.captureSession.imageOutput.isCapturingStillImage || _invalidated)
|
||||
return;
|
||||
|
||||
void (^takePhoto)(void) = ^
|
||||
{
|
||||
self.photoCaptureCompletionBlock = completion;
|
||||
[[PGCameraCaptureSession cameraQueue] dispatch:^
|
||||
{
|
||||
if (!self.captureSession.isRunning || _invalidated)
|
||||
return;
|
||||
|
||||
AVCaptureConnection *imageConnection = [self.captureSession.imageOutput connectionWithMediaType:AVMediaTypeVideo];
|
||||
[imageConnection setVideoMirrored:videoMirrored];
|
||||
|
||||
UIInterfaceOrientation orientation = UIInterfaceOrientationPortrait;
|
||||
if (self.requestedCurrentInterfaceOrientation != nil)
|
||||
orientation = self.requestedCurrentInterfaceOrientation(NULL);
|
||||
|
||||
[imageConnection setVideoOrientation:[PGCamera _videoOrientationForInterfaceOrientation:orientation mirrored:false]];
|
||||
|
||||
[self.captureSession.imageOutput captureStillImageAsynchronouslyFromConnection:self.captureSession.imageOutput.connections.firstObject completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
|
||||
{
|
||||
if (imageDataSampleBuffer != NULL && error == nil)
|
||||
{
|
||||
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
|
||||
UIImage *image = [[UIImage alloc] initWithData:imageData];
|
||||
_currentPhotoOrientation = orientation;
|
||||
|
||||
if (self.cameraMode == PGCameraModeSquarePhoto || self.cameraMode == PGCameraModeSquareVideo || self.cameraMode == PGCameraModeSquareSwing)
|
||||
{
|
||||
CGFloat shorterSide = MIN(image.size.width, image.size.height);
|
||||
CGFloat longerSide = MAX(image.size.width, image.size.height);
|
||||
|
||||
CGRect cropRect = CGRectMake(CGFloor((longerSide - shorterSide) / 2.0f), 0, shorterSide, shorterSide);
|
||||
CGImageRef croppedCGImage = CGImageCreateWithImageInRect(image.CGImage, cropRect);
|
||||
image = [UIImage imageWithCGImage:croppedCGImage scale:image.scale orientation:image.imageOrientation];
|
||||
CGImageRelease(croppedCGImage);
|
||||
}
|
||||
|
||||
PGCameraShotMetadata *metadata = [[PGCameraShotMetadata alloc] init];
|
||||
metadata.deviceAngle = [PGCameraShotMetadata relativeDeviceAngleFromAngle:_deviceAngleSampler.currentDeviceAngle orientation:orientation];
|
||||
|
||||
image = [self normalizeImageOrientation:image];
|
||||
|
||||
if (completion != nil)
|
||||
completion(image, metadata);
|
||||
}
|
||||
AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettings];
|
||||
[self.captureSession.imageOutput capturePhotoWithSettings:photoSettings delegate:self];
|
||||
}];
|
||||
};
|
||||
|
||||
@ -417,7 +400,29 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
|
||||
takePhoto();
|
||||
else
|
||||
TGDispatchAfter(0.4 - delta, [[PGCameraCaptureSession cameraQueue] _dispatch_queue], takePhoto);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error {
|
||||
if (error) {
|
||||
NSLog(@"Error capturing photo: %@", error);
|
||||
return;
|
||||
}
|
||||
|
||||
NSData *photoData = [photo fileDataRepresentation];
|
||||
UIImage *capturedImage = [UIImage imageWithData:photoData];
|
||||
|
||||
PGCameraShotMetadata *metadata = [[PGCameraShotMetadata alloc] init];
|
||||
metadata.deviceAngle = [PGCameraShotMetadata relativeDeviceAngleFromAngle:_deviceAngleSampler.currentDeviceAngle orientation:_currentPhotoOrientation];
|
||||
|
||||
UIImage *image = [self normalizeImageOrientation:capturedImage];
|
||||
|
||||
TGDispatchOnMainThread(^
|
||||
{
|
||||
if (self.photoCaptureCompletionBlock != nil) {
|
||||
self.photoCaptureCompletionBlock(image, metadata);
|
||||
self.photoCaptureCompletionBlock = nil;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)startVideoRecordingForMoment:(bool)moment completion:(void (^)(NSURL *, CGAffineTransform transform, CGSize dimensions, NSTimeInterval duration, bool success))completion
|
||||
|
||||
@ -130,8 +130,10 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
[self setFrameRate:PGCameraFrameRate forDevice:_videoDevice];
|
||||
}
|
||||
|
||||
AVCaptureStillImageOutput *imageOutput = [[AVCaptureStillImageOutput alloc] init];
|
||||
[imageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
|
||||
AVCapturePhotoOutput *imageOutput = [[AVCapturePhotoOutput alloc] init];
|
||||
if (@available(iOS 13.0, *)) {
|
||||
[imageOutput setMaxPhotoQualityPrioritization:AVCapturePhotoQualityPrioritizationBalanced];
|
||||
}
|
||||
if ([self canAddOutput:imageOutput])
|
||||
{
|
||||
#if !TARGET_IPHONE_SIMULATOR
|
||||
|
||||
@ -595,6 +595,14 @@ NSString *suffix = @"";
|
||||
return @"iPhone 14 Pro";
|
||||
if ([platform isEqualToString:@"iPhone15,3"])
|
||||
return @"iPhone 14 Pro Max";
|
||||
if ([platform isEqualToString:@"iPhone15,4"])
|
||||
return @"iPhone 15";
|
||||
if ([platform isEqualToString:@"iPhone15,5"])
|
||||
return @"iPhone 15 Plus";
|
||||
if ([platform isEqualToString:@"iPhone16,1"])
|
||||
return @"iPhone 15 Pro";
|
||||
if ([platform isEqualToString:@"iPhone16,2"])
|
||||
return @"iPhone 15 Pro Max";
|
||||
|
||||
if ([platform hasPrefix:@"iPod1"])
|
||||
return @"iPod touch 1G";
|
||||
|
||||
@ -723,8 +723,10 @@ final class LocalizationListControllerNode: ViewControllerTracingNode {
|
||||
}
|
||||
strongSelf.applyingCode.set(.single(info.languageCode))
|
||||
strongSelf.applyDisposable.set((strongSelf.context.engine.localization.downloadAndApplyLocalization(accountManager: strongSelf.context.sharedContext.accountManager, languageCode: info.languageCode)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
|> deliverOnMainQueue).start(completed: { [weak self] in
|
||||
self?.applyingCode.set(.single(nil))
|
||||
|
||||
self?.context.engine.messages.refreshAttachMenuBots()
|
||||
}))
|
||||
}
|
||||
if info.isOfficial {
|
||||
|
||||
@ -523,6 +523,10 @@ public extension TelegramEngine {
|
||||
return _internal_invokeBotCustomMethod(postbox: self.account.postbox, network: self.account.network, botId: botId, method: method, params: params)
|
||||
}
|
||||
|
||||
public func refreshAttachMenuBots() {
|
||||
let _ = managedSynchronizeAttachMenuBots(accountPeerId: self.account.peerId, postbox: self.account.postbox, network: self.account.network, force: true).startStandalone()
|
||||
}
|
||||
|
||||
public func addBotToAttachMenu(botId: PeerId, allowWrite: Bool) -> Signal<Bool, AddBotToAttachMenuError> {
|
||||
return _internal_addBotToAttachMenu(accountPeerId: self.account.peerId, postbox: self.account.postbox, network: self.account.network, botId: botId, allowWrite: allowWrite)
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
|
||||
private let bottomSeparatorNode: ASDisplayNode
|
||||
private let activateArea: AccessibilityAreaNode
|
||||
|
||||
private var iconDisposable: Disposable?
|
||||
private var iconDisposable = MetaDisposable()
|
||||
|
||||
private var item: PeerInfoScreenDisclosureItem?
|
||||
|
||||
@ -115,7 +115,7 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.iconDisposable?.dispose()
|
||||
self.iconDisposable.dispose()
|
||||
}
|
||||
|
||||
override func update(width: CGFloat, safeInsets: UIEdgeInsets, presentationData: PresentationData, item: PeerInfoScreenItem, topItem: PeerInfoScreenItem?, bottomItem: PeerInfoScreenItem?, hasCorners: Bool, transition: ContainedViewLayoutTransition) -> CGFloat {
|
||||
@ -169,12 +169,12 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
|
||||
} else if let iconSignal = item.iconSignal {
|
||||
if previousItem?.text != item.text {
|
||||
self.iconNode.image = nil
|
||||
self.iconDisposable = (iconSignal
|
||||
self.iconDisposable.set((iconSignal
|
||||
|> deliverOnMainQueue).startStrict(next: { [weak self] icon in
|
||||
if let self {
|
||||
self.iconNode.image = icon
|
||||
}
|
||||
})
|
||||
}))
|
||||
}
|
||||
iconSize = CGSize(width: 29.0, height: 29.0)
|
||||
} else {
|
||||
|
||||
@ -826,7 +826,7 @@ private func settingsItems(data: PeerInfoScreenData?, context: AccountContext, p
|
||||
} else {
|
||||
iconSignal = .single(UIImage(bundleImageName: "Settings/Menu/Websites")!)
|
||||
}
|
||||
items[.apps]!.append(PeerInfoScreenDisclosureItem(id: bot.peer.id.id._internalGetInt64Value(), text: bot.peer.compactDisplayTitle, icon: nil, iconSignal: iconSignal, action: {
|
||||
items[.apps]!.append(PeerInfoScreenDisclosureItem(id: bot.peer.id.id._internalGetInt64Value(), text: bot.shortName, icon: nil, iconSignal: iconSignal, action: {
|
||||
interaction.openBotApp(bot)
|
||||
}))
|
||||
appIndex += 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user