From 774f183ac06986b1344029dfb3edcd14988c2f25 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 25 Apr 2020 10:44:59 -0400 Subject: [PATCH] Improved web support & trigger notification URLs. --- .../project.pbxproj | 21 ++----- platform-darwin/Source/MPSecrets.m | 18 ++++-- .../Source/iOS/MPWebViewController.h | 6 +- .../Source/iOS/MPWebViewController.m | 62 +++++++++---------- platform-darwin/Source/iOS/MPiOSAppDelegate.m | 22 +++++-- .../Source/iOS/Storyboard.storyboard | 22 ++----- 6 files changed, 75 insertions(+), 76 deletions(-) diff --git a/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj b/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj index f173af92..bfbc21fa 100644 --- a/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj +++ b/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj @@ -166,6 +166,7 @@ DA69540617D975D900BF294E /* icon_gears.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD37841711E29500CF925C /* icon_gears.png */; }; DA69540717D975D900BF294E /* icon_gears@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD37851711E29500CF925C /* icon_gears@2x.png */; }; DA72BD7B19C1510C00E6ACFE /* UIView+FontScale.m in Sources */ = {isa = PBXBuildFile; fileRef = DACE2F6719BA6A2A0010F92E /* UIView+FontScale.m */; }; + DA72E2302453B91700676D4F /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA72E22F2453B91700676D4F /* WebKit.framework */; }; DA73049D194E022700E72520 /* ui_spinner.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD36511711E29400CF925C /* ui_spinner.png */; }; DA73049E194E022700E72520 /* ui_spinner@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD36521711E29400CF925C /* ui_spinner@2x.png */; }; DA73049F194E022B00E72520 /* ui_textfield.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD365B1711E29400CF925C /* ui_textfield.png */; }; @@ -662,6 +663,7 @@ DA67460B18DE7F0C00DFE240 /* Exo2.0-ExtraBold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Exo2.0-ExtraBold.otf"; sourceTree = ""; }; DA67460C18DE7F0C00DFE240 /* Exo2.0-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Exo2.0-Bold.otf"; sourceTree = ""; }; DA70EC7F1811B13C00F65DB2 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + DA72E22F2453B91700676D4F /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; DA771FE41E6E1595004D7EDE /* MasterPassword-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MasterPassword-Prefix.pch"; sourceTree = ""; }; DA854C8118D4CFBF00106317 /* avatar-add@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "avatar-add@2x.png"; sourceTree = ""; }; DA854C8218D4CFBF00106317 /* avatar-add.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "avatar-add.png"; sourceTree = ""; }; @@ -1597,6 +1599,7 @@ DAE2725A19C93B8E007C5262 /* StoreKit.framework in Frameworks */, DA6701E016406BB400B61001 /* AdSupport.framework in Frameworks */, DA6701DE16406B7300B61001 /* Social.framework in Frameworks */, + DA72E2302453B91700676D4F /* WebKit.framework in Frameworks */, DA6701B816406A4100B61001 /* Accounts.framework in Frameworks */, DABB981615100B4000B05417 /* SystemConfiguration.framework in Frameworks */, DA672D3014F9413D004A189C /* libPearl.a in Frameworks */, @@ -1775,6 +1778,7 @@ DA5BFA47147E415C00F98B1E /* Frameworks */ = { isa = PBXGroup; children = ( + DA72E22F2453B91700676D4F /* WebKit.framework */, DAFC1F6F2439795000D1CD66 /* CoreServices.framework */, DAB7AE5C1F3D752900C856B1 /* libjson-c.a */, DA6701B716406A4100B61001 /* Accounts.framework */, @@ -3865,7 +3869,6 @@ SKIP_INSTALL = YES; STRIP_INSTALLED_PRODUCT = NO; STRIP_SWIFT_SYMBOLS = NO; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; TARGETED_DEVICE_FAMILY = "1,2"; WARNING_CFLAGS = "-Wno-float-conversion"; }; @@ -3994,10 +3997,6 @@ "\"$(PROJECT_DIR)/../lib/libjson-c/build-ios~/out/include\"", ); INFOPLIST_FILE = "Source/iOS/MasterPassword-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(PROJECT_DIR)/../lib/libsodium/build-ios~/out/lib\"", @@ -4013,9 +4012,6 @@ SKIP_INSTALL = NO; STRIP_INSTALLED_PRODUCT = YES; STRIP_SWIFT_SYMBOLS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Source/iOS/MasterPassword-Bridging-Header.h"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -4028,7 +4024,6 @@ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = NO; CODE_SIGN_ENTITLEMENTS = Source/iOS/MasterPassword.entitlements; CODE_SIGN_STYLE = Manual; - EXCLUDED_SOURCE_FILE_NAMES = libDCIntrospect.a; GCC_C_LANGUAGE_STANDARD = c11; GCC_PREFIX_HEADER = "Source/MasterPassword-Prefix.pch"; GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO; @@ -4038,10 +4033,6 @@ "\"$(PROJECT_DIR)/../lib/libjson-c/build-ios~/out/include\"", ); INFOPLIST_FILE = "Source/iOS/MasterPassword-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(PROJECT_DIR)/../lib/libsodium/build-ios~/out/lib\"", @@ -4057,10 +4048,6 @@ SKIP_INSTALL = NO; STRIP_INSTALLED_PRODUCT = YES; STRIP_SWIFT_SYMBOLS = YES; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OBJC_BRIDGING_HEADER = "Source/iOS/MasterPassword-Bridging-Header.h"; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/platform-darwin/Source/MPSecrets.m b/platform-darwin/Source/MPSecrets.m index 3a80f10a..99b5118d 100644 --- a/platform-darwin/Source/MPSecrets.m +++ b/platform-darwin/Source/MPSecrets.m @@ -20,11 +20,19 @@ #import "base64.h" // printf | openssl enc -[ed] -aes-128-cbc -a -A -K -iv 0 -NSString *appSecret = @""; -NSString *appSalt = @""; -NSString *sentryDSN = @""; -NSString *countlyKey = @""; -NSString *countlySalt = @""; +#if TARGET_OS_IOS +NSString *appSecret = @"946a6b12e6e6e004cc35bad1ea11478c"; +NSString *appSalt = @"uBcsbZeTB8TfSS7dDw4yUq6wMZD/2nREvR0mqzqsNXvv9guh+62hkt99ly6QcJ5n"; +NSString *sentryDSN = @"tmVjdMN9DpZ+0EIrrvHi44hWfaBkwrlrxjBkdeau2rDk+zlvgSdAZkAvNj7m1V+5NUR7i8Y/NumNKOaYlWJvPynEMJ4ZBvPepSbivgVvmr8="; +NSString *countlyKey = @"mDnMZyxwoq4ENgYnGYTzW8wsyiJQlmNKxkRLj88/nrs0mzE+zVjs6Y5LAT3+AYBB"; +NSString *countlySalt = @"2COFsZd+4FNAU6jvI/HUu297mkZALzRIyKv5mD3vs55BHXDowh62A7FursCYS+cG"; +#elif TARGET_OS_MAC +NSString *appSecret = @"24fcbadccb5789b2a969c0c811f86702"; +NSString *appSalt = @"0N1fzSanIOCb7OQ4hEshXSjwEPXAXMhPBKQJeEcYPor8FWz76IpdB8ZHa3Wyb7o9"; +NSString *sentryDSN = @"2RbeS9wfzQEOKB9MG3EWLDe+N8iXYNtWc8tovMcBmhuMIeyAHYKqo5eclSEYyM6lA73Y7FFHqUyTLbEmOR6MAU2PtWAitLdxOZlq3VnbXjI="; +NSString *countlyKey = @"uiasXoQNtkPQHvpvNqEE5N/tw/F1Hnzm+4ViSJ38EMeoWGvDQPJ+Kt9zPhb8Qans"; +NSString *countlySalt = @"/raQUNxKQdxXRR5VFmCDJdyyJE8f6SPrTO5Y4z0kJH+wCrjaZ1VvCq+JSmOsBkz2"; +#endif NSString *decrypt(NSString *secret) { diff --git a/platform-darwin/Source/iOS/MPWebViewController.h b/platform-darwin/Source/iOS/MPWebViewController.h index 257e7024..68451fa5 100644 --- a/platform-darwin/Source/iOS/MPWebViewController.h +++ b/platform-darwin/Source/iOS/MPWebViewController.h @@ -17,10 +17,12 @@ //============================================================================== #import +#import -@interface MPWebViewController : UIViewController +@interface MPWebViewController : UIViewController -@property(nonatomic) IBOutlet UIWebView *webView; +@property(nonatomic) IBOutlet WKWebView *webView; +@property(nonatomic) IBOutlet UINavigationBar *webNavigationBar; @property(nonatomic) IBOutlet UINavigationItem *webNavigationItem; @property(nonatomic) NSURL *initialURL; diff --git a/platform-darwin/Source/iOS/MPWebViewController.m b/platform-darwin/Source/iOS/MPWebViewController.m index f2e702f2..7d0a41a4 100644 --- a/platform-darwin/Source/iOS/MPWebViewController.m +++ b/platform-darwin/Source/iOS/MPWebViewController.m @@ -24,20 +24,30 @@ [super viewDidLoad]; - [self.webView.scrollView insetOcclusion]; + if (!self.initialURL) + self.initialURL = [NSURL URLWithString:@"https://masterpassword.app"]; + self.webNavigationItem.title = self.initialURL.host; + + // WKWebView can't be on the storyboard for iOS pre 11 due to an NSCoding bug. + [self.view insertSubview:self.webView = [WKWebView new] atIndex:0]; + [self.webView setNavigationDelegate:self]; + [self.webView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [self.webView.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES; + [self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES; + [self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; + [self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES; + + [self.webView loadRequest:[[NSURLRequest alloc] initWithURL:self.initialURL]]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; +} - if (!self.initialURL) - self.initialURL = [NSURL URLWithString:@"https://masterpassword.app"]; - - self.webNavigationItem.title = self.initialURL.host; - - self.webView.visible = NO; - [self.webView loadRequest:[[NSURLRequest alloc] initWithURL:self.initialURL]]; +- (void)viewDidLayoutSubviews { + [self.webView.scrollView insetOcclusion]; + [super viewDidLayoutSubviews]; } - (UIStatusBarStyle)preferredStatusBarStyle { @@ -45,26 +55,12 @@ return UIStatusBarStyleLightContent; } -#pragma mark - UIWebViewDelegate +#pragma mark - WKNavigationDelegate -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request - navigationType:(UIWebViewNavigationType)navigationType { +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { - if ([[request.URL absoluteString] rangeOfString:@"thanks.lhunath.com"].location != NSNotFound) { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tipped.thanks"]; - if (![[NSUserDefaults standardUserDefaults] synchronize]) - wrn( @"Couldn't synchronize thanks tip." ); - } - - if ([request.URL isEqual:request.mainDocumentURL]) { - self.webNavigationItem.title = request.URL.host; - self.webNavigationItem.prompt = strl( @"Loading" ); - } - - return YES; -} - -- (void)webViewDidStartLoad:(UIWebView *)webView { + self.webNavigationItem.title = webView.URL.host; + self.webNavigationItem.prompt = strl( @"Loading" ); UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; @@ -72,15 +68,19 @@ [activityView startAnimating]; } -- (void)webViewDidFinishLoad:(UIWebView *)webView { +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { - [UIView animateWithDuration:0.3 animations:^{ - self.webView.visible = YES; - }]; + if ([[webView.URL absoluteString] rangeOfString:@"thanks.lhunath.com"].location != NSNotFound) { + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tipped.thanks"]; + if (![[NSUserDefaults standardUserDefaults] synchronize]) + wrn( @"Couldn't synchronize thanks tip." ); + } [self.webNavigationItem setLeftBarButtonItem:[webView canGoBack]? [[UIBarButtonItem alloc] initWithTitle:@"⬅︎" style:UIBarButtonItemStylePlain target:webView action:@selector( goBack )]: nil]; - self.webNavigationItem.prompt = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; + [webView evaluateJavaScript:@"document.title" completionHandler:^(id o, NSError *error) { + self.webNavigationItem.prompt = [o description]; + }]; } #pragma mark - Actions diff --git a/platform-darwin/Source/iOS/MPiOSAppDelegate.m b/platform-darwin/Source/iOS/MPiOSAppDelegate.m index 67134516..82ccef1b 100644 --- a/platform-darwin/Source/iOS/MPiOSAppDelegate.m +++ b/platform-darwin/Source/iOS/MPiOSAppDelegate.m @@ -26,6 +26,20 @@ #import #import +@interface CountlyPushNotifications +@end + +@interface CountlyPushNotifications(MPNotifications) +@end + +@implementation CountlyPushNotifications(MPNotifications) + +- (void)openURL:(NSString *)URLString { + [UIApp.keyWindow.rootViewController performSegueWithIdentifier:@"web" sender:[NSURL URLWithString:URLString]]; +} + +@end + @interface MPiOSAppDelegate() @property(nonatomic, strong) UIDocumentInteractionController *interactionController; @@ -242,13 +256,13 @@ return NO; PearlMainQueue( ^{ - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Welcome to Master Password!" message: + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Diagnostics Opt-In" 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." + @"We look for bugs, sudden crashes, runtime issues & statistics.\n" + @"Needless to say, diagnostics are scrubbed and personal details will never leave your device." preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction actionWithTitle:@"Disable" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { + [alert addAction:[UIAlertAction actionWithTitle:@"Disable" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { [MPiOSConfig get].sendInfo = @(NO); [MPiOSConfig get].sendInfoDecided = @(YES); [self consentFeatures]; diff --git a/platform-darwin/Source/iOS/Storyboard.storyboard b/platform-darwin/Source/iOS/Storyboard.storyboard index 4cf4282f..a01415bb 100644 --- a/platform-darwin/Source/iOS/Storyboard.storyboard +++ b/platform-darwin/Source/iOS/Storyboard.storyboard @@ -69,7 +69,7 @@ - + @@ -472,13 +472,6 @@ - - - - - - - @@ -494,19 +487,14 @@ - - - - - @@ -2324,7 +2312,7 @@ Suspendisse potenti. Etiam ut nisi id augue tempor ultrices et sit amet sapien. - + @@ -2412,7 +2400,7 @@ However, it means that anyone who finds your device unlocked can do the same. - + @@ -3036,7 +3024,7 @@ Invested: 3.7 work hours - + @@ -3268,7 +3256,7 @@ Ut in geometria, prima si dederis, danda sunt omnia. Nonne igitur tibi videntur, - +