Clean up ahead of PR.

This commit is contained in:
Matthew Chen 2017-11-28 16:30:08 -05:00
parent edaf65223a
commit 7429e1968c
6 changed files with 26 additions and 21 deletions

View File

@ -106,10 +106,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// We need to this _after_ we set up logging but _before_ we do
// anything else.
[self ensureMigrationToSharedData];
[self ensureIsReadyForAppExtensions];
#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.
if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) {
[DebugLogger.sharedLogger disableFileLogging];
@ -189,9 +189,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return YES;
}
- (void)ensureMigrationToSharedData
- (void)ensureIsReadyForAppExtensions
{
if ([OWSPreferences hasMigratedToSharedData]) {
if ([OWSPreferences isReadyForAppExtensions]) {
return;
}
@ -201,7 +201,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[OWSProfileManager migrateToSharedData];
[TSAttachmentStream migrateToSharedData];
[OWSPreferences setHasMigratedToSharedData:YES];
[OWSPreferences setIsReadyForAppExtensions:YES];
}
- (void)startupLogging

View File

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

View File

@ -23,7 +23,7 @@ NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion";
NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToSharedData";
NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions";
@implementation OWSPreferences
@ -60,9 +60,9 @@ NSString *const OWSPreferencesKey_HasMigratedToSharedData = @"hasMigratedToShare
#pragma mark - Specific Preferences
+ (BOOL)hasMigratedToSharedData
+ (BOOL)isReadyForAppExtensions
{
NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_HasMigratedToSharedData];
NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_IsReadyForAppExtensions];
if (preference) {
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];
}

View File

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

View File

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

View File

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