Importing: Only the main thread shall access lastFileImportErrorText

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-03-05 15:57:11 +05:30
parent 90c0f7e92e
commit fe4f8b666d
1 changed files with 8 additions and 8 deletions

View File

@ -33,22 +33,22 @@ class TunnelImporter {
do { do {
fileContents = try String(contentsOf: url) fileContents = try String(contentsOf: url)
} catch let error { } catch let error {
DispatchQueue.main.async {
if let cocoaError = error as? CocoaError, cocoaError.isFileError { if let cocoaError = error as? CocoaError, cocoaError.isFileError {
lastFileImportErrorText = (title: tr("alertCantOpenInputConfFileTitle"), message: error.localizedDescription) lastFileImportErrorText = (title: tr("alertCantOpenInputConfFileTitle"), message: error.localizedDescription)
} else { } else {
lastFileImportErrorText = (title: tr("alertCantOpenInputConfFileTitle"), message: tr(format: "alertCantOpenInputConfFileMessage (%@)", fileName)) lastFileImportErrorText = (title: tr("alertCantOpenInputConfFileTitle"), message: tr(format: "alertCantOpenInputConfFileMessage (%@)", fileName))
} }
DispatchQueue.main.async {
configs.append(nil) configs.append(nil)
dispatchGroup.leave() dispatchGroup.leave()
} }
return return
} }
let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName)
DispatchQueue.main.async {
if tunnelConfiguration == nil { if tunnelConfiguration == nil {
lastFileImportErrorText = (title: tr("alertBadConfigImportTitle"), message: tr(format: "alertBadConfigImportMessage (%@)", fileName)) lastFileImportErrorText = (title: tr("alertBadConfigImportTitle"), message: tr(format: "alertBadConfigImportMessage (%@)", fileName))
} }
DispatchQueue.main.async {
configs.append(tunnelConfiguration) configs.append(tunnelConfiguration)
dispatchGroup.leave() dispatchGroup.leave()
} }