mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Fixes #2707 - Prevent the app from locking while recording a voice message
This commit is contained in:
committed by
Stefan Ceriu
parent
effe3b6a9b
commit
1e810f91ff
@@ -18,14 +18,32 @@ import UIKit
|
|||||||
|
|
||||||
class AppMediator: AppMediatorProtocol {
|
class AppMediator: AppMediatorProtocol {
|
||||||
private let windowManager: WindowManagerProtocol
|
private let windowManager: WindowManagerProtocol
|
||||||
|
|
||||||
|
init(windowManager: WindowManagerProtocol) {
|
||||||
|
self.windowManager = windowManager
|
||||||
|
}
|
||||||
|
|
||||||
// UIApplication.State won't update if we store this e.g. in the constructor
|
// UIApplication.State won't update if we store this e.g. in the constructor
|
||||||
private var application: UIApplication {
|
private var application: UIApplication {
|
||||||
UIApplication.shared
|
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) {
|
var backgroundTimeRemaining: TimeInterval {
|
||||||
self.windowManager = windowManager
|
application.backgroundTimeRemaining
|
||||||
}
|
}
|
||||||
|
|
||||||
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier {
|
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier {
|
||||||
@@ -47,22 +65,8 @@ class AppMediator: AppMediatorProtocol {
|
|||||||
|
|
||||||
open(url)
|
open(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundTimeRemaining: TimeInterval {
|
func setIdleTimerDisabled(_ disabled: Bool) {
|
||||||
application.backgroundTimeRemaining
|
application.isIdleTimerDisabled = disabled
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import UIKit
|
|||||||
|
|
||||||
// sourcery: AutoMockable
|
// sourcery: AutoMockable
|
||||||
protocol AppMediatorProtocol {
|
protocol AppMediatorProtocol {
|
||||||
|
var appState: UIApplication.State { get }
|
||||||
|
|
||||||
|
var backgroundTimeRemaining: TimeInterval { get }
|
||||||
|
|
||||||
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
|
func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
|
||||||
|
|
||||||
func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)
|
func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)
|
||||||
@@ -26,10 +30,8 @@ protocol AppMediatorProtocol {
|
|||||||
func open(_ url: URL)
|
func open(_ url: URL)
|
||||||
|
|
||||||
func openAppSettings()
|
func openAppSettings()
|
||||||
|
|
||||||
var backgroundTimeRemaining: TimeInterval { get }
|
func setIdleTimerDisabled(_ disabled: Bool)
|
||||||
|
|
||||||
var appState: UIApplication.State { get }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIApplication.State: CustomStringConvertible {
|
extension UIApplication.State: CustomStringConvertible {
|
||||||
|
|||||||
@@ -748,16 +748,16 @@ class AppLockServiceMock: AppLockServiceProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class AppMediatorMock: AppMediatorProtocol {
|
class AppMediatorMock: AppMediatorProtocol {
|
||||||
var backgroundTimeRemaining: TimeInterval {
|
|
||||||
get { return underlyingBackgroundTimeRemaining }
|
|
||||||
set(value) { underlyingBackgroundTimeRemaining = value }
|
|
||||||
}
|
|
||||||
var underlyingBackgroundTimeRemaining: TimeInterval!
|
|
||||||
var appState: UIApplication.State {
|
var appState: UIApplication.State {
|
||||||
get { return underlyingAppState }
|
get { return underlyingAppState }
|
||||||
set(value) { underlyingAppState = value }
|
set(value) { underlyingAppState = value }
|
||||||
}
|
}
|
||||||
var underlyingAppState: UIApplication.State!
|
var underlyingAppState: UIApplication.State!
|
||||||
|
var backgroundTimeRemaining: TimeInterval {
|
||||||
|
get { return underlyingBackgroundTimeRemaining }
|
||||||
|
set(value) { underlyingBackgroundTimeRemaining = value }
|
||||||
|
}
|
||||||
|
var underlyingBackgroundTimeRemaining: TimeInterval!
|
||||||
|
|
||||||
//MARK: - beginBackgroundTask
|
//MARK: - beginBackgroundTask
|
||||||
|
|
||||||
@@ -936,6 +936,45 @@ class AppMediatorMock: AppMediatorProtocol {
|
|||||||
openAppSettingsCallsCount += 1
|
openAppSettingsCallsCount += 1
|
||||||
openAppSettingsClosure?()
|
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 {
|
class AudioConverterMock: AudioConverterProtocol {
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,12 @@ class RoomScreenInteractionHandler {
|
|||||||
actionsSubject.eraseToAnyPublisher()
|
actionsSubject.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var voiceMessageRecorderObserver: AnyCancellable?
|
private var voiceMessageRecorderObserver: AnyCancellable? {
|
||||||
|
didSet {
|
||||||
|
appMediator.setIdleTimerDisabled(voiceMessageRecorderObserver != nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var canCurrentUserRedactOthers = false
|
private var canCurrentUserRedactOthers = false
|
||||||
private var canCurrentUserRedactSelf = false
|
private var canCurrentUserRedactSelf = false
|
||||||
private var resumeVoiceMessagePlaybackAfterScrubbing = false
|
private var resumeVoiceMessagePlaybackAfterScrubbing = false
|
||||||
@@ -405,6 +410,7 @@ class RoomScreenInteractionHandler {
|
|||||||
|
|
||||||
func stopRecordingVoiceMessage() async {
|
func stopRecordingVoiceMessage() async {
|
||||||
await voiceMessageRecorder.stopRecording()
|
await voiceMessageRecorder.stopRecording()
|
||||||
|
voiceMessageRecorderObserver = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cancelRecordingVoiceMessage() async {
|
func cancelRecordingVoiceMessage() async {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Prevent the app from locking while recording a voice message
|
||||||
Reference in New Issue
Block a user