mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +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 {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user