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/SPDataImport.m | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'Source/SPDataImport.m') 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]; + } + } - - } + }); } -- cgit v1.2.3 From 16e6af773c3f3262bff9fa7da63ad9bf0e5e4828 Mon Sep 17 00:00:00 2001 From: Facundo Date: Sat, 29 Apr 2017 14:36:00 +0100 Subject: Implement progress for BZ2 file import --- Source/SPDataImport.m | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'Source/SPDataImport.m') diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index 6522885c..4c680801 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -162,6 +162,7 @@ { SPMainQSync(^{ [NSApp endSheet:singleProgressSheet]; + [singleProgressBar setIndeterminate:YES]; [singleProgressSheet orderOut:nil]; [singleProgressBar stopAnimation:self]; [singleProgressBar setMaxValue:100]; @@ -397,16 +398,12 @@ fileTotalLength = (NSUInteger)[[[[NSFileManager defaultManager] attributesOfItemAtPath:filename error:NULL] objectForKey:NSFileSize] longLongValue]; if (!fileTotalLength) fileTotalLength = 1; - // If importing a bzipped file, use indeterminate progress bars as no progress is available - BOOL useIndeterminate = NO; - if ([sqlFileHandle compressionFormat] == SPBzip2Compression) useIndeterminate = YES; - SPMainQSync(^{ // Reset progress interface [errorsView setString:@""]; [singleProgressTitle setStringValue:NSLocalizedString(@"Importing SQL", @"text showing that the application is importing SQL")]; [singleProgressText setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")]; - [singleProgressBar setIndeterminate:useIndeterminate]; + [singleProgressBar setIndeterminate:NO]; [singleProgressBar setMaxValue:fileTotalLength]; [singleProgressBar setUsesThreadedAnimation:YES]; [singleProgressBar startAnimation:self]; @@ -787,16 +784,12 @@ if (!fileTotalLength) fileTotalLength = 1; fileIsCompressed = ([csvFileHandle compressionFormat] != SPNoCompression); - // If importing a bzipped file, use indeterminate progress bars as no progress is available - BOOL useIndeterminate = NO; - if ([csvFileHandle compressionFormat] == SPBzip2Compression) useIndeterminate = YES; - // Reset progress interface SPMainQSync(^{ [errorsView setString:@""]; [singleProgressTitle setStringValue:NSLocalizedString(@"Importing CSV", @"text showing that the application is importing CSV")]; [singleProgressText setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")]; - [singleProgressBar setIndeterminate:YES]; + [singleProgressBar setIndeterminate:NO]; [singleProgressBar setUsesThreadedAnimation:YES]; [singleProgressBar startAnimation:self]; @@ -971,8 +964,8 @@ // Reset progress interface and open the progress sheet SPMainQSync(^{ - [singleProgressBar setIndeterminate:useIndeterminate]; [singleProgressBar setMaxValue:fileTotalLength]; + [singleProgressBar setIndeterminate:NO]; [singleProgressBar startAnimation:self]; [NSApp beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil]; [singleProgressSheet makeKeyWindow]; -- cgit v1.2.3