mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Convert "is logging enabled" methods to class methods so that they can safely be used before Environment has been initialized.
// FREEBIE
This commit is contained in:
parent
fb474a2a1a
commit
dc422f7b00
|
@ -83,7 +83,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
loggingIsEnabled = TRUE;
|
||||
[DebugLogger.sharedLogger enableTTYLogging];
|
||||
#elif RELEASE
|
||||
loggingIsEnabled = Environment.preferences.loggingIsEnabled;
|
||||
loggingIsEnabled = PropertyListPreferences.loggingIsEnabled;
|
||||
#endif
|
||||
if (loggingIsEnabled) {
|
||||
[DebugLogger.sharedLogger enableFileLogging];
|
||||
|
@ -134,8 +134,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
self.window.rootViewController = [storyboard instantiateInitialViewController];
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
[VersionMigrations performUpdateCheck]; // this call must be made after environment has been initialized because in
|
||||
// general upgrade may depend on environment
|
||||
// performUpdateCheck must be invoked after Environment has been initialized because
|
||||
// upgrade process may depend on Environment.
|
||||
[VersionMigrations performUpdateCheck];
|
||||
|
||||
// Accept push notification when app is not open
|
||||
NSDictionary *remoteNotif = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
|
|
|
@ -244,6 +244,8 @@ static Environment *environment = nil;
|
|||
|
||||
+ (PropertyListPreferences *)preferences
|
||||
{
|
||||
OWSAssert([Environment getCurrent] != nil);
|
||||
OWSAssert([Environment getCurrent].preferences != nil);
|
||||
return [Environment getCurrent].preferences;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"
|
|||
|
||||
if (existingValue) {
|
||||
DDLogInfo(@"%@ assigning existing value: %@", self.tag, existingValue);
|
||||
[[Environment preferences] setLoggingEnabled:[existingValue boolValue]];
|
||||
[PropertyListPreferences setLoggingEnabled:[existingValue boolValue]];
|
||||
|
||||
if (![existingValue boolValue]) {
|
||||
DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.tag);
|
||||
|
|
|
@ -43,8 +43,8 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
|
|||
- (BOOL)getHasArchivedAMessage;
|
||||
- (void)setHasArchivedAMessage:(BOOL)enabled;
|
||||
|
||||
- (BOOL)loggingIsEnabled;
|
||||
- (void)setLoggingEnabled:(BOOL)flag;
|
||||
+ (BOOL)loggingIsEnabled;
|
||||
+ (void)setLoggingEnabled:(BOOL)flag;
|
||||
|
||||
- (BOOL)screenSecurityIsEnabled;
|
||||
- (void)setScreenSecurity:(BOOL)flag;
|
||||
|
@ -61,8 +61,8 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
|
|||
|
||||
- (TSImageQuality)imageUploadQuality;
|
||||
|
||||
- (nullable NSString *)lastRanVersion;
|
||||
- (NSString *)setAndGetCurrentVersion;
|
||||
+ (nullable NSString *)lastRanVersion;
|
||||
+ (NSString *)setAndGetCurrentVersion;
|
||||
|
||||
#pragma mark - Calling
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
|
|||
[self setValueForKey:PropertyListPreferencesKeyHasRegisteredVoipPush toValue:@(enabled)];
|
||||
}
|
||||
|
||||
- (BOOL)loggingIsEnabled
|
||||
+ (BOOL)loggingIsEnabled
|
||||
{
|
||||
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 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];
|
||||
}
|
||||
|
||||
- (nullable NSString *)lastRanVersion
|
||||
{
|
||||
return [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyLastRunSignalVersion];
|
||||
}
|
||||
|
||||
- (void)setHasSentAMessage:(BOOL)enabled
|
||||
{
|
||||
[self setValueForKey:PropertyListPreferencesKeyHasSentAMessage toValue:@(enabled)];
|
||||
|
@ -162,7 +157,12 @@ NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddr
|
|||
[self setValueForKey:PropertyListPreferencesKeyHasArchivedAMessage toValue:@(enabled)];
|
||||
}
|
||||
|
||||
- (NSString *)setAndGetCurrentVersion
|
||||
+ (nullable NSString *)lastRanVersion
|
||||
{
|
||||
return [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyLastRunSignalVersion];
|
||||
}
|
||||
|
||||
+ (NSString *)setAndGetCurrentVersion
|
||||
{
|
||||
NSString *currentVersion =
|
||||
[NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]];
|
||||
|
|
|
@ -31,7 +31,11 @@
|
|||
|
||||
+ (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 stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]];
|
||||
|
||||
|
@ -43,7 +47,7 @@
|
|||
OWSDatabaseMigrationRunner *runner =
|
||||
[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]];
|
||||
[runner assumeAllExistingMigrationsRun];
|
||||
[Environment.preferences setAndGetCurrentVersion];
|
||||
[PropertyListPreferences setAndGetCurrentVersion];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -90,7 +94,7 @@
|
|||
}
|
||||
|
||||
[[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]] runAllOutstanding];
|
||||
[Environment.preferences setAndGetCurrentVersion];
|
||||
[PropertyListPreferences setAndGetCurrentVersion];
|
||||
}
|
||||
|
||||
+ (BOOL)isVersion:(NSString *)thisVersionString
|
||||
|
|
|
@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
|
|||
self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
|
||||
self.enableLogCell.userInteractionEnabled = YES;
|
||||
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
||||
[self.enableLogSwitch setOn:[Environment.preferences loggingIsEnabled]];
|
||||
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
|
||||
[self.enableLogSwitch addTarget:self
|
||||
action:@selector(didToggleEnableLogSwitch:)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
|
@ -161,7 +161,7 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
|
|||
[[DebugLogger sharedLogger] enableFileLogging];
|
||||
}
|
||||
|
||||
[Environment.preferences setLoggingEnabled:sender.isOn];
|
||||
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue