updated updatetheme to add the theme if not present

added a new theme button with a avigation destination
This commit is contained in:
neon443
2025-07-09 13:54:34 +01:00
parent 53888bc600
commit e3e4108723
2 changed files with 19 additions and 1 deletions

View File

@@ -129,7 +129,11 @@ class HostsManager: ObservableObject, @unchecked Sendable {
} }
func updateTheme(_ theme: Theme) { func updateTheme(_ theme: Theme) {
guard let index = themes.firstIndex(where: { $0.id == theme.id }) else { return } guard let index = themes.firstIndex(where: { $0.id == theme.id }) else {
themes.append(theme)
saveThemes()
return
}
themes[index] = theme themes[index] = theme
if selectedTheme.id == theme.id { if selectedTheme.id == theme.id {
selectedTheme = theme selectedTheme = theme

View File

@@ -14,6 +14,9 @@ struct ThemeManagerView: View {
@State var importURL: String = "" @State var importURL: String = ""
@State var toImportName: String = "" @State var toImportName: String = ""
@State private var newTheme: Theme = Theme.defaultTheme
@State private var showNewThemeEditor: Bool = false
var minColWidth: CGFloat {150} var minColWidth: CGFloat {150}
var spacing: CGFloat {8} var spacing: CGFloat {8}
var grid: GridItem { var grid: GridItem {
@@ -121,6 +124,17 @@ struct ThemeManagerView: View {
} }
} }
ToolbarItem() {
Button() {
newTheme = Theme.defaultTheme
showNewThemeEditor = true
} label: {
Label("New", systemImage: "plus")
}
}
}
.navigationDestination(isPresented: $showNewThemeEditor) {
ThemeEditorView(hostsManager: hostsManager, theme: $newTheme)
} }
} }
} }