Skip to content

Commit

Permalink
Merge pull request #659 from Sequel-Ace/stale-bookmarks
Browse files Browse the repository at this point in the history
Bookmarks improvements #changed
  • Loading branch information
Kaspik committed Dec 29, 2020
2 parents 01fa877 + 000b931 commit 2664a17
Show file tree
Hide file tree
Showing 21 changed files with 908 additions and 501 deletions.
18 changes: 18 additions & 0 deletions Resources/Localization/en.lproj/Localizable.strings
Expand Up @@ -3176,3 +3176,21 @@

/* connection view : ssl : key file picker : wrong format error title */
"“%@” is not a valid private key file." = "“%@” is not a valid private key file.";

/* text shown when there are App Sandbox Issues */
"App Sandbox Issue" = "App Sandbox Issue";

/* Stale Bookmarks error title */
"Stale Bookmarks" = "Stale Bookmarks";

/* Question to user to see if they would like to re-request access */
"You have stale secure bookmarks:\n\n%@\n\nWould you like to re-request access now?" = "You have stale secure bookmarks:\n\n%@\n\nWould you like to re-request access now?";

/* The answer, yes */
"Yes" = "Yes";

/* Shown to remind users of their stale bookmarks */
"A reminder of your stale secure bookmarks:<br /><br />%@<br />" = "A reminder of your stale secure bookmarks:<br /><br />%@<br />";

/* Title for Stale Secure Bookmarks help window */
"Stale Secure Bookmarks" = "Stale Secure Bookmarks";
1 change: 1 addition & 0 deletions Resources/Localization/es-ES.lproj/Localizable.strings
Expand Up @@ -3173,3 +3173,4 @@

/* connection view : ssl : key file picker : wrong format error title */
"“%@” is not a valid private key file." = "“%@” is not a valid private key file.";

