diff --git a/Modules/RSCore/Sources/RSCore/AppNotifications.swift b/Modules/RSCore/Sources/RSCore/AppNotifications.swift new file mode 100644 index 000000000..9af48e0e5 --- /dev/null +++ b/Modules/RSCore/Sources/RSCore/AppNotifications.swift @@ -0,0 +1,36 @@ +// +// Notifications.swift +// RSCore +// +// Created by Brent Simmons on 3/7/26. +// + +import Foundation +import os + +public extension Notification.Name { + + /// Posted on actual low memory condition. Posted on main thread. + static let lowMemory = Notification.Name("LowMemoryNotification") + + /// Posted when the app goes to background. Posted on main thread. + static let appDidGoToBackground = Notification.Name("AppDidGoToBackgroundNotification") +} + +private let notificationLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Notifications.swift") + +public func postLowMemoryNotification() { + NotificationCenter.default.postOnMainThread(name: .lowMemory, object: nil) +} + +public func postAppDidGoToBackgroundNotification() { + if Thread.isMainThread { + lowMemoryLogger.info("Posting app did go to background notification") + NotificationCenter.default.post(name: .appDidGoToBackground, object: nil) + } else { + Task { @MainActor in + lowMemoryLogger.info("Posting app did go to background notification") + NotificationCenter.default.post(name: .appDidGoToBackground, object: nil) + } + } +} diff --git a/Modules/RSCore/Sources/RSCore/Notifications.swift b/Modules/RSCore/Sources/RSCore/Notifications.swift deleted file mode 100644 index 80aebf504..000000000 --- a/Modules/RSCore/Sources/RSCore/Notifications.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// Notifications.swift -// RSCore -// -// Created by Brent Simmons on 3/7/26. -// - -import Foundation -import os - -public extension Notification.Name { - /// Posted when the app should free memory — on background transition - /// and potentially on memory warnings. Always posted on the main thread. - static let lowMemory = Notification.Name("LowMemoryNotification") -} - -private let lowMemoryLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "LowMemory") - -public func postLowMemoryNotification() { - if Thread.isMainThread { - lowMemoryLogger.info("Posting low memory notification") - NotificationCenter.default.post(name: .lowMemory, object: nil) - } else { - Task { @MainActor in - lowMemoryLogger.info("Posting low memory notification") - NotificationCenter.default.post(name: .lowMemory, object: nil) - } - } -}