Skip to content

Commit

Permalink
Merge pull request #92 from UbiqueInnovation/feature/app-specific-deb…
Browse files Browse the repository at this point in the history
…ug-settings

adds support for custom form entry for debug settings
  • Loading branch information
stmitt authored Jul 12, 2024
2 parents 6987310 + 89f498e commit 8b649ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Sources/UBDevTools/BackendDevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BackendDevTools: DevTool {

class ViewModel: ObservableObject {
@Published var urls: [BaseUrl] = []
var appSpecificView: AnyView = AnyView(EmptyView())
}

public static var viewModel = ViewModel()
Expand All @@ -47,6 +48,10 @@ class BackendDevTools: DevTool {
viewModel.urls = baseUrls
}

public static func setAppSettingsView(view: some View) {
viewModel.appSpecificView = AnyView(view)
}

public static func saveNewUrl(baseUrl: BaseUrl, newUrl: String) {
let key = Self.key(url: baseUrl.url)
UserDefaults.standard.set(newUrl, forKey: key)
Expand Down
5 changes: 5 additions & 0 deletions Sources/UBDevTools/DevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import UBFoundation
import SwiftUI

protocol DevTool {
static func setup()
Expand All @@ -31,6 +32,10 @@ public enum UBDevTools {
}
}

public static func setAppSettingsView(view: some View) {
BackendDevTools.setAppSettingsView(view: view)
}

public static func setupBaseUrls(baseUrls: [BaseUrl]) {
BackendDevTools.setup(baseUrls: baseUrls)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/UBDevTools/DevToolsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct DevToolsView: View {
@State private var showingKeychainDeleteAlert = false
@State private var showingUserDefaultsDeleteAlert = false

@StateObject private var backendUrls = BackendDevTools.viewModel
@StateObject private var viewModel = BackendDevTools.viewModel

@State private var cacheUpdateValue = UUID()

Expand All @@ -42,6 +42,7 @@ public struct DevToolsView: View {

private var contentView: some View {
Form {
viewModel.appSpecificView
Group {
Section(header: Text("UserDefaults.standard")) {
Button("Clear UserDefaults.standard") {
Expand Down Expand Up @@ -129,8 +130,8 @@ public struct DevToolsView: View {
Toggle("Show localization keys", isOn: Binding(get: { Self.showLocalizationKeys }, set: { Self.showLocalizationKeys = $0 }))
}
Section(header: Text("Backend URL Config")) {
if backendUrls.urls.count > 0 {
List(backendUrls.urls, id: \.title) { bu in
if viewModel.urls.count > 0 {
List(viewModel.urls, id: \.title) { bu in
BackendUrlEditor(url: bu)
}
Button {
Expand Down

0 comments on commit 8b649ad

Please sign in to comment.