12 changes: 8 additions & 4 deletions Source/Controllers/BundleSupport/SPBundleHTMLOutputController.m
Expand Up @@ -94,9 +94,12 @@ - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displ
{
[[self window] orderFront:nil];
// [[self window] makeKeyAndOrderFront:nil];

// only do this if invoked with SPConnectionShownSocketHelp = YES in the displayOptions
if(displayOptions.count > 0 && [[displayOptions objectForKey:SPConnectionShownSocketHelp] boolValue] == YES){

BOOL shownSocketHelp = [[displayOptions objectForKey:SPConnectionShownSocketHelp] boolValue];
BOOL staleBookmarksHelp = [[displayOptions objectForKey:SPStaleBookmarksHelp] boolValue];

// only do this if invoked with SPConnectionShownSocketHelp = YES or SPStaleBookmarksHelp == YES in the displayOptions
if(displayOptions.count > 0 && (shownSocketHelp == YES || staleBookmarksHelp == YES )){
if([displayOptions objectForKey:@"frame"] != nil){
SPLog(@"Changing frame rect");

Expand All @@ -106,7 +109,8 @@ - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displ
// save the current frame for restore
origFrame = CGRectMake(tmpFrame.origin.x,tmpFrame.origin.y, tmpFrame.size.width, tmpFrame.size.height );
restoreFrame = YES;
windowType = SPConnectionShownSocketHelp;
windowType = (shownSocketHelp == YES) ? SPConnectionShownSocketHelp : ((staleBookmarksHelp == YES) ? SPStaleBookmarksHelp : @"" );
SPLog(@"windowType: %@", windowType);
// set the new wider frame
[[self window] setFrame:CGRectMake([frameDict[@"x"] doubleValue], [frameDict[@"y"] doubleValue], [frameDict[@"w"] doubleValue], [frameDict[@"h"] doubleValue]) display:YES];

Expand Down
87 changes: 13 additions & 74 deletions Source/Controllers/DataExport/SPExportController.m
Expand Up @@ -202,8 +202,8 @@ - (instancetype)init
exporters = [[NSMutableArray alloc] init];
exportFiles = [[NSMutableArray alloc] init];
operationQueue = [[NSOperationQueue alloc] init];
bookmarks = [[NSMutableArray alloc] init];
bookmarks = [NSMutableArray arrayWithArray:SecureBookmarkManager.sharedInstance.bookmarks];

showAdvancedView = NO;
showCustomFilenameView = NO;
serverLowerCaseTableNameValue = NSNotFound;
Expand Down Expand Up @@ -288,16 +288,7 @@ - (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format using

// initially popuplate the tables list
[self refreshTableList:nil];

id o;
if((o = [prefs objectForKey:SPSecureBookmarks])){
[bookmarks setArray:o];
}
else{
SPLog(@"Could not load SPSecureBookmarks from prefs");
CLS_LOG(@"Could not load SPSecureBookmarks from prefs");
}


// overwrite defaults with user settings from last export
[self applySettingsFromDictionary:[prefs objectForKey:SPLastExportSettings] error:NULL];

Expand Down Expand Up @@ -630,47 +621,11 @@ - (IBAction)changeExportOutputPath:(id)sender
}

[self->exportPathField setStringValue:path];

// the code always seems to go into this block as the
// user has selected the folder and we have com.apple.security.files.user-selected.read-write
if([self->changeExportOutputPathPanel.URL startAccessingSecurityScopedResource] == YES){
SPLog(@"got access to: %@", self->changeExportOutputPathPanel.URL.absoluteString);
CLS_LOG(@"got access to: %@", self->changeExportOutputPathPanel.URL.absoluteString);

BOOL __block beenHereBefore = NO;

// have we been here before?
[self.bookmarks enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {

if(dict[self->changeExportOutputPathPanel.URL.absoluteString] != nil){
NSLog(@"beenHereBefore: %@", dict[self->changeExportOutputPathPanel.URL.absoluteString]);
beenHereBefore = YES;
*stop = YES;
}
}];

if(beenHereBefore == NO){
// create a bookmark
NSError *error = nil;
NSData *tmpAppScopedBookmark = [self->changeExportOutputPathPanel.URL bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope // this needs to be read-write
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&error];
// save to prefs
if(tmpAppScopedBookmark && !error) {
[self->bookmarks addObject:@{self->changeExportOutputPathPanel.URL.absoluteString : tmpAppScopedBookmark}];
[self->prefs setObject:self->bookmarks forKey:SPSecureBookmarks];
}
else{
SPLog(@"Problem creating bookmark - %@ : %@",self->changeExportOutputPathPanel.URL.absoluteString, [error localizedDescription]);
CLS_LOG(@"Problem creating bookmark - %@ : %@",self->changeExportOutputPathPanel.URL.absoluteString, [error localizedDescription]);
}
}
}
else{
SPLog(@"Problem startAccessingSecurityScopedResource for - %@",self->changeExportOutputPathPanel.URL.absoluteString);
CLS_LOG(@"Problem startAccessingSecurityScopedResource for - %@",self->changeExportOutputPathPanel.URL.absoluteString);
}

// this needs to be read-write
if([SecureBookmarkManager.sharedInstance addBookmarkForUrl:self->changeExportOutputPathPanel.URL options:(NSURLBookmarkCreationWithSecurityScope)] == YES){
SPLog(@"addBookmarkForUrl success");
}
}
}];
}
Expand Down Expand Up @@ -3162,27 +3117,11 @@ - (BOOL)applySettingsFromDictionary:(NSDictionary *)dict error:(NSError **)err
// look up that bookmark and request access
if(bookmarks.count > 0){
if((o = [dict objectForKey:@"exportPath"])) [exportPathField setStringValue:o];

NSError __block *error = nil;

[self.bookmarks enumerateObjectsUsingBlock:^(NSDictionary *dict2, NSUInteger idx, BOOL *stop) {

NSString *tmpStr = [NSURL fileURLWithPath:[exportPathField stringValue] isDirectory:YES].absoluteString;

if(dict2[tmpStr] != nil){
self.userChosenDirectory = [NSURL URLByResolvingBookmarkData:dict2[tmpStr]
options:NSURLBookmarkResolutionWithSecurityScope
relativeToURL:nil
bookmarkDataIsStale:nil
error:&error];
*stop = YES;
}
}];

// if no bookmark was found this just calls against nil
if(!error){
[userChosenDirectory startAccessingSecurityScopedResource];
}

NSString *fileURLString = [NSURL fileURLWithPath:[exportPathField stringValue] isDirectory:YES].absoluteString;

// ret value can be nil
userChosenDirectory = [SecureBookmarkManager.sharedInstance bookmarkForFilename:fileURLString];
}

SPExportType et;
Expand Down
Expand Up @@ -232,7 +232,6 @@ typedef NS_ENUM(NSInteger, SPConnectionTimeZoneMode) {
@property (readwrite, copy) NSString *connectionSSHKeychainItemAccount;
@property (readwrite) BOOL useCompression;
@property (readwrite, strong) NSMutableArray<NSDictionary<NSString *, id> *> *bookmarks;
@property (readwrite, strong) NSMutableArray<NSURL *> *resolvedBookmarks;

@property (readonly) BOOL isConnecting;
@property (readonly) BOOL isEditingConnection;
Expand Down Expand Up @@ -260,7 +259,6 @@ typedef NS_ENUM(NSInteger, SPConnectionTimeZoneMode) {
-(BOOL)validateCertFile:(NSURL *)url error:(NSError **)outError;
-(BOOL)validateKeyFile:(NSURL *)url error:(NSError **)outError;
-(void)showValidationAlertForError:(NSError*)err;
-(void)reRequestSecureAccess;
-(BOOL)connected;

// Favorites interaction
Expand Down

0 comments on commit 2664a17

Please sign in to comment.