From e84013727abab654b2c0eff73c208e75321ffbef Mon Sep 17 00:00:00 2001 From: Max Radermacher Date: Thu, 13 Nov 2025 14:53:28 -0600 Subject: [PATCH] Remove appForegroundTime property --- Signal/AppLaunch/MainAppContext.swift | 4 --- .../StoryPageViewController.swift | 26 +++++++++++-------- SignalNSE/NSEContext.swift | 2 -- .../TestUtils/TestAppContext.swift | 2 -- SignalServiceKit/Util/AppContext.swift | 3 --- .../ShareAppExtensionContext.swift | 2 -- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Signal/AppLaunch/MainAppContext.swift b/Signal/AppLaunch/MainAppContext.swift index ff59608641..5553cfa045 100644 --- a/Signal/AppLaunch/MainAppContext.swift +++ b/Signal/AppLaunch/MainAppContext.swift @@ -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) diff --git a/Signal/src/ViewControllers/HomeView/Stories/Context View/StoryPageViewController.swift b/Signal/src/ViewControllers/HomeView/Stories/Context View/StoryPageViewController.swift index 55fbedcf70..6e9498df8f 100644 --- a/Signal/src/ViewControllers/HomeView/Stories/Context View/StoryPageViewController.swift +++ b/Signal/src/ViewControllers/HomeView/Stories/Context View/StoryPageViewController.swift @@ -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() diff --git a/SignalNSE/NSEContext.swift b/SignalNSE/NSEContext.swift index 6c4c6452e3..b374b5f4d6 100644 --- a/SignalNSE/NSEContext.swift +++ b/SignalNSE/NSEContext.swift @@ -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 { diff --git a/SignalServiceKit/TestUtils/TestAppContext.swift b/SignalServiceKit/TestUtils/TestAppContext.swift index 8e995bf73c..456f5c8caf 100644 --- a/SignalServiceKit/TestUtils/TestAppContext.swift +++ b/SignalServiceKit/TestUtils/TestAppContext.swift @@ -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() } diff --git a/SignalServiceKit/Util/AppContext.swift b/SignalServiceKit/Util/AppContext.swift index 0b02888cc0..e43084fce4 100644 --- a/SignalServiceKit/Util/AppContext.swift +++ b/SignalServiceKit/Util/AppContext.swift @@ -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 diff --git a/SignalShareExtension/ShareAppExtensionContext.swift b/SignalShareExtension/ShareAppExtensionContext.swift index 5fcce86c61..25d805d56c 100644 --- a/SignalShareExtension/ShareAppExtensionContext.swift +++ b/SignalShareExtension/ShareAppExtensionContext.swift @@ -16,8 +16,6 @@ final class ShareAppExtensionContext: NSObject { let appLaunchTime = Date() - let appForegroundTime = Date() - private var notificationCenterObservers = [NSObjectProtocol]() static private let isRTL: Bool = {