From bed1cff292d5997b1b5a822be48ed92d31db9590 Mon Sep 17 00:00:00 2001 From: Max Lohrmann Date: Sat, 22 Apr 2017 18:30:55 +0200 Subject: * Fix a case of "background thread updating UI" (may affect some crashes when importing CSVs) --- Source/SPAppController.m | 2 +- Source/SPDataImport.m | 43 ++++++++++++++++++++++--------------------- Source/SPTableContent.m | 16 +++++++++------- Source/SPTablesList.m | 4 +++- 4 files changed, 35 insertions(+), 30 deletions(-) (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 3028c0f6..afdfd16f 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -770,7 +770,7 @@ } else { NSBeep(); - NSLog(@"Error in sequelpro URL scheme"); + NSLog(@"Error in sequelpro URL scheme for URL <%@>",url); } } diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index 058ff916..6522885c 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -1213,29 +1213,30 @@ document:tableDocumentInstance notificationName:@"Import Finished"]; + SPMainQSync(^{ + if(importIntoNewTable) { - if(importIntoNewTable) { - - // Select the new table - - // Update current database tables - [[tablesListInstance onMainThread] updateTables:self]; - - // Re-query the structure of all databases in the background - [[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}]; - - // Select the new table - [tablesListInstance selectItemWithName:selectedTableTarget]; - - } else { - - // If import was done into a new table or the table selected for import is also selected in the content view, - // update the content view - on the main thread to avoid crashes. - if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) { - [tableDocumentInstance setContentRequiresReload:YES]; + // Select the new table + + // Update current database tables + [tablesListInstance updateTables:self]; + + // Re-query the structure of all databases in the background + [[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}]; + + // Select the new table + [tablesListInstance selectItemWithName:selectedTableTarget]; + + } else { + + // If import was done into a new table or the table selected for import is also selected in the content view, + // update the content view - on the main thread to avoid crashes. + if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) { + [tableDocumentInstance setContentRequiresReload:YES]; + } + } - - } + }); } diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 0738fe96..62f3b758 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2541,13 +2541,15 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper @"filterValue": targetFilterValue, @"filterComparison": SPBoxNil(filterComparison) }; - [self setFiltersToRestore:filterSettings]; - - // Attempt to switch to the target table - if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) { - NSBeep(); - [self setFiltersToRestore:nil]; - } + SPMainQSync(^{ + [self setFiltersToRestore:filterSettings]; + + // Attempt to switch to the target table + if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) { + NSBeep(); + [self setFiltersToRestore:nil]; + } + }); } #ifndef SP_CODA diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index 2fa26229..27810898 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -1370,6 +1370,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; /** * Select an item using the provided name; returns YES if the * supplied name could be selected, or NO if not. + * + * MUST BE CALLED ON THE UI THREAD! */ - (BOOL)selectItemWithName:(NSString *)theName { @@ -1418,7 +1420,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; } } - [[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]]; + [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; #endif return YES; -- cgit v1.2.3