diff --git a/CloverApp/Clover.xcodeproj/project.pbxproj b/CloverApp/Clover.xcodeproj/project.pbxproj index 9008c795a..1fe11893e 100644 --- a/CloverApp/Clover.xcodeproj/project.pbxproj +++ b/CloverApp/Clover.xcodeproj/project.pbxproj @@ -1309,7 +1309,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1.22; + CURRENT_PROJECT_VERSION = 1.23; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Clover/Frameworks", @@ -1336,7 +1336,7 @@ "$(PROJECT_DIR)/Clover/Library", "$(PROJECT_DIR)", ); - MARKETING_VERSION = 1.22; + MARKETING_VERSION = 1.23; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = org.slice.Clover; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1357,7 +1357,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1.22; + CURRENT_PROJECT_VERSION = 1.23; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Clover/Frameworks", @@ -1383,7 +1383,7 @@ "$(PROJECT_DIR)/Clover/Library", "$(PROJECT_DIR)", ); - MARKETING_VERSION = 1.22; + MARKETING_VERSION = 1.23; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = org.slice.Clover; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/CloverApp/Clover/ThemeManager/ThemeManager.swift b/CloverApp/Clover/ThemeManager/ThemeManager.swift index a2e3fc1af..b9780f447 100644 --- a/CloverApp/Clover/ThemeManager/ThemeManager.swift +++ b/CloverApp/Clover/ThemeManager/ThemeManager.swift @@ -557,8 +557,10 @@ final class ThemeManager: NSObject, URLSessionDataDelegate { } return false } + /// Return the path for a given theme, if the download succeded public func download(theme: String, down: ThemeDownload, completion: @escaping (String?) -> ()) { + let advice = "Try to refresh the list by pressing the Refresh button below." self.statusError = nil if let sha = self.getSha() { let shaPath : String = self.basePath.addPath(sha) @@ -573,13 +575,21 @@ final class ThemeManager: NSObject, URLSessionDataDelegate { try fm.createDirectory(atPath: themeDest, withIntermediateDirectories: true, attributes: nil) - } catch {} + } catch { + let desc = "Unexpected error: '\(error)'" + let e = NSError(domain: "org.slice.Clover.Download.Error", + code: 3000, + userInfo :[NSLocalizedDescriptionKey : desc]) + + self.statusError = e + completion(nil) + return + } } - + let plistPath : String = "\(themeManagerIndexDir)/Themes/\(theme).plist" let themePlist = NSDictionary(contentsOfFile: plistPath) if let files : [String] = themePlist?.allKeys as? [String] { - // --------------------------------------- let fc : Int = files.count if fc > 0 { var succeded : Bool = true @@ -617,17 +627,43 @@ final class ThemeManager: NSObject, URLSessionDataDelegate { if succeded { completion(themeDest) } else { - completion(nil) + if self.statusError == nil { // downloadFile() generate a specific error + let desc = "Unknown error downloading '\(theme)' theme." + let e = NSError(domain: "org.slice.Clover.Download.Error", + code: 3001, + userInfo :[NSLocalizedDescriptionKey : desc]) + + self.statusError = e + } + completion(nil) } }) } else { + let desc = "'\(theme)' index file contains no file to download.\n\n\(advice)" + let e = NSError(domain: "org.slice.Clover.Download.Error", + code: 3002, + userInfo :[NSLocalizedDescriptionKey : desc]) + + self.statusError = e completion(nil) } } else { + let desc = "Unable to load '\(theme)' index file (not found or unreadable).\n\n\(advice)" + let e = NSError(domain: "org.slice.Clover.Download.Error", + code: 3003, + userInfo :[NSLocalizedDescriptionKey : desc]) + + self.statusError = e completion(nil) } } } else { + let desc = "sha1 directory not found.\n\n\(advice)" + let e = NSError(domain: "org.slice.Clover.Download.Error", + code: 3004, + userInfo :[NSLocalizedDescriptionKey : desc]) + + self.statusError = e completion(nil) } } diff --git a/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift b/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift index 298f3acaf..51cc5e3ed 100644 --- a/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift +++ b/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift @@ -455,7 +455,6 @@ NSComboBoxDataSource { let sr = self.sidebar.selectedRow if sr >= 0 && sr < self.dataSource().count { - // --------- self.isBusy = true self.spinner.startAnimation(nil) self.optimizeButton.isEnabled = false @@ -464,7 +463,7 @@ NSComboBoxDataSource { self.targetPop.isEnabled = false self.nameBox.isEnabled = false self.installedThemesCheckBox.isEnabled = false - // --------- + self.manager?.download(theme: theme, down: .complete, completion: { (path) in @@ -476,7 +475,9 @@ NSComboBoxDataSource { alert.messageText = "Installation failed".locale alert.informativeText = self.manager!.statusError!.localizedDescription alert.addButton(withTitle: "OK") - alert.runModal() + + alert.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in + }) } } else { if let themePath = path { @@ -498,17 +499,20 @@ NSComboBoxDataSource { alert.messageText = "Installation failed".locale alert.informativeText = "\(error.localizedDescription)" alert.addButton(withTitle: "OK") - alert.runModal() + alert.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in + }) } } } else { NSSound(named: "Basso")?.play() DispatchQueue.main.async { let alert = NSAlert() + let advice = "Try to refresh the list by pressing the Refresh button below." alert.messageText = "Installation failed".locale - alert.informativeText = "Theme \"\(theme)\" not found." + alert.informativeText = "Theme \"\(theme)\" cannot be downloaded.\n\n\(advice)" alert.addButton(withTitle: "OK") - alert.runModal() + alert.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in + }) } } }