Fixes #2707 - Prevent the app from locking while recording a voice message

This commit is contained in:
Stefan Ceriu
2024-04-19 17:25:43 +03:00
committed by Stefan Ceriu
parent effe3b6a9b
commit 1e810f91ff
5 changed files with 81 additions and 29 deletions
+23 -19
View File
@@ -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 {