Skip to content

Commit

Permalink
[CGM Config View] - Nightscout button
Browse files Browse the repository at this point in the history
Add a link to configure Nightscout if not defined.
Improve minor code
  • Loading branch information
avouspierre authored and mountrcg committed May 19, 2024
1 parent 5011290 commit d7c7b6d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
6 changes: 4 additions & 2 deletions FreeAPS/Sources/Modules/CGM/CGMStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,20 @@ extension CGM {
.store(in: &lifetime)
}

func displayNameOfApp() -> String {
func displayNameOfApp() -> String? {
guard cgmManager != nil else { return nil }
var nameOfApp = "Open Application"
switch cgmManager.cgmGlucoseSourceType {
case .plugin:
nameOfApp = "Open " + (cgmManager.cgmManager?.localizedTitle ?? "Application")
default:
nameOfApp = "Open " + (cgmManager.cgmGlucoseSourceType.displayName ?? "Application")
nameOfApp = "Open " + cgmManager.cgmGlucoseSourceType.displayName
}
return nameOfApp
}

func urlOfApp() -> URL? {
guard cgmManager != nil else { return nil }
switch cgmManager.cgmGlucoseSourceType {
case .plugin:
return cgmManager.cgmManager?.appURL
Expand Down
48 changes: 30 additions & 18 deletions FreeAPS/Sources/Modules/CGM/View/CGMRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ extension CGM {
}
}

if let cgmFetchManager = state.cgmManager {
if let appURL = state.urlOfApp()
{
Section {
Button {
UIApplication.shared.open(appURL, options: [:]) { success in
if !success {
self.router.alertMessage
.send(MessageContent(content: "Unable to open the app", type: .warning))
}
if let appURL = state.urlOfApp()
{
Section {
Button {
UIApplication.shared.open(appURL, options: [:]) { success in
if !success {
self.router.alertMessage
.send(MessageContent(content: "Unable to open the app", type: .warning))
}
}

label: {
Label(state.displayNameOfApp(), systemImage: "waveform.path.ecg.rectangle").font(.title3) }
.frame(maxWidth: .infinity, alignment: .center)
.buttonStyle(.bordered)
}
.listRowBackground(Color.clear)
} else if state.cgmCurrent.type == .nightscout && state.url != nil {

label: {
Label(state.displayNameOfApp() ?? "-", systemImage: "waveform.path.ecg.rectangle").font(.title3) }
.frame(maxWidth: .infinity, alignment: .center)
.buttonStyle(.bordered)
}
.listRowBackground(Color.clear)
} else if state.cgmCurrent.type == .nightscout {
if let url = state.url {
Section {
Button {
UIApplication.shared.open(state.url!, options: [:]) { success in
UIApplication.shared.open(url, options: [:]) { success in
if !success {
self.router.alertMessage
.send(MessageContent(content: "No URL available", type: .warning))
Expand All @@ -80,6 +80,18 @@ extension CGM {
.buttonStyle(.bordered)
}
.listRowBackground(Color.clear)
} else {
Section {
Button {
state.showModal(for: .nighscoutConfigDirect)
// router.mainSecondaryModalView.send(router.view(for: .nighscoutConfigDirect))
}
label: { Label("Config Nightscout", systemImage: "waveform.path.ecg.rectangle").font(.title3)
}
.frame(maxWidth: .infinity, alignment: .center)
.buttonStyle(.bordered)
}
.listRowBackground(Color.clear)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Swinject
extension NightscoutConfig {
struct RootView: BaseView {
let resolver: Resolver
let displayClose: Bool
@StateObject var state = StateModel()
@State var importAlert: Alert?
@State var isImportAlertPresented = false
Expand Down Expand Up @@ -153,6 +154,7 @@ extension NightscoutConfig {
.onAppear(perform: configureView)
.navigationBarTitle("Nightscout Config")
.navigationBarTitleDisplayMode(.automatic)
.navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
.alert(isPresented: $isImportAlertPresented) {
importAlert!
}
Expand Down
5 changes: 4 additions & 1 deletion FreeAPS/Sources/Router/Screen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Screen: Identifiable, Hashable {
case settings
case configEditor(file: String)
case nighscoutConfig
case nighscoutConfigDirect
case pumpConfig
case pumpSettingsEditor
case basalProfileEditor
Expand Down Expand Up @@ -55,7 +56,9 @@ extension Screen {
case let .configEditor(file):
ConfigEditor.RootView(resolver: resolver, file: file)
case .nighscoutConfig:
NightscoutConfig.RootView(resolver: resolver)
NightscoutConfig.RootView(resolver: resolver, displayClose: false)
case .nighscoutConfigDirect:
NightscoutConfig.RootView(resolver: resolver, displayClose: true)
case .pumpConfig:
PumpConfig.RootView(resolver: resolver)
case .pumpSettingsEditor:
Expand Down

0 comments on commit d7c7b6d

Please sign in to comment.