Skip to content

Commit

Permalink
Fix refresh OTP Edit in Browse View. 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McGuill committed Jan 24, 2019
1 parent 77ed246 commit 10caab2
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 144 deletions.
77 changes: 50 additions & 27 deletions StrongBox Auto Fill/Base.lproj/MainInterface.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions StrongBox Auto Fill/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.21.0</string>
<string>1.21.1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -30,7 +30,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2631</string>
<string>2632</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down
65 changes: 39 additions & 26 deletions StrongBox/BrowseSafeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self refresh];

if(self.timerRefreshOtp) {
[self.timerRefreshOtp invalidate];
self.timerRefreshOtp = nil;
}

if(!Settings.sharedInstance.hideTotpInBrowse) {
self.timerRefreshOtp = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateOtpCodes:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timerRefreshOtp forMode:NSRunLoopCommonModes];
}
}

- (void)viewWillDisappear:(BOOL)animated {
Expand All @@ -87,7 +77,9 @@ - (void)viewWillDisappear:(BOOL)animated {
}

- (IBAction)updateOtpCodes:(id)sender {
[self.tableView reloadData];
if(![self.tableView isEditing]) { // DO not update during edit, cancels left swipe menu and edit selections!
[self.tableView reloadData]; // FUTURE: Only update OTP rows
}
}

- (void)viewDidLoad {
Expand Down Expand Up @@ -303,25 +295,30 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.accessoryType = UITableViewCellAccessoryNone;
cell.icon.image = [NodeIconHelper getIconForNode:node database:self.viewModel.database];
cell.flags.text = node.fields.attachments.count > 0 ? @"📎" : @"";

[self setOtpCellProperties:cell node:node];

if(!Settings.sharedInstance.hideTotpInBrowse && node.otpToken) {
uint64_t remainingSeconds = node.otpToken.period - ((uint64_t)([NSDate date].timeIntervalSince1970) % (uint64_t)node.otpToken.period);
return cell;
}
}

cell.otpCode.text = [NSString stringWithFormat:@"%@", node.otpToken.password];
cell.otpCode.textColor = (remainingSeconds < 5) ? [UIColor redColor] : (remainingSeconds < 9) ? [UIColor orangeColor] : [UIColor blueColor];
- (void)setOtpCellProperties:(BrowseSafeEntryTableViewCell*)cell node:(Node*)node {
if(!Settings.sharedInstance.hideTotpInBrowse && node.otpToken) {
uint64_t remainingSeconds = node.otpToken.period - ((uint64_t)([NSDate date].timeIntervalSince1970) % (uint64_t)node.otpToken.period);

cell.otpCode.alpha = 1;

if(remainingSeconds < 16) {
[UIView animateWithDuration:0.45 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
cell.otpCode.alpha = 0.5;
} completion:nil];
}
}
else {
cell.otpCode.text = @"";
cell.otpCode.text = [NSString stringWithFormat:@"%@", node.otpToken.password];
cell.otpCode.textColor = (remainingSeconds < 5) ? [UIColor redColor] : (remainingSeconds < 9) ? [UIColor orangeColor] : [UIColor blueColor];

cell.otpCode.alpha = 1;

if(remainingSeconds < 16) {
[UIView animateWithDuration:0.45 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
cell.otpCode.alpha = 0.5;
} completion:nil];
}
return cell;
}
else {
cell.otpCode.text = @"";
}
}

Expand Down Expand Up @@ -449,6 +446,22 @@ - (void)refresh {
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.hidden = NO;
[self.navigationController setNavigationBarHidden:NO];

// Any OTPs we should start a refresh timer if so...

[self startOtpRefreshTimerIfAppropriate];
}

- (void)startOtpRefreshTimerIfAppropriate {
if(self.timerRefreshOtp) {
[self.timerRefreshOtp invalidate];
self.timerRefreshOtp = nil;
}

if(!Settings.sharedInstance.hideTotpInBrowse) {
self.timerRefreshOtp = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateOtpCodes:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timerRefreshOtp forMode:NSRunLoopCommonModes];
}
}

