Log whether a notification is expected to make a noise. (#3782)

* Log whether a notification is expected to make a noise.

* Also log the system notification sound setting too.
This commit is contained in:
Doug
2025-02-11 09:59:46 +00:00
committed by GitHub
parent 8680d8437b
commit f6a1d38972
5 changed files with 74 additions and 1 deletions
@@ -17099,6 +17099,70 @@ class UserNotificationCenterMock: UserNotificationCenterProtocol, @unchecked Sen
return authorizationStatusReturnValue
}
}
//MARK: - notificationSettings
var notificationSettingsUnderlyingCallsCount = 0
var notificationSettingsCallsCount: Int {
get {
if Thread.isMainThread {
return notificationSettingsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = notificationSettingsUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
notificationSettingsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
notificationSettingsUnderlyingCallsCount = newValue
}
}
}
}
var notificationSettingsCalled: Bool {
return notificationSettingsCallsCount > 0
}
var notificationSettingsUnderlyingReturnValue: UNNotificationSettings!
var notificationSettingsReturnValue: UNNotificationSettings! {
get {
if Thread.isMainThread {
return notificationSettingsUnderlyingReturnValue
} else {
var returnValue: UNNotificationSettings? = nil
DispatchQueue.main.sync {
returnValue = notificationSettingsUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
notificationSettingsUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
notificationSettingsUnderlyingReturnValue = newValue
}
}
}
}
var notificationSettingsClosure: (() async -> UNNotificationSettings)?
func notificationSettings() async -> UNNotificationSettings {
notificationSettingsCallsCount += 1
if let notificationSettingsClosure = notificationSettingsClosure {
return await notificationSettingsClosure()
} else {
return notificationSettingsReturnValue
}
}
}
class UserSessionMock: UserSessionProtocol, @unchecked Sendable {
var clientProxy: ClientProxyProtocol {
@@ -94,6 +94,9 @@ final class NotificationManager: NSObject, NotificationManagerProtocol {
self?.delegate?.registerForRemoteNotifications()
}
}
let settings = await notificationCenter.notificationSettings()
MXLog.info("Notification sound enabled: \(settings.soundSetting == .enabled)")
}
}
@@ -16,6 +16,7 @@ protocol UserNotificationCenterProtocol: AnyObject {
func removeDeliveredNotifications(withIdentifiers identifiers: [String])
func setNotificationCategories(_ categories: Set<UNNotificationCategory>)
func authorizationStatus() async -> UNAuthorizationStatus
func notificationSettings() async -> UNNotificationSettings
}
// sourcery: AutoMockable