diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/PGCameraCaptureSession.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/PGCameraCaptureSession.h index ab241977cb..ee08d0cb83 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/PGCameraCaptureSession.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/PGCameraCaptureSession.h @@ -4,6 +4,7 @@ @class PGCameraMovieWriter; @class PGRectangleDetector; +@class SQueue; @interface PGCameraCaptureSession : AVCaptureSession @@ -65,4 +66,6 @@ + (bool)_isZoomAvailableForDevice:(AVCaptureDevice *)device; ++ (SQueue *)cameraQueue; + @end diff --git a/submodules/LegacyComponents/Sources/PGCamera.m b/submodules/LegacyComponents/Sources/PGCamera.m index af30b63446..446282eb11 100644 --- a/submodules/LegacyComponents/Sources/PGCamera.m +++ b/submodules/LegacyComponents/Sources/PGCamera.m @@ -120,7 +120,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; TGLegacyLog(@"ERROR: Camera runtime error: %@", notification.userInfo[AVCaptureSessionErrorKey]); __weak PGCamera *weakSelf = self; - TGDispatchAfter(1.5f, [PGCamera cameraQueue]._dispatch_queue, ^ + TGDispatchAfter(1.5f, [PGCameraCaptureSession cameraQueue]._dispatch_queue, ^ { __strong PGCamera *strongSelf = weakSelf; if (strongSelf == nil || strongSelf->_invalidated) @@ -198,7 +198,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; [previewView setupWithCamera:self]; __weak PGCamera *weakSelf = self; - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { __strong PGCamera *strongSelf = weakSelf; if (strongSelf == nil || strongSelf->_invalidated) @@ -225,7 +225,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (_invalidated) return; - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.captureSession.isRunning) return; @@ -261,10 +261,11 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; TGLegacyLog(@"Camera: stop capture"); - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (_invalidated) { +#if !TARGET_IPHONE_SIMULATOR [self.captureSession beginConfiguration]; [self.captureSession resetFlashMode]; @@ -279,16 +280,21 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; for (AVCaptureOutput *output in self.captureSession.outputs) [self.captureSession removeOutput:output]; -#if !TARGET_IPHONE_SIMULATOR [self.captureSession commitConfiguration]; #endif } TGLegacyLog(@"Camera: stop running"); #if !TARGET_IPHONE_SIMULATOR - [self.captureSession stopRunning]; + @try { + [self.captureSession stopRunning]; + } @catch (NSException *exception) { + TGLegacyLog(@"Camera: caught exception – %@", exception.description); + [self.captureSession commitConfiguration]; + [self.captureSession stopRunning]; + TGLegacyLog(@"Camera: seems to be successfully resolved"); + } #endif - _capturing = false; TGDispatchOnMainThread(^ @@ -328,9 +334,9 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; }; if (synchronous) - [[PGCamera cameraQueue] dispatchSync:block]; + [[PGCameraCaptureSession cameraQueue] dispatchSync:block]; else - [[PGCamera cameraQueue] dispatch:block]; + [[PGCameraCaptureSession cameraQueue] dispatch:block]; } #pragma mark - @@ -361,7 +367,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; { bool videoMirrored = !self.disableResultMirroring ? _previewView.captureConnection.videoMirrored : false; - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (!self.captureSession.isRunning || self.captureSession.imageOutput.isCapturingStillImage || _invalidated) return; @@ -410,13 +416,13 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (CFAbsoluteTimeGetCurrent() - _captureStartTime > 0.4) takePhoto(); else - TGDispatchAfter(0.4 - delta, [[PGCamera cameraQueue] _dispatch_queue], takePhoto); + TGDispatchAfter(0.4 - delta, [[PGCameraCaptureSession cameraQueue] _dispatch_queue], takePhoto); }]; } - (void)startVideoRecordingForMoment:(bool)moment completion:(void (^)(NSURL *, CGAffineTransform transform, CGSize dimensions, NSTimeInterval duration, bool success))completion { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (!self.captureSession.isRunning || _invalidated) return; @@ -443,7 +449,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (CFAbsoluteTimeGetCurrent() - _captureStartTime > 1.5) startRecording(); else - TGDispatchAfter(1.5, [[PGCamera cameraQueue] _dispatch_queue], startRecording); + TGDispatchAfter(1.5, [[PGCameraCaptureSession cameraQueue] _dispatch_queue], startRecording); TGDispatchOnMainThread(^ { @@ -455,7 +461,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)stopVideoRecording { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { [self.captureSession stopVideoRecording]; @@ -496,7 +502,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (strongSelf == nil) return; - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { strongSelf.captureSession.currentMode = cameraMode; @@ -584,7 +590,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)_setFocusPoint:(CGPoint)point focusMode:(AVCaptureFocusMode)focusMode exposureMode:(AVCaptureExposureMode)exposureMode monitorSubjectAreaChange:(bool)monitorSubjectAreaChange { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.disabled) return; @@ -600,7 +606,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)beginExposureTargetBiasChange { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.disabled) return; @@ -611,7 +617,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)setExposureTargetBias:(CGFloat)bias { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.disabled) return; @@ -622,7 +628,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)endExposureTargetBiasChange { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.disabled) return; @@ -661,7 +667,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)setFlashMode:(PGCameraFlashMode)flashMode { - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { self.captureSession.currentFlashMode = flashMode; }]; @@ -689,7 +695,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (strongSelf == nil) return; - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { [strongSelf.captureSession setCurrentCameraPosition:targetCameraPosition]; @@ -744,7 +750,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; if (self.cameraMode == PGCameraModeVideo) { animated = false; } - [[PGCamera cameraQueue] dispatch:^ + [[PGCameraCaptureSession cameraQueue] dispatch:^ { if (self.disabled) return; @@ -786,18 +792,6 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; return ([PGCameraCaptureSession _deviceWithCameraPosition:PGCameraPositionFront] != nil); } -+ (SQueue *)cameraQueue -{ - static dispatch_once_t onceToken; - static SQueue *queue = nil; - dispatch_once(&onceToken, ^ - { - queue = [[SQueue alloc] init]; - }); - - return queue; -} - + (AVCaptureVideoOrientation)_videoOrientationForInterfaceOrientation:(UIInterfaceOrientation)deviceOrientation mirrored:(bool)mirrored { switch (deviceOrientation) diff --git a/submodules/LegacyComponents/Sources/PGCameraCaptureSession.m b/submodules/LegacyComponents/Sources/PGCameraCaptureSession.m index 7d8814b37b..e071d81116 100644 --- a/submodules/LegacyComponents/Sources/PGCameraCaptureSession.m +++ b/submodules/LegacyComponents/Sources/PGCameraCaptureSession.m @@ -208,6 +208,7 @@ const NSInteger PGCameraFrameRate = 30; - (void)reset { + NSAssert([[PGCameraCaptureSession cameraQueue] isCurrentQueue], @"[[PGCameraCaptureSession cameraQueue] isCurrentQueue]"); [self beginConfiguration]; [self _removeAudioInputEndAudioSession:true]; @@ -259,6 +260,8 @@ const NSInteger PGCameraFrameRate = 30; - (void)setCurrentMode:(PGCameraMode)mode { + NSAssert([[PGCameraCaptureSession cameraQueue] isCurrentQueue], @"[[PGCameraCaptureSession cameraQueue] isCurrentQueue]"); + _currentMode = mode; [self beginConfiguration]; @@ -804,6 +807,7 @@ const NSInteger PGCameraFrameRate = 30; - (void)setCurrentCameraPosition:(PGCameraPosition)position { + NSAssert([[PGCameraCaptureSession cameraQueue] isCurrentQueue], @"[[PGCameraCaptureSession cameraQueue] isCurrentQueue]"); AVCaptureDevice *deviceForTargetPosition = [PGCameraCaptureSession _deviceWithCameraPosition:position]; if ([_videoDevice isEqual:deviceForTargetPosition]) return; @@ -1123,4 +1127,18 @@ static UIImageOrientation TGSnapshotOrientationForVideoOrientation(bool mirrored } } +#pragma mark - + ++ (SQueue *)cameraQueue +{ + static dispatch_once_t onceToken; + static SQueue *queue = nil; + dispatch_once(&onceToken, ^ + { + queue = [[SQueue alloc] init]; + }); + + return queue; +} + @end diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index 77098e8839..02b181312a 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -425,7 +425,6 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } strongSelf.presentationData = presentationData - strongSelf.nativeNode.updateBubbleTheme(bubbleTheme: presentationData.theme, bubbleCorners: presentationData.chatBubbleCorners) if let (layout, _) = strongSelf.validLayout { strongSelf.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .animated(duration: 0.3, curve: .easeInOut)) @@ -533,7 +532,9 @@ final class WallpaperGalleryItemNode: GalleryItemNode { switch entry { case let .wallpaper(wallpaper, _): - self.nativeNode.update(wallpaper: wallpaper) + Queue.mainQueue().justDispatch { + self.nativeNode.update(wallpaper: wallpaper) + } if case let .file(file) = wallpaper, file.isPattern { self.nativeNode.isHidden = false @@ -559,15 +560,14 @@ final class WallpaperGalleryItemNode: GalleryItemNode { self.nativeNode.update(wallpaper: wallpaper) self.patternButtonNode.isSelected = false } else { + self.nativeNode._internalUpdateIsSettingUpWallpaper() self.nativeNode.isHidden = true self.patternButtonNode.isSelected = false self.playButtonNode.setIcon(self.playButtonRotateImage) } case .asset: self.nativeNode._internalUpdateIsSettingUpWallpaper() - - //self.nativeNode.update(wallpaper: .color(0xff000000)) - self.nativeNode.isHidden = false + self.nativeNode.isHidden = true self.patternButtonNode.isSelected = false self.playButtonNode.setIcon(self.playButtonRotateImage) default: @@ -1322,6 +1322,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } private func updateMessagesLayout(layout: ContainerViewLayout, offset: CGPoint, transition: ContainedViewLayoutTransition) { + self.nativeNode.updateBubbleTheme(bubbleTheme: self.presentationData.theme, bubbleCorners: self.presentationData.chatBubbleCorners) + var bottomInset: CGFloat = 132.0 var items: [ListViewItem] = [] @@ -1468,7 +1470,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { if let _ = serviceMessageText, let messageNodes = self.messageNodes, let node = messageNodes.last { if let backgroundNode = node.subnodes?.first?.subnodes?.first?.subnodes?.first?.subnodes?.first, let backdropNode = node.subnodes?.first?.subnodes?.first?.subnodes?.first?.subnodes?.last?.subnodes?.last?.subnodes?.first { - backdropNode.isHidden = true + backdropNode.isHidden = true let serviceBackgroundFrame = backgroundNode.view.convert(backgroundNode.bounds, to: self.view).offsetBy(dx: 0.0, dy: -1.0).insetBy(dx: 0.0, dy: -1.0) transition.updateFrame(node: self.serviceBackgroundNode, frame: serviceBackgroundFrame) self.serviceBackgroundNode.update(size: serviceBackgroundFrame.size, cornerRadius: serviceBackgroundFrame.height / 2.0, transition: transition) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift index ab8bc1b3b4..88335906e7 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift @@ -423,7 +423,6 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { func setEnabled(_ enabled: Bool) { let alpha: CGFloat = enabled ? 1.0 : 0.4 - self.backgroundNode.alpha = alpha self.checkNode.alpha = alpha self.colorNode.alpha = alpha self.textNode.alpha = alpha diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift index f7be6abafd..b81a8f26f3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift @@ -164,6 +164,10 @@ func _internal_setExistingChatWallpaper(account: Account, messageId: MessageId, return account.postbox.transaction { transaction -> Peer? in if let peer = transaction.getPeer(messageId.peerId), let message = transaction.getMessage(messageId) { if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case let .setChatWallpaper(wallpaper) = action.action { + var wallpaper = wallpaper + if let settings = settings { + wallpaper = wallpaper.withUpdatedSettings(settings) + } transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in if let current = current as? CachedUserData { return current.withUpdatedWallpaper(wallpaper) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 710f40a519..186396ff83 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -858,11 +858,18 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } strongSelf.chatDisplayNode.dismissInput() let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, nil, [], nil, nil, nil), mode: .peer(EnginePeer(peer), true)) - wallpaperPreviewController.apply = { wallpaper, options, _, _ in - let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: nil) - |> deliverOnMainQueue).start(completed: { [weak wallpaperPreviewController] in - wallpaperPreviewController?.dismiss() - }) + wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _ in + if case let .wallpaper(wallpaper, _) = entry, case let .file(file) = wallpaper, !file.isPattern && options.contains(.blur) { + uploadCustomPeerWallpaper(context: strongSelf.context, wallpaper: entry, mode: options, cropRect: nil, brightness: nil, peerId: message.id.peerId, completion: { + wallpaperPreviewController?.dismiss() + }) + } else { + let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: nil) + |> deliverOnMainQueue).start() + Queue.mainQueue().after(0.1) { + wallpaperPreviewController?.dismiss() + } + } } strongSelf.push(wallpaperPreviewController) return true @@ -5861,7 +5868,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var themeEmoticon = themeEmoticon if let themeEmoticonPreview = themeEmoticonPreview { if !themeEmoticonPreview.isEmpty { - if themeEmoticon != themeEmoticonPreview { + if themeEmoticon?.strippedEmoji != themeEmoticonPreview.strippedEmoji { chatWallpaper = nil themeEmoticon = themeEmoticonPreview } diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index af8c9bc9f0..230b208e50 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -864,6 +864,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode self.bakedBackgroundView.isHidden = true self.dimLayer = SimpleLayer() + self.dimLayer.opacity = 0.0 self.dimLayer.backgroundColor = UIColor.black.cgColor super.init() @@ -904,8 +905,19 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode return } var dimAlpha: Float = 0.0 - if case let .file(file) = wallpaper, !file.isPattern { - if let intensity = file.settings.intensity, intensity < 100, theme.overallDarkAppearance == true { + if theme.overallDarkAppearance == true { + var intensity: Int32? + switch wallpaper { + case let .image(_, settings): + intensity = settings.intensity + case let .file(file): + if !file.isPattern { + intensity = file.settings.intensity + } + default: + break + } + if let intensity, intensity < 100 { dimAlpha = 1.0 - max(0.0, min(1.0, Float(intensity) / 100.0)) } } diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 5cf2e4f506..b85cdf200d 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -258,7 +258,7 @@ public func wallpaperImage(account: Account, accountManager: AccountManager