Convert "is logging enabled" methods to class methods so that they can safely be used before Environment has been initialized.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago committed by Michael Kirk
parent fb474a2a1a
commit dc422f7b00

@ -83,7 +83,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
loggingIsEnabled = TRUE; loggingIsEnabled = TRUE;
[DebugLogger.sharedLogger enableTTYLogging]; [DebugLogger.sharedLogger enableTTYLogging];
#elif RELEASE #elif RELEASE
loggingIsEnabled = Environment.preferences.loggingIsEnabled; loggingIsEnabled = PropertyListPreferences.loggingIsEnabled;
#endif #endif
if (loggingIsEnabled) { if (loggingIsEnabled) {
[DebugLogger.sharedLogger enableFileLogging]; [DebugLogger.sharedLogger enableFileLogging];
@ -134,8 +134,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
self.window.rootViewController = [storyboard instantiateInitialViewController]; self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
[VersionMigrations performUpdateCheck]; // this call must be made after environment has been initialized because in // performUpdateCheck must be invoked after Environment has been initialized because
// general upgrade may depend on environment // upgrade process may depend on Environment.
[VersionMigrations performUpdateCheck];
// Accept push notification when app is not open // Accept push notification when app is not open
NSDictionary *remoteNotif = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; NSDictionary *remoteNotif = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

@ -244,6 +244,8 @@ static Environment *environment = nil;
+ (PropertyListPreferences *)preferences + (PropertyListPreferences *)preferences
{ {
OWSAssert([Environment getCurrent] != nil);
OWSAssert([Environment getCurrent].preferences != nil);
return [Environment getCurrent].preferences; return [Environment getCurrent].preferences;
} }

@ -27,7 +27,7 @@ static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"
if (existingValue) { if (existingValue) {
DDLogInfo(@"%@ assigning existing value: %@", self.tag, existingValue); DDLogInfo(@"%@ assigning existing value: %@", self.tag, existingValue);
[[Environment preferences] setLoggingEnabled:[existingValue boolValue]]; [PropertyListPreferences setLoggingEnabled:[existingValue boolValue]];
if (![existingValue boolValue]) { if (![existingValue boolValue]) {
DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.tag); DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.tag);

@ -43,8 +43,8 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
- (BOOL)getHasArchivedAMessage; - (BOOL)getHasArchivedAMessage;
- (void)setHasArchivedAMessage:(BOOL)enabled; - (void)setHasArchivedAMessage:(BOOL)enabled;
- (BOOL)loggingIsEnabled; + (BOOL)loggingIsEnabled;
- (void)setLoggingEnabled:(BOOL)flag; + (void)setLoggingEnabled:(BOOL)flag;
- (BOOL)screenSecurityIsEnabled; - (BOOL)screenSecurityIsEnabled;
- (void)setScreenSecurity:(BOOL)flag; - (void)setScreenSecurity:(BOOL)flag;
@ -61,8 +61,8 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
- (TSImageQuality)imageUploadQuality; - (TSImageQuality)imageUploadQuality;
- (nullable NSString *)lastRanVersion; + (nullable NSString *)lastRanVersion;
- (NSString *)setAndGetCurrentVersion; + (NSString *)setAndGetCurrentVersion;
#pragma mark - Calling #pragma mark - Calling

@ -127,7 +127,7 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
[self setValueForKey:PropertyListPreferencesKeyHasRegisteredVoipPush toValue:@(enabled)]; [self setValueForKey:PropertyListPreferencesKeyHasRegisteredVoipPush toValue:@(enabled)];
} }
- (BOOL)loggingIsEnabled + (BOOL)loggingIsEnabled
{ {
NSNumber *preference = [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyEnableDebugLog]; NSNumber *preference = [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyEnableDebugLog];
@ -138,7 +138,7 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
} }
} }
- (void)setLoggingEnabled:(BOOL)flag + (void)setLoggingEnabled:(BOOL)flag
{ {
// Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start // Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start
// logging before the database is initialized. This is important because sometimes there are problems *with* the // logging before the database is initialized. This is important because sometimes there are problems *with* the
@ -147,11 +147,6 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
[NSUserDefaults.standardUserDefaults synchronize]; [NSUserDefaults.standardUserDefaults synchronize];
} }
- (nullable NSString *)lastRanVersion
{
return [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyLastRunSignalVersion];
}
- (void)setHasSentAMessage:(BOOL)enabled - (void)setHasSentAMessage:(BOOL)enabled
{ {
[self setValueForKey:PropertyListPreferencesKeyHasSentAMessage toValue:@(enabled)]; [self setValueForKey:PropertyListPreferencesKeyHasSentAMessage toValue:@(enabled)];
@ -162,7 +157,12 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
[self setValueForKey:PropertyListPreferencesKeyHasArchivedAMessage toValue:@(enabled)]; [self setValueForKey:PropertyListPreferencesKeyHasArchivedAMessage toValue:@(enabled)];
} }
- (NSString *)setAndGetCurrentVersion + (nullable NSString *)lastRanVersion
{
return [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyLastRunSignalVersion];
}
+ (NSString *)setAndGetCurrentVersion
{ {
NSString *currentVersion = NSString *currentVersion =
[NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]]; [NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]];

@ -31,7 +31,11 @@
+ (void)performUpdateCheck + (void)performUpdateCheck
{ {
NSString *previousVersion = Environment.preferences.lastRanVersion; // performUpdateCheck must be invoked after Environment has been initialized because
// upgrade process may depend on Environment.
OWSAssert([Environment getCurrent]);
NSString *previousVersion = PropertyListPreferences.lastRanVersion;
NSString *currentVersion = NSString *currentVersion =
[NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]]; [NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]];
@ -43,7 +47,7 @@
OWSDatabaseMigrationRunner *runner = OWSDatabaseMigrationRunner *runner =
[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]]; [[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]];
[runner assumeAllExistingMigrationsRun]; [runner assumeAllExistingMigrationsRun];
[Environment.preferences setAndGetCurrentVersion]; [PropertyListPreferences setAndGetCurrentVersion];
return; return;
} }
@ -90,7 +94,7 @@
} }
[[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]] runAllOutstanding]; [[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]] runAllOutstanding];
[Environment.preferences setAndGetCurrentVersion]; [PropertyListPreferences setAndGetCurrentVersion];
} }
+ (BOOL)isVersion:(NSString *)thisVersionString + (BOOL)isVersion:(NSString *)thisVersionString

@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @""); self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
self.enableLogCell.userInteractionEnabled = YES; self.enableLogCell.userInteractionEnabled = YES;
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[self.enableLogSwitch setOn:[Environment.preferences loggingIsEnabled]]; [self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
[self.enableLogSwitch addTarget:self [self.enableLogSwitch addTarget:self
action:@selector(didToggleEnableLogSwitch:) action:@selector(didToggleEnableLogSwitch:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
@ -161,7 +161,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
[[DebugLogger sharedLogger] enableFileLogging]; [[DebugLogger sharedLogger] enableFileLogging];
} }
[Environment.preferences setLoggingEnabled:sender.isOn]; [PropertyListPreferences setLoggingEnabled:sender.isOn];
[self.tableView reloadData]; [self.tableView reloadData];
} }

Loading…
Cancel
Save