Harmonize consent flow on both platforms.
This commit is contained in:
		@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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];
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user