Add asserts around Swift singletons.
This commit is contained in:
parent
26bd1f2e65
commit
7a1e47cd26
|
@ -914,7 +914,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
|
||||
[[TSStorageManager sharedManager].newDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[[ExperienceUpgradeFinder new] markAllAsSeenWithTransaction:transaction];
|
||||
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
|
||||
}];
|
||||
// Start running the disappearing messages job in case the newly registered user
|
||||
// enables this feature
|
||||
|
|
|
@ -20,6 +20,10 @@ class MessageFetcherJob: NSObject {
|
|||
self.messageReceiver = messageReceiver
|
||||
self.networkManager = networkManager
|
||||
self.signalService = signalService
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
public func run() -> Promise<Void> {
|
||||
|
|
|
@ -26,6 +26,10 @@ class AccountManager: NSObject {
|
|||
self.networkManager = textSecureAccountManager.networkManager
|
||||
self.textSecureAccountManager = textSecureAccountManager
|
||||
self.preferences = preferences
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
// MARK: registration
|
||||
|
|
|
@ -24,6 +24,10 @@ class CallNotificationsAdapter: NSObject {
|
|||
// } else {
|
||||
adaptee = SignalApp.shared().notificationsManager
|
||||
// }
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
func presentIncomingCall(_ call: SignalCall, callerName: String) {
|
||||
|
|
|
@ -72,8 +72,11 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot
|
|||
|
||||
override init() {
|
||||
self.center = UNUserNotificationCenter.current()
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
center.delegate = self
|
||||
|
||||
// FIXME TODO only do this after user has registered.
|
||||
|
|
|
@ -56,7 +56,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
|
||||
@property (nonatomic, readonly) AccountManager *accountManager;
|
||||
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
||||
@property (nonatomic, readonly) ExperienceUpgradeFinder *experienceUpgradeFinder;
|
||||
@property (nonatomic, readonly) OWSMessageManager *messagesManager;
|
||||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
||||
|
@ -111,7 +110,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
_blockingManager = [OWSBlockingManager sharedManager];
|
||||
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
|
||||
|
||||
_experienceUpgradeFinder = [ExperienceUpgradeFinder new];
|
||||
ExperienceUpgradeFinder.sharedManager;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(blockedPhoneNumbersDidChange:)
|
||||
|
@ -530,7 +529,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
|
||||
__block NSArray<ExperienceUpgrade *> *unseenUpgrades;
|
||||
[self.editingDbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
unseenUpgrades = [self.experienceUpgradeFinder allUnseenWithTransaction:transaction];
|
||||
unseenUpgrades = [ExperienceUpgradeFinder.sharedManager allUnseenWithTransaction:transaction];
|
||||
}];
|
||||
return unseenUpgrades;
|
||||
}
|
||||
|
@ -540,7 +539,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
AssertIsOnMainThread();
|
||||
|
||||
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction];
|
||||
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
@ -148,6 +148,8 @@ struct AudioSource: Hashable {
|
|||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
// Configure audio session so we don't prompt user with Record permission until call is connected.
|
||||
audioSession.configure()
|
||||
}
|
||||
|
|
|
@ -224,6 +224,8 @@ protocol CallServiceObserver: class {
|
|||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
self.createCallUIAdapter()
|
||||
|
||||
NotificationCenter.default.addObserver(self,
|
||||
|
|
|
@ -9,7 +9,7 @@ import SignalMessaging
|
|||
/**
|
||||
* Manage call related UI in a pre-CallKit world.
|
||||
*/
|
||||
class NonCallKitCallUIAdaptee: CallUIAdaptee {
|
||||
class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
|
||||
let TAG = "[NonCallKitCallUIAdaptee]"
|
||||
|
||||
|
@ -20,8 +20,14 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
|
|||
let hasManualRinger = true
|
||||
|
||||
required init(callService: CallService, notificationsAdapter: CallNotificationsAdapter) {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
self.callService = callService
|
||||
self.notificationsAdapter = notificationsAdapter
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
func startOutgoingCall(handle: String) -> SignalCall {
|
||||
|
|
|
@ -20,6 +20,8 @@ import SignalMessaging
|
|||
self.contactsUpdater = contactsUpdater
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,14 @@ final class CallKitCallManager: NSObject {
|
|||
let callController = CXCallController()
|
||||
static let kAnonymousCallHandlePrefix = "Signal:"
|
||||
|
||||
override required init() {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
func startCall(_ call: SignalCall) {
|
||||
|
|
|
@ -63,6 +63,8 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
|||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
self.provider.setDelegate(self, queue: nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,8 @@ extension CallUIAdaptee {
|
|||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
callService.addObserverAndSyncState(observer: self)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,10 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
|||
self.accountManager = accountManager
|
||||
self.callService = callService
|
||||
self.messageSender = messageSender
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
// MARK: - Call Handlers
|
||||
|
|
|
@ -13,7 +13,17 @@ enum ExperienceUpgradeId: String {
|
|||
}
|
||||
|
||||
class ExperienceUpgradeFinder: NSObject {
|
||||
public let TAG = "[ExperienceUpgradeFinder]"
|
||||
|
||||
// MARK - Singleton class
|
||||
|
||||
@objc(sharedManager)
|
||||
public static let shared = ExperienceUpgradeFinder()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
var videoCalling: ExperienceUpgrade {
|
||||
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.videoCalling.rawValue,
|
||||
|
@ -64,7 +74,7 @@ class ExperienceUpgradeFinder: NSObject {
|
|||
}
|
||||
|
||||
public func markAllAsSeen(transaction: YapDatabaseReadWriteTransaction) {
|
||||
Logger.info("\(TAG) marking experience upgrades as seen")
|
||||
Logger.info("\(logTag) marking experience upgrades as seen")
|
||||
allExperienceUpgrades.forEach { $0.save(with: transaction) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ public enum PushRegistrationError: Error {
|
|||
|
||||
private override init() {
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
private var userNotificationSettingsPromise: Promise<Void>?
|
||||
|
|
|
@ -271,7 +271,11 @@ extension GiphyError: LocalizedError {
|
|||
static let sharedInstance = GiphyAPI()
|
||||
|
||||
// Force usage as a singleton
|
||||
override private init() {}
|
||||
override private init() {
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
|
|
|
@ -450,6 +450,8 @@ extension URLSessionTask {
|
|||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
ensureGifFolder()
|
||||
}
|
||||
|
||||
|
|
|
@ -428,7 +428,7 @@
|
|||
"DATABASE_VIEW_OVERLAY_TITLE" = "Updating Database";
|
||||
|
||||
/* Message indicating that the debug log is being uploaded. */
|
||||
"DEBUG_LOG_ACTIVITY_INDICATOR" = "Sending debug log...";
|
||||
"DEBUG_LOG_ACTIVITY_INDICATOR" = "Sending Debug Log...";
|
||||
|
||||
/* Message of the debug log alert. */
|
||||
"DEBUG_LOG_ALERT_MESSAGE" = "What would you like to do with the link to your debug log?";
|
||||
|
@ -449,13 +449,13 @@
|
|||
"DEBUG_LOG_ALERT_TITLE" = "One More Step";
|
||||
|
||||
/* Title of the alert indicating the debug log upload failed. */
|
||||
"DEBUG_LOG_FAILURE_ALERT_TITLE" = "Failed to submit debug log";
|
||||
"DEBUG_LOG_FAILURE_ALERT_TITLE" = "Failed to Submit Debug Log";
|
||||
|
||||
/* Message of the alert before redirecting to Github Issues. */
|
||||
"DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE" = "The gist link was copied in your clipboard. You are about to be redirected to the GitHub issue list.";
|
||||
|
||||
/* Title of the alert before redirecting to Github Issues. */
|
||||
"DEBUG_LOG_GITHUB_ISSUE_ALERT_TITLE" = "GitHub redirection";
|
||||
"DEBUG_LOG_GITHUB_ISSUE_ALERT_TITLE" = "GitHub Redirection";
|
||||
|
||||
/* {{Short Date}} when device last communicated with Signal Server. */
|
||||
"DEVICE_LAST_ACTIVE_AT_LABEL" = "Last active: %@";
|
||||
|
|
|
@ -351,6 +351,10 @@ public class SystemContactsFetcher: NSObject {
|
|||
|
||||
override init() {
|
||||
self.contactStoreAdapter = ContactStoreAdapter()
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
@objc
|
||||
|
|
|
@ -38,6 +38,8 @@ public class DeviceSleepManager: NSObject {
|
|||
private override init() {
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector:#selector(didEnterBackground),
|
||||
name:NSNotification.Name.UIApplicationDidEnterBackground,
|
||||
|
|
|
@ -20,3 +20,30 @@ public func owsFail(_ message: String) {
|
|||
Logger.flush()
|
||||
assertionFailure(message)
|
||||
}
|
||||
|
||||
public class SwiftSingletons: NSObject {
|
||||
public static let shared = SwiftSingletons()
|
||||
|
||||
private var classSet = Set<String>()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func register(_ singleton: AnyObject) {
|
||||
guard _isDebugAssertConfiguration() else {
|
||||
return
|
||||
}
|
||||
let singletonClassName = String(describing:type(of:singleton))
|
||||
guard !classSet.contains(singletonClassName) else {
|
||||
owsFail("\(self.logTag()) in \(#function) Duplicate singleton: \(singletonClassName).")
|
||||
return
|
||||
}
|
||||
Logger.verbose("\(self.logTag()) in \(#function) Registering singleton: \(singletonClassName).")
|
||||
classSet.insert(singletonClassName)
|
||||
}
|
||||
|
||||
public static func register(_ singleton: AnyObject) {
|
||||
shared.register(singleton)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue