From 635692ef091c4edbe74b65cb6d284743ca4444c4 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 4f8eb281..2995973e 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 { @@ -301,12 +319,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) { @@ -315,22 +327,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( ^{