From 338957e986c671ce6bf0e45b87b4527af0575852 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Fri, 27 Jun 2025 18:25:16 +0100 Subject: [PATCH] theme loading works!! before i tried decoding the entire array when it expected one theme lol --- ShhShell/Host/HostsManager.swift | 2 +- ShhShell/Themes/Theme.swift | 47 +++++++++++++++----------- ShhShell/Views/Themes/ThemesView.swift | 10 ++---- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 8b59c73..55387db 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -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.. 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( - 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) - ) - return 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), + background: Color(decoded.background), + cursor: Color(decoded.cursor), + cursorText: Color(decoded.cursorText), + bold: Color(decoded.bold), + selectedText: Color(decoded.selectedText), + selection: Color(decoded.selection) + ) + } 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) + ) + } } } diff --git a/ShhShell/Views/Themes/ThemesView.swift b/ShhShell/Views/Themes/ThemesView.swift index e87fe72..fc0a591 100644 --- a/ShhShell/Views/Themes/ThemesView.swift +++ b/ShhShell/Views/Themes/ThemesView.swift @@ -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) - } } } }