damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

DeveloperSettingsView.swift (4329B)


      1 //
      2 //  DeveloperSettingsView.swift
      3 //  damus
      4 //
      5 //  Created by Bryan Montz on 7/6/23.
      6 //
      7 
      8 import Foundation
      9 import SwiftUI
     10 
     11 struct DeveloperSettingsView: View {
     12     @ObservedObject var settings: UserSettingsStore
     13     
     14     var body: some View {
     15         Form {
     16             Section(footer: Text("Developer Mode enables features and options that may help developers diagnose issues and improve this app. Most users will not need Developer Mode.", comment: "Section header for Developer Settings view")) {
     17                 Toggle(NSLocalizedString("Developer Mode", comment: "Setting to enable developer mode"), isOn: $settings.developer_mode)
     18                     .toggleStyle(.switch)
     19                 if settings.developer_mode {
     20                     Toggle(NSLocalizedString("Always show onboarding", comment: "Developer mode setting to always show onboarding suggestions."), isOn: $settings.always_show_onboarding_suggestions)
     21 
     22                     Toggle(NSLocalizedString("Enable experimental push notifications", comment: "Developer mode setting to enable experimental push notifications."), isOn: $settings.enable_experimental_push_notifications)
     23                         .toggleStyle(.switch)
     24 
     25                     Toggle(NSLocalizedString("Send device token to localhost", comment: "Developer mode setting to send device token metadata to a local server instead of the damus.io server."), isOn: $settings.send_device_token_to_localhost)
     26                         .toggleStyle(.switch)
     27                     
     28                     Toggle(NSLocalizedString("Enable experimental Purple API support", comment: "Developer mode setting to enable experimental Purple API support."), isOn: $settings.enable_experimental_purple_api)
     29                         .toggleStyle(.switch)
     30                     
     31                     Picker(NSLocalizedString("Damus Purple environment", comment: "Prompt selection of the Damus purple environment (Developer feature to switch between real/production mode to test modes)."), 
     32                            selection: Binding(
     33                             get: { () -> DamusPurpleEnvironment in
     34                                 switch settings.purple_enviroment {
     35                                     case .local_test(_):
     36                                         return .local_test(host: nil)    // Avoid errors related to a value which is not a valid picker option
     37                                     default:
     38                                         return settings.purple_enviroment
     39                                 }
     40                             },
     41                             set: { new_value in
     42                                 settings.purple_enviroment = new_value
     43                             }
     44                            )
     45                     ) {
     46                         ForEach(DamusPurpleEnvironment.allCases, id: \.self) { purple_environment in
     47                             Text(purple_environment.text_description())
     48                                 .tag(purple_environment.to_string())
     49                         }
     50                     }
     51                     
     52                     if case .local_test(_) = settings.purple_enviroment {
     53                         TextField(
     54                             NSLocalizedString("URL", comment: "Custom URL host for Damus Purple testing"),
     55                             text: Binding.init(
     56                                 get: {
     57                                     return settings.purple_enviroment.custom_host() ?? ""
     58                                 }, set: { new_host_value in
     59                                     settings.purple_enviroment = .local_test(host: new_host_value)
     60                                 }
     61                             )
     62                         )
     63                             .disableAutocorrection(true)
     64                             .autocapitalization(UITextAutocapitalizationType.none)
     65                     }
     66 
     67                     Toggle(NSLocalizedString("Enable experimental Purple In-app purchase support", comment: "Developer mode setting to enable experimental Purple In-app purchase support."), isOn: $settings.enable_experimental_purple_iap_support)
     68                         .toggleStyle(.switch)
     69                 }
     70             }
     71         }
     72         .navigationTitle(NSLocalizedString("Developer", comment: "Navigation title for developer settings"))
     73     }
     74 }