mirror of
				https://github.com/yggdrasil-network/yggdrasil-ios.git
				synced 2025-11-04 03:05:09 +03:00 
			
		
		
		
	Add ability to reset config
This commit is contained in:
		
							parent
							
								
									00419e6269
								
							
						
					
					
						commit
						b0c3d045a3
					
				
					 2 changed files with 37 additions and 43 deletions
				
			
		| 
						 | 
					@ -90,6 +90,15 @@ class ConfigurationProxy: PlatformItemSource {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    public func reset() {
 | 
				
			||||||
 | 
					        self.json = MobileGenerateConfigJSON()
 | 
				
			||||||
 | 
					        try? self.convertToDict()
 | 
				
			||||||
 | 
					        self.fix()
 | 
				
			||||||
 | 
					        if var manager = self.manager {
 | 
				
			||||||
 | 
					            try? self.save(to: &manager)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public var multicastBeacons: Bool {
 | 
					    public var multicastBeacons: Bool {
 | 
				
			||||||
        get {
 | 
					        get {
 | 
				
			||||||
            let multicastInterfaces = self.get("MulticastInterfaces") as? [[String: Any]] ?? []
 | 
					            let multicastInterfaces = self.get("MulticastInterfaces") as? [[String: Any]] ?? []
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@ struct SettingsView: View {
 | 
				
			||||||
    @ObservedObject private var appDelegate = Application.appDelegate
 | 
					    @ObservedObject private var appDelegate = Application.appDelegate
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    @State private var deviceName = ""
 | 
					    @State private var deviceName = ""
 | 
				
			||||||
 | 
					    @State private var isResetting = false
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    var body: some View {
 | 
					    var body: some View {
 | 
				
			||||||
        Form {
 | 
					        Form {
 | 
				
			||||||
| 
						 | 
					@ -33,37 +34,17 @@ struct SettingsView: View {
 | 
				
			||||||
                Text("Automatically start when connected to")
 | 
					                Text("Automatically start when connected to")
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            /*
 | 
					            
 | 
				
			||||||
             Section(content: {
 | 
					             Section(content: {
 | 
				
			||||||
             VStack(alignment: .leading) {
 | 
					 | 
				
			||||||
             Button("Import configuration") {
 | 
					 | 
				
			||||||
             
 | 
					 | 
				
			||||||
             }
 | 
					 | 
				
			||||||
             #if os(macOS)
 | 
					 | 
				
			||||||
             .buttonStyle(.link)
 | 
					 | 
				
			||||||
             #endif
 | 
					 | 
				
			||||||
             .foregroundColor(.accentColor)
 | 
					 | 
				
			||||||
             Text("Import configuration from another device, including the public key and Yggdrasil IP address.")
 | 
					 | 
				
			||||||
             .font(.system(size: 11))
 | 
					 | 
				
			||||||
             .foregroundColor(.gray)
 | 
					 | 
				
			||||||
             }
 | 
					 | 
				
			||||||
             
 | 
					 | 
				
			||||||
             VStack(alignment: .leading) {
 | 
					 | 
				
			||||||
             Button("Export configuration") {
 | 
					 | 
				
			||||||
             
 | 
					 | 
				
			||||||
             }
 | 
					 | 
				
			||||||
             #if os(macOS)
 | 
					 | 
				
			||||||
             .buttonStyle(.link)
 | 
					 | 
				
			||||||
             #endif
 | 
					 | 
				
			||||||
             .foregroundColor(.accentColor)
 | 
					 | 
				
			||||||
             Text("Configuration will be exported as a file. Your configuration contains your private key which is extremely sensitive. Do not share it with anyone.")
 | 
					 | 
				
			||||||
             .font(.system(size: 11))
 | 
					 | 
				
			||||||
             .foregroundColor(.gray)
 | 
					 | 
				
			||||||
             }
 | 
					 | 
				
			||||||
             
 | 
					 | 
				
			||||||
                 VStack(alignment: .leading) {
 | 
					                 VStack(alignment: .leading) {
 | 
				
			||||||
                     Button("Reset configuration") {
 | 
					                     Button("Reset configuration") {
 | 
				
			||||||
             
 | 
					                         self.isResetting.toggle()
 | 
				
			||||||
 | 
					                     }
 | 
				
			||||||
 | 
					                     .alert("Reset configuration", isPresented: $isResetting) {
 | 
				
			||||||
 | 
					                         Button("Confirm", action: resetConfig)
 | 
				
			||||||
 | 
					                         Button("Cancel", role: .cancel) { }
 | 
				
			||||||
 | 
					                     } message: {
 | 
				
			||||||
 | 
					                         Text("Are you sure you want to reset your configuration? This operation cannot be undone.")
 | 
				
			||||||
                     }
 | 
					                     }
 | 
				
			||||||
                     #if os(macOS)
 | 
					                     #if os(macOS)
 | 
				
			||||||
                     .buttonStyle(.link)
 | 
					                     .buttonStyle(.link)
 | 
				
			||||||
| 
						 | 
					@ -75,8 +56,8 @@ struct SettingsView: View {
 | 
				
			||||||
                     }
 | 
					                     }
 | 
				
			||||||
                 }, header: {
 | 
					                 }, header: {
 | 
				
			||||||
                     Text("Configuration")
 | 
					                     Text("Configuration")
 | 
				
			||||||
             })
 | 
					                 }
 | 
				
			||||||
             */
 | 
					             )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        .formStyle(.grouped)
 | 
					        .formStyle(.grouped)
 | 
				
			||||||
        .navigationTitle("Settings")
 | 
					        .navigationTitle("Settings")
 | 
				
			||||||
| 
						 | 
					@ -84,6 +65,10 @@ struct SettingsView: View {
 | 
				
			||||||
        .navigationBarTitleDisplayMode(.large)
 | 
					        .navigationBarTitleDisplayMode(.large)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    func resetConfig() {
 | 
				
			||||||
 | 
					        self.appDelegate.yggdrasilConfig.reset()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct SettingsView_Previews: PreviewProvider {
 | 
					struct SettingsView_Previews: PreviewProvider {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue