From 5af383235aaa472166bb424fe4af9755748d10ef Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Mon, 1 May 2017 18:40:51 -0400 Subject: [PATCH] Fix issue causing site list to appear empty on login. --- .../Source/iOS/MPPasswordsViewController.m | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/platform-darwin/Source/iOS/MPPasswordsViewController.m b/platform-darwin/Source/iOS/MPPasswordsViewController.m index 82e42d6d..1169907e 100644 --- a/platform-darwin/Source/iOS/MPPasswordsViewController.m +++ b/platform-darwin/Source/iOS/MPPasswordsViewController.m @@ -81,6 +81,24 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) { [self registerObservers]; [self updateConfigKey:nil]; + + static NSRegularExpression *bareHostRE = nil; + static dispatch_once_t once = 0; + dispatch_once( &once, ^{ + bareHostRE = [NSRegularExpression regularExpressionWithPattern:@"([^\\.]+\\.[^\\.]+)$" options:0 error:nil]; + } ); + + NSURL *pasteboardURL = nil; + UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + if ([pasteboard respondsToSelector:@selector( hasURLs )]) + pasteboardURL = pasteboard.hasURLs? pasteboard.URL: nil; + else + pasteboardURL = [NSURL URLWithString:pasteboard.string]; + + if (pasteboardURL.host) + self.query = NSNullToNil( [pasteboardURL.host firstMatchGroupsOfExpression:bareHostRE][0] ); + else + [self reloadPasswords]; } - (void)viewDidAppear:(BOOL)animated { @@ -300,12 +318,6 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) { - (void)registerObservers { - static NSRegularExpression *bareHostRE = nil; - static dispatch_once_t once = 0; - dispatch_once( &once, ^{ - bareHostRE = [NSRegularExpression regularExpressionWithPattern:@"([^\\.]+\\.[^\\.]+)$" options:0 error:nil]; - } ); - PearlRemoveNotificationObservers(); PearlAddNotificationObserver( UIApplicationWillResignActiveNotification, nil, [NSOperationQueue mainQueue], ^(MPPasswordsViewController *self, NSNotification *note) { @@ -313,22 +325,14 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) { } ); PearlAddNotificationObserver( UIApplicationDidBecomeActiveNotification, nil, [NSOperationQueue mainQueue], ^(MPPasswordsViewController *self, NSNotification *note) { - NSURL *pasteboardURL = nil; - UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; - if ([pasteboard respondsToSelector:@selector( hasURLs )]) - pasteboardURL = pasteboard.hasURLs? pasteboard.URL: nil; - else - pasteboardURL = [NSURL URLWithString:pasteboard.string]; - - if (pasteboardURL.host) - self.query = NSNullToNil( [pasteboardURL.host firstMatchGroupsOfExpression:bareHostRE][0] ); - else - [self reloadPasswords]; - [UIView animateWithDuration:0.7f animations:^{ self.passwordSelectionContainer.visible = YES; }]; } ); + PearlAddNotificationObserver( UIApplicationWillEnterForegroundNotification, nil, [NSOperationQueue mainQueue], + ^(MPPasswordsViewController *self, NSNotification *note) { + [self viewWillAppear:YES]; + } ); PearlAddNotificationObserver( MPSignedOutNotification, nil, nil, ^(MPPasswordsViewController *self, NSNotification *note) { PearlMainQueue( ^{