mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Fixes #2707 - Prevent the app from locking while recording a voice message
This commit is contained in:
parent
effe3b6a9b
commit
1e810f91ff
@ -18,14 +18,32 @@ import UIKit
|
||||
|
||||
class AppMediator: AppMediatorProtocol {
|
||||
private let windowManager: WindowManagerProtocol
|
||||
|
||||
init(windowManager: WindowManagerProtocol) {
|
||||
self.windowManager = windowManager
|
||||
}
|
||||
|
||||
// UIApplication.State won't update if we store this e.g. in the constructor
|
||||
private var application: UIApplication {
|
||||
UIApplication.shared
|
||||
}
|
||||
|
||||
@MainActor
|
||||
var appState: UIApplication.State {
|
||||
switch application.applicationState {
|
||||
case .active:
|
||||
windowManager.mainWindow.traitCollection.activeAppearance == .active ? .active : .inactive
|
||||
case .inactive:
|
||||
.inactive
|
||||
case .background:
|
||||
.background
|
||||
default:
|
||||
.inactive
|
||||
}
|
||||
}
|
||||
|
||||
init(windowManager: WindowManagerProtocol) {
|
||||
self.windowManager = windowManager
|
||||
var backgroundTimeRemaining: TimeInterval {
|
||||
application.backgroundTimeRemaining
|
||||
}
|
||||
|
||||
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier {
|
||||
@ -47,22 +65,8 @@ class AppMediator: AppMediatorProtocol {
|
||||
|
||||
open(url)
|
||||
}
|
||||
|
||||
var backgroundTimeRemaining: TimeInterval {
|
||||
application.backgroundTimeRemaining
|
||||
}
|
||||
|
||||
@MainActor
|
||||
var appState: UIApplication.State {
|
||||
switch application.applicationState {
|
||||
case .active:
|
||||
windowManager.mainWindow.traitCollection.activeAppearance == .active ? .active : .inactive
|
||||
case .inactive:
|
||||
.inactive
|
||||
case .background:
|
||||
.background
|
||||
default:
|
||||
.inactive
|
||||
}
|
||||
|
||||
func setIdleTimerDisabled(_ disabled: Bool) {
|
||||
application.isIdleTimerDisabled = disabled
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ import UIKit
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol AppMediatorProtocol {
|
||||
var appState: UIApplication.State { get }
|
||||
|
||||
var backgroundTimeRemaining: TimeInterval { get }
|
||||
|
||||
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
|
||||
|
||||
func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)
|
||||
@ -26,10 +30,8 @@ protocol AppMediatorProtocol {
|
||||
func open(_ url: URL)
|
||||
|
||||
func openAppSettings()
|
||||
|
||||
var backgroundTimeRemaining: TimeInterval { get }
|
||||
|
||||
var appState: UIApplication.State { get }
|
||||
|
||||
func setIdleTimerDisabled(_ disabled: Bool)
|
||||
}
|
||||
|
||||
extension UIApplication.State: CustomStringConvertible {
|
||||
|
@ -748,16 +748,16 @@ class AppLockServiceMock: AppLockServiceProtocol {
|
||||
}
|
||||
}
|
||||
class AppMediatorMock: AppMediatorProtocol {
|
||||
var backgroundTimeRemaining: TimeInterval {
|
||||
get { return underlyingBackgroundTimeRemaining }
|
||||
set(value) { underlyingBackgroundTimeRemaining = value }
|
||||
}
|
||||
var underlyingBackgroundTimeRemaining: TimeInterval!
|
||||
var appState: UIApplication.State {
|
||||
get { return underlyingAppState }
|
||||
set(value) { underlyingAppState = value }
|
||||
}
|
||||
var underlyingAppState: UIApplication.State!
|
||||
var backgroundTimeRemaining: TimeInterval {
|
||||
get { return underlyingBackgroundTimeRemaining }
|
||||
set(value) { underlyingBackgroundTimeRemaining = value }
|
||||
}
|
||||
var underlyingBackgroundTimeRemaining: TimeInterval!
|
||||
|
||||
//MARK: - beginBackgroundTask
|
||||
|
||||
@ -936,6 +936,45 @@ class AppMediatorMock: AppMediatorProtocol {
|
||||
openAppSettingsCallsCount += 1
|
||||
openAppSettingsClosure?()
|
||||
}
|
||||
//MARK: - setIdleTimerDisabled
|
||||
|
||||
var setIdleTimerDisabledUnderlyingCallsCount = 0
|
||||
var setIdleTimerDisabledCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return setIdleTimerDisabledUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = setIdleTimerDisabledUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
setIdleTimerDisabledUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
setIdleTimerDisabledUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var setIdleTimerDisabledCalled: Bool {
|
||||
return setIdleTimerDisabledCallsCount > 0
|
||||
}
|
||||
var setIdleTimerDisabledReceivedDisabled: Bool?
|
||||
var setIdleTimerDisabledReceivedInvocations: [Bool] = []
|
||||
var setIdleTimerDisabledClosure: ((Bool) -> Void)?
|
||||
|
||||
func setIdleTimerDisabled(_ disabled: Bool) {
|
||||
setIdleTimerDisabledCallsCount += 1
|
||||
setIdleTimerDisabledReceivedDisabled = disabled
|
||||
setIdleTimerDisabledReceivedInvocations.append(disabled)
|
||||
setIdleTimerDisabledClosure?(disabled)
|
||||
}
|
||||
}
|
||||
class AudioConverterMock: AudioConverterProtocol {
|
||||
|
||||
|
@ -50,7 +50,12 @@ class RoomScreenInteractionHandler {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private var voiceMessageRecorderObserver: AnyCancellable?
|
||||
private var voiceMessageRecorderObserver: AnyCancellable? {
|
||||
didSet {
|
||||
appMediator.setIdleTimerDisabled(voiceMessageRecorderObserver != nil)
|
||||
}
|
||||
}
|
||||
|
||||
private var canCurrentUserRedactOthers = false
|
||||
private var canCurrentUserRedactSelf = false
|
||||
private var resumeVoiceMessagePlaybackAfterScrubbing = false
|
||||
@ -405,6 +410,7 @@ class RoomScreenInteractionHandler {
|
||||
|
||||
func stopRecordingVoiceMessage() async {
|
||||
await voiceMessageRecorder.stopRecording()
|
||||
voiceMessageRecorderObserver = nil
|
||||
}
|
||||
|
||||
func cancelRecordingVoiceMessage() async {
|
||||
|
1
changelog.d/2707.change
Normal file
1
changelog.d/2707.change
Normal file
@ -0,0 +1 @@
|
||||
Prevent the app from locking while recording a voice message
|
Loading…
x
Reference in New Issue
Block a user