mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
theme loading works!! before i tried decoding the entire array when it expected one theme lol
This commit is contained in:
@@ -29,7 +29,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
guard let decodedThemeNames = try? JSONDecoder().decode([String].self, from: dataThemeNames) else { return }
|
||||
|
||||
for index in 0..<decodedThemes.count {
|
||||
guard let encoded = try? JSONEncoder().encode(decodedThemes) else { return }
|
||||
guard let encoded = try? JSONEncoder().encode(decodedThemes[index]) else { return }
|
||||
guard let synthedTheme = Theme.decodeTheme(name: decodedThemeNames[index], data: encoded) else { return }
|
||||
self.themes.append(synthedTheme)
|
||||
}
|
||||
|
||||
@@ -51,15 +51,11 @@ struct Theme: Hashable, Equatable, Identifiable {
|
||||
|
||||
static func decodeTheme(name: String, data: Data?) -> Theme? {
|
||||
guard let data else { return nil }
|
||||
guard let string = String(data: data, encoding: .utf8) else { return nil }
|
||||
|
||||
let plistDecoder = PropertyListDecoder()
|
||||
let jsonDecoder = JSONDecoder()
|
||||
|
||||
guard let decoded =
|
||||
(try? plistDecoder.decode(ThemeCodable.self, from: data)) ??
|
||||
(try? jsonDecoder.decode(ThemeCodable.self, from: data))
|
||||
else { return nil }
|
||||
let theme = Theme(
|
||||
if string.contains("plist") {
|
||||
guard let decoded = try? PropertyListDecoder().decode(ThemeCodable.self, from: data) else { return nil }
|
||||
return Theme(
|
||||
name: name,
|
||||
ansi: decoded.ansi,
|
||||
foreground: Color(decoded.foreground),
|
||||
@@ -70,7 +66,20 @@ struct Theme: Hashable, Equatable, Identifiable {
|
||||
selectedText: Color(decoded.selectedText),
|
||||
selection: Color(decoded.selection)
|
||||
)
|
||||
return theme
|
||||
} else {
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,21 +29,15 @@ struct ThemesView: View {
|
||||
HStack {
|
||||
ForEach(0..<8, id: \.self) { index in
|
||||
Rectangle()
|
||||
.frame(width: 12)
|
||||
.frame(width: 12, height: 12)
|
||||
.foregroundStyle(theme.ansi[index].suiColor)
|
||||
.onAppear {
|
||||
print(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
ForEach(8..<16, id: \.self) { index in
|
||||
Rectangle()
|
||||
.frame(width: 12)
|
||||
.frame(width: 12, height: 12)
|
||||
.foregroundStyle(theme.ansi[index].suiColor)
|
||||
.onAppear {
|
||||
print(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user