Remove appForegroundTime property

This commit is contained in:
Max Radermacher 2025-11-13 14:53:28 -06:00 committed by GitHub
parent faf4618355
commit e84013727a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 24 deletions

View File

@ -11,14 +11,11 @@ class MainAppContext: NSObject, AppContext {
let appLaunchTime: Date
private(set) var appForegroundTime: Date
override init() {
_reportedApplicationState = AtomicValue(.inactive, lock: .init())
let launchDate = Date()
appLaunchTime = launchDate
appForegroundTime = launchDate
_mainApplicationStateOnLaunch = UIApplication.shared.applicationState
super.init()
@ -68,7 +65,6 @@ class MainAppContext: NSObject, AppContext {
AssertIsOnMainThread()
self.reportedApplicationState = .inactive
self.appForegroundTime = Date()
BenchManager.bench(title: "Slow WillEnterForeground", logIfLongerThan: 0.2, logInProduction: true) {
NotificationCenter.default.post(name: .OWSApplicationWillEnterForeground, object: nil)

View File

@ -183,28 +183,33 @@ class StoryPageViewController: UIPageViewController {
private struct MuteStatus {
let isMuted: Bool
let shouldInitialRingerStateSetMuteState: Bool
let appForegroundTime: Date
}
// Once unmuted, stays that way until the app is backgrounded.
private static var muteStatus: MuteStatus?
private static var muteStatus: MuteStatus? {
didSet {
if muteStatus != nil, muteStatusObserver == nil {
muteStatusObserver = NotificationCenter.default.addObserver(
forName: UIApplication.willEnterForegroundNotification,
object: nil,
queue: nil,
using: { _ in muteStatus = nil },
)
}
}
}
private static var muteStatusObserver: (any NSObjectProtocol)?
private var isMuted: Bool {
get {
let appForegroundTime = CurrentAppContext().appForegroundTime
if
let muteStatus = Self.muteStatus,
// Mute status is only valid for one foregroundind session,
// dedupe by timestamp.
muteStatus.appForegroundTime == appForegroundTime
{
if let muteStatus = Self.muteStatus {
return muteStatus.isMuted
}
// Start muted, but let the ringer change the setting.
let muteStatus = MuteStatus(
isMuted: true,
shouldInitialRingerStateSetMuteState: true,
appForegroundTime: CurrentAppContext().appForegroundTime
)
Self.muteStatus = muteStatus
return muteStatus.isMuted
@ -213,7 +218,6 @@ class StoryPageViewController: UIPageViewController {
Self.muteStatus = MuteStatus(
isMuted: newValue,
shouldInitialRingerStateSetMuteState: false,
appForegroundTime: CurrentAppContext().appForegroundTime
)
viewControllers?.forEach {
($0 as? StoryContextViewController)?.updateMuteState()

View File

@ -19,8 +19,6 @@ class NSEContext: NSObject, AppContext {
func canPresentNotifications() -> Bool { true }
let appLaunchTime = Date()
// In NSE foreground and launch are the same.
var appForegroundTime: Date { return appLaunchTime }
func appDocumentDirectoryPath() -> String {
guard let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else {

View File

@ -24,7 +24,6 @@ public class TestAppContext: NSObject, AppContext {
public var mainWindow: UIWindow?
public let appLaunchTime: Date
public let appForegroundTime: Date
public override init() {
// Avoid using OWSTemporaryDirectory(); it can consult the current app context.
@ -41,7 +40,6 @@ public class TestAppContext: NSObject, AppContext {
self.internalAppUserDefaults = UserDefaults()
let launchDate = Date()
self.appLaunchTime = launchDate
self.appForegroundTime = launchDate
super.init()
}

View File

@ -84,9 +84,6 @@ public protocol AppContext {
var appLaunchTime: Date { get }
/// Will be updated every time the app is foregrounded.
var appForegroundTime: Date { get }
func appDocumentDirectoryPath() -> String
func appSharedDataDirectoryPath() -> String

View File

@ -16,8 +16,6 @@ final class ShareAppExtensionContext: NSObject {
let appLaunchTime = Date()
let appForegroundTime = Date()
private var notificationCenterObservers = [NSObjectProtocol]()
static private let isRTL: Bool = {