Theme Import/Opening Changes

Mac:
- Better error messages
- The alert displayed contains an additional button to open the theme's folder (when clicked it will not dismiss the alert).
This commit is contained in:
Stuart Breckenridge 2021-09-23 20:12:35 +08:00
parent f73426f397
commit e9b84d9219
3 changed files with 25 additions and 13 deletions

View File

@ -107,6 +107,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
private var softwareUpdater: SPUUpdater!
private var crashReporter: PLCrashReporter!
#endif
private var themeImportPath: String?
override init() {
NSWindow.allowsAutomaticWindowTabbing = false
@ -890,15 +892,11 @@ internal extension AppDelegate {
} else {
importTheme()
}
}
}
} catch {
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error" : error])
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error" : error, "path": filename])
}
}
func confirmImportSuccess(themeName: String) {
@ -921,16 +919,16 @@ internal extension AppDelegate {
let window = mainWindowController?.window else {
return
}
themeImportPath = userInfo["path"] as? String
var informativeText: String = ""
if let decodingError = error as? DecodingError {
switch decodingError {
case .typeMismatch(let type, _):
informativeText = "Type '\(type)' mismatch."
informativeText = "the type—'\(type)'—is mismatched."
case .valueNotFound(let value, _):
informativeText = "Value '\(value)' not found."
informativeText = "the value—'\(value)'—is not found."
case .keyNotFound(let codingKey, _):
informativeText = "Key '\(codingKey.stringValue)' not found."
informativeText = "the key—'\(codingKey.stringValue)'—is not found."
case .dataCorrupted( _):
informativeText = error.localizedDescription
default:
@ -944,9 +942,25 @@ internal extension AppDelegate {
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("Theme Error", comment: "Theme download error")
alert.informativeText = NSLocalizedString("This theme cannot be imported due to the following error: \(informativeText)", comment: "Theme download error information")
alert.informativeText = NSLocalizedString("This theme cannot be used because \(informativeText)", comment: "Theme download error information")
alert.addButton(withTitle: NSLocalizedString("Open Theme Folder", comment: "Open Theme Folder"))
alert.addButton(withTitle: NSLocalizedString("OK", comment: "OK"))
alert.beginSheetModal(for: window)
let button = alert.buttons.first
button?.target = self
button?.action = #selector(self.openThemesFolder(_:))
alert.runModal()
}
}
@objc func openThemesFolder(_ sender: Any) {
if themeImportPath == nil {
let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)
NSWorkspace.shared.open(url)
} else {
let url = URL(fileURLWithPath: themeImportPath!)
NSWorkspace.shared.open(url.deletingLastPathComponent())
}
}

View File

@ -58,7 +58,6 @@ struct ArticleTheme: Equatable {
let data = try Data(contentsOf: URL(fileURLWithPath: infoPath))
self.info = try PropertyListDecoder().decode(ArticleThemePlist.self, from: data)
let corePath = Bundle.main.path(forResource: "core", ofType: "css")!
let stylesheetPath = (path as NSString).appendingPathComponent("stylesheet.css")
if let stylesheetCSS = Self.stringAtPath(stylesheetPath) {

View File

@ -22,7 +22,6 @@ public class ArticleThemeDownloader {
}
}
public static let shared = ArticleThemeDownloader()
private init() {}