From c4f60e325d95c7ce2f237a8ce197337ac874d2a6 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 21 Apr 2020 11:33:31 -0400 Subject: [PATCH] Harmonize consent flow on both platforms. --- platform-darwin/Source/MPConfig.h | 1 + platform-darwin/Source/MPConfig.m | 15 +-- platform-darwin/Source/Mac/MPMacAppDelegate.m | 40 ++++---- platform-darwin/Source/iOS/MPiOSAppDelegate.m | 94 ++++++++++++++----- 4 files changed, 99 insertions(+), 51 deletions(-) diff --git a/platform-darwin/Source/MPConfig.h b/platform-darwin/Source/MPConfig.h index f40da91e..487383e2 100644 --- a/platform-darwin/Source/MPConfig.h +++ b/platform-darwin/Source/MPConfig.h @@ -22,6 +22,7 @@ @property(nonatomic, retain) NSNumber *sendInfo; @property(nonatomic, retain) NSNumber *sendInfoDecided; +@property(nonatomic, retain) NSNumber *notificationsDecided; @property(nonatomic, retain) NSNumber *rememberLogin; @property(nonatomic, retain) NSNumber *hidePasswords; diff --git a/platform-darwin/Source/MPConfig.m b/platform-darwin/Source/MPConfig.m index 24381e42..b15e68a9 100644 --- a/platform-darwin/Source/MPConfig.m +++ b/platform-darwin/Source/MPConfig.m @@ -29,15 +29,16 @@ return nil; [self.defaults registerDefaults:@{ - NSStringFromSelector( @selector( sendInfo ) ) : @YES, - NSStringFromSelector( @selector( sendInfoDecided ) ) : @NO, + NSStringFromSelector( @selector( sendInfo ) ) : @NO, + NSStringFromSelector( @selector( sendInfoDecided ) ) : @NO, + NSStringFromSelector( @selector( notificationsDecided ) ): @NO, - NSStringFromSelector( @selector( rememberLogin ) ) : @NO, - NSStringFromSelector( @selector( hidePasswords ) ) : @NO, - NSStringFromSelector( @selector( siteAttacker ) ) : @(MPAttacker1), + NSStringFromSelector( @selector( rememberLogin ) ) : @NO, + NSStringFromSelector( @selector( hidePasswords ) ) : @NO, + NSStringFromSelector( @selector( siteAttacker ) ) : @(MPAttacker1), - NSStringFromSelector( @selector( checkInconsistency ) ): @NO, - NSStringFromSelector( @selector( askForReviews ) ) : @YES, + NSStringFromSelector( @selector( checkInconsistency ) ) : @NO, + NSStringFromSelector( @selector( askForReviews ) ) : @YES, }]; self.delegate = [MPAppDelegate_Shared get]; diff --git a/platform-darwin/Source/Mac/MPMacAppDelegate.m b/platform-darwin/Source/Mac/MPMacAppDelegate.m index bb635fa6..760f0fab 100644 --- a/platform-darwin/Source/Mac/MPMacAppDelegate.m +++ b/platform-darwin/Source/Mac/MPMacAppDelegate.m @@ -29,7 +29,6 @@ #define LOGIN_HELPER_BUNDLE_ID @"com.lyndir.lhunath.MasterPassword.Mac.LoginHelper" - @implementation MPMacAppDelegate #pragma clang diagnostic push @@ -134,7 +133,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven #if DEBUG countlyConfig.enableDebug = YES; countlyConfig.pushTestMode = CLYPushTestModeDevelopment; -#elif ! PUBLIC +#elif !PUBLIC countlyConfig.enableDebug = NO; countlyConfig.pushTestMode = CLYPushTestModeTestFlightOrAdHoc; #endif @@ -205,7 +204,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [NSApp activateIgnoringOtherApps:YES]; } - [self enableNotifications]; + [self tryNotifications]; } - (void)applicationWillResignActive:(NSNotification *)notification { @@ -231,7 +230,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven return NSTerminateNow; } -- (void)enableNotifications { +- (void)tryNotifications { [Countly.sharedInstance giveConsentForFeature:CLYConsentPushNotifications]; if (@available( macOS 10.14, * )) { @@ -250,18 +249,19 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven - (void)askNotifications { + if ([[MPMacConfig get].notificationsDecided boolValue]) + return; + PearlMainQueue( ^{ - if (![[NSUserDefaults standardUserDefaults] boolForKey:@"notificationsDecided"]) { - if (@available( macOS 10.14, * )) { - [Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler: - ^(BOOL granted, NSError *error) { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"]; - }]; - } - else { - [Countly.sharedInstance askForNotificationPermission]; - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"]; - } + if (@available( macOS 10.14, * )) { + [Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler: + ^(BOOL granted, NSError *error) { + [MPMacConfig get].notificationsDecided = @(YES); + }]; + } + else { + [Countly.sharedInstance askForNotificationPermission]; + [MPMacConfig get].notificationsDecided = @(YES); } } ); } @@ -440,8 +440,8 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven NSAlert *alert = [NSAlert new]; [alert setMessageText:@"New User"]; [alert setInformativeText:@"To begin, enter your full name.\n\n" - @"IMPORTANT: Enter your name correctly, including the right capitalization, " - @"as you would on an official document."]; + @"IMPORTANT: Enter your name correctly, including the right capitalization, " + @"as you would on an official document."]; [alert addButtonWithTitle:@"Create User"]; [alert addButtonWithTitle:@"Cancel"]; NSTextField *nameField = [[NSTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )]; @@ -769,8 +769,12 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven // Send info NSArray *countlyFeatures = @[ - CLYConsentSessions, CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating + CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating ]; + if ([[MPConfig get].sendInfo boolValue] || ![[MPConfig get].sendInfoDecided boolValue]) + [Countly.sharedInstance giveConsentForFeature:CLYConsentSessions]; + else + [Countly.sharedInstance cancelConsentForFeature:CLYConsentSessions]; if ([[MPMacConfig get].sendInfo boolValue]) { if ([PearlLogger get].printLevel > PearlLogLevelInfo) [PearlLogger get].printLevel = PearlLogLevelInfo; diff --git a/platform-darwin/Source/iOS/MPiOSAppDelegate.m b/platform-darwin/Source/iOS/MPiOSAppDelegate.m index 6a8f712a..67134516 100644 --- a/platform-darwin/Source/iOS/MPiOSAppDelegate.m +++ b/platform-darwin/Source/iOS/MPiOSAppDelegate.m @@ -176,7 +176,7 @@ if ([[MPiOSConfig get].showSetup boolValue]) [self.navigationController performSegueWithIdentifier:@"setup" sender:self]; - [self enableNotifications]; + [self consentFeatures]; } ); } @catch (id exception) { @@ -229,7 +229,44 @@ return YES; } -- (void)enableNotifications { +- (void)consentFeatures { + if ([self askDiagnostics]) + return; + + [self tryNotifications]; +} + +- (BOOL)askDiagnostics { + + if ([[MPiOSConfig get].sendInfoDecided boolValue]) + return NO; + + PearlMainQueue( ^{ + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Welcome to Master Password!" message: + @"We want this experience to be top-notch.\n\n" + @"We look for bugs, runtime issues, crashes & usage counters.\n" + @"Needless to say, diagnostics are always scrubbed and personal details will never leave your device." + preferredStyle:UIAlertControllerStyleAlert]; + + [alert addAction:[UIAlertAction actionWithTitle:@"Disable" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { + [MPiOSConfig get].sendInfo = @(NO); + [MPiOSConfig get].sendInfoDecided = @(YES); + [self consentFeatures]; + }]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Thanks" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [MPiOSConfig get].sendInfo = @(YES); + [MPiOSConfig get].sendInfoDecided = @(YES); + [self consentFeatures]; + }]]; + + [(self.navigationController.presentedViewController?: (UIViewController *)self.navigationController) + presentViewController:alert animated:YES completion:nil]; + } ); + + return YES; +} + +- (void)tryNotifications { [Countly.sharedInstance giveConsentForFeature:CLYConsentPushNotifications]; if (@available( iOS 12, * )) { @@ -240,35 +277,36 @@ [self askNotifications]; }]; + return; } - else { - [self askNotifications]; - } + + [self askNotifications]; } - (void)askNotifications { + if ([[MPiOSConfig get].notificationsDecided boolValue]) + return; + PearlMainQueue( ^{ - if (![[NSUserDefaults standardUserDefaults] boolForKey:@"notificationsDecided"]) { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Coming Soon" message: - @"Master Password is rolling out a new modern personal security platform and we're excited to bring you along.\n\n" - @"When it's time, we'll send you a notification to help you make an effortless transition." - preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction actionWithTitle:@"Thanks" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - if (@available( iOS 12, * )) { - [Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler: - ^(BOOL granted, NSError *error) { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"]; - }]; - } - else { - [Countly.sharedInstance askForNotificationPermission]; - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"]; - } - }]]; - [(self.navigationController.presentedViewController?: (UIViewController *)self.navigationController) - presentViewController:alert animated:YES completion:nil]; - } + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Coming Soon" message: + @"Master Password is rolling out a new modern personal security platform and we're excited to bring you along.\n\n" + @"When it's time, we'll send you a notification to help you make an effortless transition." + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Thanks" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + if (@available( iOS 12, * )) { + [Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler: + ^(BOOL granted, NSError *error) { + [MPiOSConfig get].notificationsDecided = @(YES); + }]; + } + else { + [Countly.sharedInstance askForNotificationPermission]; + [MPiOSConfig get].notificationsDecided = @(YES); + } + }]]; + [(self.navigationController.presentedViewController?: (UIViewController *)self.navigationController) + presentViewController:alert animated:YES completion:nil]; } ); } @@ -643,8 +681,12 @@ // Send info NSArray *countlyFeatures = @[ - CLYConsentSessions, CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating + CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating ]; + if ([[MPConfig get].sendInfo boolValue] || ![[MPConfig get].sendInfoDecided boolValue]) + [Countly.sharedInstance giveConsentForFeature:CLYConsentSessions]; + else + [Countly.sharedInstance cancelConsentForFeature:CLYConsentSessions]; if ([[MPConfig get].sendInfo boolValue]) { if ([PearlLogger get].printLevel > PearlLogLevelInfo) [PearlLogger get].printLevel = PearlLogLevelInfo;