Skip to content

Commit 6f217a8

Browse files
authored
Merge pull request #426 from loopandlearn/initial-setup-improvements
Improve initial setup and UI reactivity
2 parents 10f2310 + 03effc2 commit 6f217a8

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

LoopFollow/Settings/SettingsMenuView.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import SwiftUI
66
import UIKit
77

88
struct SettingsMenuView: View {
9-
// MARK: – Call-backs
9+
// MARK: - Observed Objects
1010

11-
let onNightscoutVisibilityChange: (_ enabled: Bool) -> Void
11+
@ObservedObject private var nightscoutURL = Storage.shared.url
1212

1313
// MARK: – Local state
1414

@@ -45,7 +45,7 @@ struct SettingsMenuView: View {
4545
path.append(Sheet.graph)
4646
}
4747

48-
if IsNightscoutEnabled() {
48+
if !nightscoutURL.value.isEmpty {
4949
NavigationRow(title: "Information Display Settings",
5050
icon: "info.circle")
5151
{
@@ -154,9 +154,6 @@ struct SettingsMenuView: View {
154154
path.append(Sheet.dexcom)
155155
}
156156
}
157-
.onAppear {
158-
onNightscoutVisibilityChange(IsNightscoutEnabled())
159-
}
160157
}
161158

162159
@ViewBuilder

LoopFollow/Storage/Storage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
*/
1212

1313
class Storage {
14-
var remoteType = StorageValue<RemoteType>(key: "remoteType", defaultValue: .nightscout)
14+
var remoteType = StorageValue<RemoteType>(key: "remoteType", defaultValue: .none)
1515
var deviceToken = StorageValue<String>(key: "deviceToken", defaultValue: "")
1616
var expirationDate = StorageValue<Date?>(key: "expirationDate", defaultValue: nil)
1717
var sharedSecret = StorageValue<String>(key: "sharedSecret", defaultValue: "")

LoopFollow/ViewControllers/MainViewController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
291291
}
292292
.store(in: &cancellables)
293293

294+
Storage.shared.url.$value
295+
.receive(on: DispatchQueue.main)
296+
.sink { [weak self] value in
297+
self?.tabBarController?.tabBar.items?[3].isEnabled = !value.isEmpty
298+
}
299+
.store(in: &cancellables)
300+
294301
updateQuickActions()
295302

296303
speechSynthesizer.delegate = self

LoopFollow/ViewControllers/SettingsViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ final class SettingsViewController: UIViewController {
1616
super.viewDidLoad()
1717

1818
// Build SwiftUI menu
19-
host = UIHostingController(
20-
rootView: SettingsMenuView { [weak self] nightscoutEnabled in
21-
self?.tabBarController?.tabBar.items?[3].isEnabled = nightscoutEnabled
22-
})
19+
host = UIHostingController(rootView: SettingsMenuView())
2320

2421
// Dark-mode override
2522
if Storage.shared.forceDarkMode.value {

0 commit comments

Comments
 (0)