mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Various fixes
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
import MediaEditor
|
||||
import DrawingUI
|
||||
import ChatPresentationInterfaceState
|
||||
import PresentationDataUtils
|
||||
import TelegramPresentationData
|
||||
import DeviceAccess
|
||||
import AccountContext
|
||||
|
||||
extension MediaEditorScreen {
|
||||
final class Recording {
|
||||
@@ -13,10 +16,56 @@ extension MediaEditorScreen {
|
||||
|
||||
private var recorder: EntityVideoRecorder?
|
||||
|
||||
private let idleTimerExtensionDisposable = MetaDisposable()
|
||||
|
||||
private var authorizationStatusDisposables = DisposableSet()
|
||||
private var cameraAuthorizationStatus: AccessType = .notDetermined
|
||||
private var microphoneAuthorizationStatus: AccessType = .notDetermined
|
||||
|
||||
fileprivate var cameraIsActive = true {
|
||||
didSet {
|
||||
guard let context = self.controller?.context else {
|
||||
return
|
||||
}
|
||||
if self.cameraIsActive {
|
||||
self.idleTimerExtensionDisposable.set(context.sharedContext.applicationBindings.pushIdleTimerExtension())
|
||||
} else {
|
||||
self.idleTimerExtensionDisposable.set(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isLocked = false
|
||||
|
||||
init(controller: MediaEditorScreen) {
|
||||
self.controller = controller
|
||||
|
||||
self.authorizationStatusDisposables.add((DeviceAccess.authorizationStatus(subject: .camera(.video))
|
||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||
if let self {
|
||||
self.cameraAuthorizationStatus = status
|
||||
}
|
||||
}))
|
||||
|
||||
self.authorizationStatusDisposables.add((DeviceAccess.authorizationStatus(subject: .microphone(.video))
|
||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||
if let self {
|
||||
self.microphoneAuthorizationStatus = status
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.idleTimerExtensionDisposable.dispose()
|
||||
self.authorizationStatusDisposables.dispose()
|
||||
}
|
||||
|
||||
func requestDeviceAccess() {
|
||||
DeviceAccess.authorizeAccess(to: .camera(.video), { granted in
|
||||
if granted {
|
||||
DeviceAccess.authorizeAccess(to: .microphone(.video))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func setMediaRecordingActive(_ isActive: Bool, finished: Bool, sourceView: UIView?) {
|
||||
@@ -29,8 +78,8 @@ extension MediaEditorScreen {
|
||||
}
|
||||
|
||||
if isActive {
|
||||
if controller.cameraAuthorizationStatus != .allowed || controller.microphoneAuthorizationStatus != .allowed {
|
||||
controller.requestDeviceAccess()
|
||||
if self.cameraAuthorizationStatus != .allowed || self.microphoneAuthorizationStatus != .allowed {
|
||||
self.requestDeviceAccess()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -53,6 +102,8 @@ extension MediaEditorScreen {
|
||||
}
|
||||
self.recorder = recorder
|
||||
controller.node.requestLayout(forceUpdate: true, transition: .easeInOut(duration: 0.2))
|
||||
|
||||
self.cameraIsActive = true
|
||||
} else {
|
||||
if let recorder = self.recorder {
|
||||
recorder.stopRecording(save: finished, completion: { [weak self] in
|
||||
@@ -65,6 +116,8 @@ extension MediaEditorScreen {
|
||||
})
|
||||
|
||||
controller.node.requestLayout(forceUpdate: true, transition: .easeInOut(duration: 0.2))
|
||||
|
||||
self.cameraIsActive = false
|
||||
} else {
|
||||
guard self.tooltipController == nil, let sourceView else {
|
||||
return
|
||||
|
||||
@@ -4043,11 +4043,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
private var audioSessionDisposable: Disposable?
|
||||
private let postingAvailabilityPromise = Promise<StoriesUploadAvailability>()
|
||||
private var postingAvailabilityDisposable: Disposable?
|
||||
|
||||
private var authorizationStatusDisposables = DisposableSet()
|
||||
private(set) var cameraAuthorizationStatus: AccessType = .notDetermined
|
||||
private(set) var microphoneAuthorizationStatus: AccessType = .notDetermined
|
||||
|
||||
|
||||
public init(
|
||||
context: AccountContext,
|
||||
subject: Signal<Subject?, NoError>,
|
||||
@@ -4122,20 +4118,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
if let _ = forwardSource {
|
||||
self.postingAvailabilityPromise.set(self.context.engine.messages.checkStoriesUploadAvailability(target: .myStories))
|
||||
}
|
||||
|
||||
self.authorizationStatusDisposables.add((DeviceAccess.authorizationStatus(subject: .camera(.video))
|
||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||
if let self {
|
||||
self.cameraAuthorizationStatus = status
|
||||
}
|
||||
}))
|
||||
|
||||
self.authorizationStatusDisposables.add((DeviceAccess.authorizationStatus(subject: .microphone(.video))
|
||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||
if let self {
|
||||
self.microphoneAuthorizationStatus = status
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
required public init(coder aDecoder: NSCoder) {
|
||||
@@ -4146,7 +4128,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
self.exportDisposable.dispose()
|
||||
self.audioSessionDisposable?.dispose()
|
||||
self.postingAvailabilityDisposable?.dispose()
|
||||
self.authorizationStatusDisposables.dispose()
|
||||
}
|
||||
|
||||
override public func loadDisplayNode() {
|
||||
@@ -4225,14 +4206,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
fileprivate var isEmbeddedEditor: Bool {
|
||||
return self.isEditingStory || self.forwardSource != nil
|
||||
}
|
||||
|
||||
func requestDeviceAccess() {
|
||||
DeviceAccess.authorizeAccess(to: .camera(.video), { granted in
|
||||
if granted {
|
||||
DeviceAccess.authorizeAccess(to: .microphone(.video))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func openPrivacySettings(_ privacy: MediaEditorResultPrivacy? = nil, completion: @escaping () -> Void = {}) {
|
||||
self.node.mediaEditor?.maybePauseVideo()
|
||||
|
||||
Reference in New Issue
Block a user