Clean up ahead of PR.

pull/1/head
Matthew Chen 8 years ago
parent edaf65223a
commit 7429e1968c

@ -106,10 +106,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// We need to this _after_ we set up logging but _before_ we do // We need to this _after_ we set up logging but _before_ we do
// anything else. // anything else.
[self ensureMigrationToSharedData]; [self ensureIsReadyForAppExtensions];
#if RELEASE #if RELEASE
// ensureMigrationToSharedData may have changed the state of the logging // ensureIsReadyForAppExtensions may have changed the state of the logging
// preference, so honor that change if necessary. // preference, so honor that change if necessary.
if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) { if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) {
[DebugLogger.sharedLogger disableFileLogging]; [DebugLogger.sharedLogger disableFileLogging];
@ -189,9 +189,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return YES; return YES;
} }
- (void)ensureMigrationToSharedData - (void)ensureIsReadyForAppExtensions
{ {
if ([OWSPreferences hasMigratedToSharedData]) { if ([OWSPreferences isReadyForAppExtensions]) {
return; return;
} }
@ -201,7 +201,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[OWSProfileManager migrateToSharedData]; [OWSProfileManager migrateToSharedData];
[TSAttachmentStream migrateToSharedData]; [TSAttachmentStream migrateToSharedData];
[OWSPreferences setHasMigratedToSharedData:YES]; [OWSPreferences setIsReadyForAppExtensions:YES];
} }
- (void)startupLogging - (void)startupLogging

@ -27,8 +27,8 @@ extern NSString *const OWSPreferencesKeyEnableDebugLog;
#pragma mark - Specific Preferences #pragma mark - Specific Preferences
+ (BOOL)hasMigratedToSharedData; + (BOOL)isReadyForAppExtensions;
+ (void)setHasMigratedToSharedData:(BOOL)value; + (void)setIsReadyForAppExtensions:(BOOL)value;
- (BOOL)getHasSentAMessage; - (BOOL)getHasSentAMessage;
- (void)setHasSentAMessage:(BOOL)enabled; - (void)setHasSentAMessage:(BOOL)enabled;

@ -23,7 +23,7 @@ NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView"; NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion"; NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion";
NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToSharedData"; NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions";
@implementation OWSPreferences @implementation OWSPreferences
@ -60,9 +60,9 @@ NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToShare
#pragma mark - Specific Preferences #pragma mark - Specific Preferences
+ (BOOL)hasMigratedToSharedData + (BOOL)isReadyForAppExtensions
{ {
NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_HasMigratedToSharedData]; NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_IsReadyForAppExtensions];
if (preference) { if (preference) {
return [preference boolValue]; return [preference boolValue];
@ -71,9 +71,9 @@ NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToShare
} }
} }
+ (void)setHasMigratedToSharedData:(BOOL)value + (void)setIsReadyForAppExtensions:(BOOL)value
{ {
[NSUserDefaults.appUserDefaults setObject:@(value) forKey:OWSPreferencesKey_HasMigratedToSharedData]; [NSUserDefaults.appUserDefaults setObject:@(value) forKey:OWSPreferencesKey_IsReadyForAppExtensions];
[NSUserDefaults.appUserDefaults synchronize]; [NSUserDefaults.appUserDefaults synchronize];
} }

@ -57,6 +57,8 @@ typedef enum { kSMSVerification, kPhoneNumberVerification } VerificationTranspor
#define textSecureSetProfileNameAPIFormat @"v1/profile/name/%@" #define textSecureSetProfileNameAPIFormat @"v1/profile/name/%@"
#define textSecureProfileAvatarFormAPI @"v1/profile/form/avatar" #define textSecureProfileAvatarFormAPI @"v1/profile/form/avatar"
#define SignalApplicationGroup @"group.org.whispersystems.signal.group"
#pragma mark Push RegistrationSpecific Constants #pragma mark Push RegistrationSpecific Constants
typedef NS_ENUM(NSInteger, TSPushRegistrationError) { typedef NS_ENUM(NSInteger, TSPushRegistrationError) {
TSPushRegistrationErrorNetwork, TSPushRegistrationErrorNetwork,

@ -3,6 +3,7 @@
// //
#import "NSUserDefaults+OWS.h" #import "NSUserDefaults+OWS.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -10,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSUserDefaults *)appUserDefaults + (NSUserDefaults *)appUserDefaults
{ {
return [[NSUserDefaults alloc] initWithSuiteName:@"group.org.whispersystems.signal.group"]; return [[NSUserDefaults alloc] initWithSuiteName:SignalApplicationGroup];
} }
+ (void)migrateToSharedUserDefaults + (void)migrateToSharedUserDefaults

@ -3,6 +3,7 @@
// //
#import "OWSFileSystem.h" #import "OWSFileSystem.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -38,8 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)appSharedDataDirectoryPath + (NSString *)appSharedDataDirectoryPath
{ {
NSURL *groupContainerDirectoryURL = [[NSFileManager defaultManager] NSURL *groupContainerDirectoryURL =
containerURLForSecurityApplicationGroupIdentifier:@"group.org.whispersystems.signal.group"]; [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:SignalApplicationGroup];
return [groupContainerDirectoryURL path]; return [groupContainerDirectoryURL path];
} }
@ -52,7 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
if ([fileManager fileExistsAtPath:newFilePath]) { if ([fileManager fileExistsAtPath:newFilePath]) {
DDLogError(@""); OWSFail(
@"%@ Can't move file from %@ to %@; destination already exists.", self.logTag, oldFilePath, newFilePath);
return; return;
} }
@ -62,11 +64,11 @@ NS_ASSUME_NONNULL_BEGIN
BOOL success = [fileManager moveItemAtPath:oldFilePath toPath:newFilePath error:&error]; BOOL success = [fileManager moveItemAtPath:oldFilePath toPath:newFilePath error:&error];
if (!success || error) { if (!success || error) {
NSString *errorDescription = NSString *errorDescription =
[NSString stringWithFormat:@"%@ Could not move database file from %@ to %@, error: %@", [NSString stringWithFormat:@"%@ Could not move file or directory from %@ to %@, error: %@",
self.logTag, self.logTag,
oldFilePath, oldFilePath,
newFilePath, newFilePath,
error]; error];
OWSFail(@"%@", errorDescription); OWSFail(@"%@", errorDescription);
[NSException raise:exceptionName format:@"%@", errorDescription]; [NSException raise:exceptionName format:@"%@", errorDescription];
} }

Loading…
Cancel
Save