- (NSString *)getGroupPathDisplayString:(Node *)vm {
Expand Down
8 changes: 6 additions & 2 deletions StrongBox/OpenSafeSequenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ - (instancetype)initWithViewController:(UIViewController*)viewController
- (void)beginSequence {
if (self.safe.isEnrolledForConvenience && Settings.sharedInstance.isProOrFreeTrial) {
BOOL biometricPossible = !Settings.sharedInstance.disallowAllBiometricId && self.safe.isTouchIdEnabled && Settings.isBiometricIdAvailable;
if(biometricPossible) {

// Show biometric if possible... unless BOTH Bio & PIN are configured but PIN has been disabled, then fall back to full master credentials
if(biometricPossible && !(self.safe.conveniencePin != nil && Settings.sharedInstance.disallowAllPinCodeOpens)) {
[self showBiometricAuthentication];
}
else if(!Settings.sharedInstance.disallowAllPinCodeOpens && self.safe.conveniencePin != nil) {
// Only show PIN code now if it is enabled exclusively (i.e. not also with Touch ID) because if for some
// other reason biometric is disabled we want to fallback to master credentials
else if(!Settings.sharedInstance.disallowAllPinCodeOpens && self.safe.conveniencePin != nil && !self.safe.isTouchIdEnabled) {
[self promptForConveniencePin];
}
else {
Expand Down
4 changes: 2 additions & 2 deletions StrongBox/StrongBox-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.21.0</string>
<string>1.21.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -120,7 +120,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2631</string>
<string>2632</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-1</string>
Expand Down
26 changes: 0 additions & 26 deletions lib/OneTimePassword/Info.plist

This file was deleted.

4 changes: 0 additions & 4 deletions macbox/MacBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
4D8DE9BE21F898470043DDC0 /* OTPToken+Persistence.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D8DE9B321F898460043DDC0 /* OTPToken+Persistence.m */; };
4D8DE9BF21F898470043DDC0 /* OTPAlgorithm.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D8DE9B421F898470043DDC0 /* OTPAlgorithm.m */; };
4D8DE9C021F898470043DDC0 /* OTPToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D8DE9B521F898470043DDC0 /* OTPToken.m */; };
4D8DE9C121F898470043DDC0 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4D8DE9B821F898470043DDC0 /* Info.plist */; };
4D92C8271F38A03500341A58 /* WindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D92C8261F38A03500341A58 /* WindowController.m */; };
4D9E098021825108007BA1E7 /* XmlStrongboxNodeModelAdaptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D9E095121825103007BA1E7 /* XmlStrongboxNodeModelAdaptor.m */; };
4D9E098121825108007BA1E7 /* Entry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D9E095221825103007BA1E7 /* Entry.m */; };
Expand Down Expand Up @@ -314,7 +313,6 @@
4D8DE9B521F898470043DDC0 /* OTPToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OTPToken.m; path = ../lib/OneTimePassword/OTPToken.m; sourceTree = "<group>"; };
4D8DE9B621F898470043DDC0 /* OTPToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OTPToken.h; path = ../lib/OneTimePassword/OTPToken.h; sourceTree = "<group>"; };
4D8DE9B721F898470043DDC0 /* OTPToken+Generation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OTPToken+Generation.h"; path = "../lib/OneTimePassword/OTPToken+Generation.h"; sourceTree = "<group>"; };
4D8DE9B821F898470043DDC0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../lib/OneTimePassword/Info.plist; sourceTree = "<group>"; };
4D8DE9B921F898470043DDC0 /* NSURL+QueryItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSURL+QueryItems.h"; path = "../lib/OneTimePassword/NSURL+QueryItems.h"; sourceTree = "<group>"; };
4D92C8251F38A03500341A58 /* WindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WindowController.h; path = MacBox/WindowController.h; sourceTree = "<group>"; };
4D92C8261F38A03500341A58 /* WindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WindowController.m; path = MacBox/WindowController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -733,7 +731,6 @@
4D8DE9A921F898240043DDC0 /* OneTimePassword */ = {
isa = PBXGroup;
children = (
4D8DE9B821F898470043DDC0 /* Info.plist */,
4D8DE9B921F898470043DDC0 /* NSURL+QueryItems.h */,
4D8DE9AB21F898460043DDC0 /* NSURL+QueryItems.m */,
4D8DE9B021F898460043DDC0 /* OneTimePassword.h */,
Expand Down Expand Up @@ -1058,7 +1055,6 @@
4DDCE1CC21BBFF7800D1DE09 /* ProgressWindow.xib in Resources */,
4D23BBF4216136D10054C8D0 /* formatV3.txt in Resources */,
4D524D13219B4AD500C22CB4 /* google-10000-english-usa-no-swears-medium.txt in Resources */,
4D8DE9C121F898470043DDC0 /* Info.plist in Resources */,
4DEAEC2A1F3DDF61000CE3A6 /* ChangeMasterPasswordWindowController.xib in Resources */,
4D88AD4F21E654E700B49149 /* SourceSansPro-Bold.ttf in Resources */,
4D23BBF5216136D10054C8D0 /* formatV4.txt in Resources */,
Expand Down
62 changes: 47 additions & 15 deletions macbox/MacBox/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

[self removeShowSafesMetaDataItem];
//BiometricIdHelper.sharedInstance.dummyMode = YES; // DEBUG

if(![Settings sharedInstance].fullVersion) {
[self getValidIapProducts];

[self getValidIapProductsAndMessageForUpgrade];
if([Settings sharedInstance].endFreeTrialDate == nil) {
[self initializeFreeTrialAndShowWelcomeMessage];
}
else if(![Settings sharedInstance].freeTrial){
[self randomlyShowUpgradeMessage];
}
}
else {
[self removeUpgradeMenuItem];
Expand Down Expand Up @@ -117,7 +114,9 @@ - (void)randomlyShowUpgradeMessage {
}
}

- (void)getValidIapProducts {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)getValidIapProductsAndMessageForUpgrade {
NSSet *productIdentifiers = [NSSet setWithObjects:kIapFullVersionStoreId, nil];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self;
Expand All @@ -127,18 +126,51 @@ - (void)getValidIapProducts {
-(void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
NSUInteger count = [response.products count];
if (count > 0) {
self.validProducts = response.products;
for (SKProduct *validProduct in self.validProducts) {
NSLog(@"%@", validProduct.productIdentifier);
NSLog(@"%@", validProduct.localizedTitle);
NSLog(@"%@", validProduct.localizedDescription);
NSLog(@"%@", validProduct.price);
dispatch_async(dispatch_get_main_queue(), ^{
[self appStoreProductRequestCompleted:response.products error:nil];
});
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{
[self appStoreProductRequestCompleted:nil error:error];
});
}

- (void)appStoreProductRequestCompleted:(NSArray<SKProduct *> *)products error:(NSError*)error {
if(products) {
NSUInteger count = [products count];
if (count > 0) {
self.validProducts = products;
for (SKProduct *validProduct in self.validProducts) {
NSLog(@"%@", validProduct.productIdentifier);
NSLog(@"%@", validProduct.localizedTitle);
NSLog(@"%@", validProduct.localizedDescription);
NSLog(@"%@", validProduct.price);
}
}

if(![Settings sharedInstance].freeTrial){
[self randomlyShowUpgradeMessage];
}
}
else {
[Alerts error:@"Error Contacting App Store for Upgrade Info" error:error window:[NSApplication sharedApplication].mainWindow];
}
}

- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem {
SEL theAction = [anItem action];

if (theAction == @selector(onUpgradeToFullVersion:)) {
return self.validProducts != nil;
}

return YES;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)removeUnwantedMenuItems {
// Remove Start Dictation and Emoji menu Items

Expand Down
4 changes: 2 additions & 2 deletions macbox/MacBox/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.1</string>
<string>1.4.2</string>
<key>CFBundleVersion</key>
<string>2619</string>
<string>2620</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
11 changes: 6 additions & 5 deletions macbox/MacBox/UpgradeWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ + (BOOL)run:(SKProduct*)product cancelDelay:(NSInteger)cancelDelay
windowController.product = product;
windowController.cancelDelay = cancelDelay;

if ([NSApp runModalForWindow:windowController.window]) {
NSModalResponse response = [NSApp runModalForWindow:windowController.window];

if (response) {
return YES;
}

Expand Down Expand Up @@ -161,6 +163,8 @@ - (void) customizeButtonsBasedOnProduct {
}

- (void) startNoThanksCountdown {
NSLog(@"Starting No Thanks Countdown with %ld delay", (long)self.cancelDelay);

[self.buttonNoThanks setEnabled:NO];
[self.buttonNoThanks setTitle:[NSString stringWithFormat:@"No Thanks (%ld)", (long)self.cancelDelay]];

Expand All @@ -172,6 +176,7 @@ - (void) startNoThanksCountdown {

if(secondsRemaining < 1) {
[self.buttonNoThanks setTitle:@"No Thanks"];
[self.buttonNoThanks setEnabled:YES];
[timer invalidate];
}
else {
Expand All @@ -180,10 +185,6 @@ - (void) startNoThanksCountdown {
}];

[[NSRunLoop currentRunLoop] addTimer:y forMode:NSModalPanelRunLoopMode];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, self.cancelDelay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.buttonNoThanks setEnabled:YES];
});
}

- (void)showProgressIndicator {
Expand Down
Loading

0 comments on commit 10caab2

Please sign in to comment.