mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
make decodeTheme cleaner, still works yayyy
This commit is contained in:
@@ -51,11 +51,15 @@ struct Theme: Hashable, Equatable, Identifiable {
|
|||||||
|
|
||||||
static func decodeTheme(name: String, data: Data?) -> Theme? {
|
static func decodeTheme(name: String, data: Data?) -> Theme? {
|
||||||
guard let data else { return nil }
|
guard let data else { return nil }
|
||||||
guard let string = String(data: data, encoding: .utf8) else { return nil }
|
|
||||||
|
|
||||||
if string.contains("plist") {
|
let plistDecoder = PropertyListDecoder()
|
||||||
guard let decoded = try? PropertyListDecoder().decode(ThemeCodable.self, from: data) else { return nil }
|
let jsonDecoder = JSONDecoder()
|
||||||
return Theme(
|
|
||||||
|
guard let decoded =
|
||||||
|
(try? plistDecoder.decode(ThemeCodable.self, from: data)) ??
|
||||||
|
(try? jsonDecoder.decode(ThemeCodable.self, from: data))
|
||||||
|
else { return nil }
|
||||||
|
let theme = Theme(
|
||||||
name: name,
|
name: name,
|
||||||
ansi: decoded.ansi,
|
ansi: decoded.ansi,
|
||||||
foreground: Color(decoded.foreground),
|
foreground: Color(decoded.foreground),
|
||||||
@@ -66,20 +70,7 @@ struct Theme: Hashable, Equatable, Identifiable {
|
|||||||
selectedText: Color(decoded.selectedText),
|
selectedText: Color(decoded.selectedText),
|
||||||
selection: Color(decoded.selection)
|
selection: Color(decoded.selection)
|
||||||
)
|
)
|
||||||
} else {
|
return theme
|
||||||
guard let decoded = try? JSONDecoder().decode(ThemeCodable.self, from: data) else { return nil }
|
|
||||||
return Theme(
|
|
||||||
name: name,
|
|
||||||
ansi: decoded.ansi,
|
|
||||||
foreground: Color(decoded.foreground),
|
|
||||||
background: Color(decoded.background),
|
|
||||||
cursor: Color(decoded.cursor),
|
|
||||||
cursorText: Color(decoded.cursorText),
|
|
||||||
bold: Color(decoded.bold),
|
|
||||||
selectedText: Color(decoded.selectedText),
|
|
||||||
selection: Color(decoded.selection)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user