Issue #6: Always reflect current state of NEDNSSettingsManager.
This commit is contained in:
parent
178a625050
commit
3aee0db9e9
2 changed files with 38 additions and 24 deletions
|
|
@ -3,6 +3,9 @@ import SwiftUI
|
||||||
|
|
||||||
struct HomeView: View {
|
struct HomeView: View {
|
||||||
|
|
||||||
|
@Environment(\.scenePhase)
|
||||||
|
private var scenePhase
|
||||||
|
|
||||||
@EnvironmentObject
|
@EnvironmentObject
|
||||||
private var viewModel: ViewModel
|
private var viewModel: ViewModel
|
||||||
|
|
||||||
|
|
@ -204,6 +207,13 @@ struct HomeView: View {
|
||||||
}
|
}
|
||||||
.navigationTitle(ViewModel.title)
|
.navigationTitle(ViewModel.title)
|
||||||
.animation(.default, value: viewModel.isDnsEnabled)
|
.animation(.default, value: viewModel.isDnsEnabled)
|
||||||
|
.onChange(of: scenePhase) { _, newPhase in
|
||||||
|
if newPhase == .active {
|
||||||
|
Task {
|
||||||
|
await viewModel.refreshConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,18 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
|
await refreshConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
Task {
|
||||||
|
await fetchServerStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Public Methods
|
||||||
|
|
||||||
|
func refreshConfig() async {
|
||||||
do {
|
do {
|
||||||
try await manager.loadFromPreferences()
|
try await manager.loadFromPreferences()
|
||||||
}
|
}
|
||||||
|
|
@ -79,14 +91,6 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task {
|
|
||||||
await fetchServerStatus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: Public Methods
|
|
||||||
|
|
||||||
func fetchServerStatus() async {
|
func fetchServerStatus() async {
|
||||||
do {
|
do {
|
||||||
let (data, _) = try await URLSession.shared.data(for: .init(url: .init(string: "https://status.sr2.uk/index.json")!))
|
let (data, _) = try await URLSession.shared.data(for: .init(url: .init(string: "https://status.sr2.uk/index.json")!))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue