Skip to content

Commit 5d26088

Browse files
committed
- more bugfixes
- last commit before overhauling HRM/Battery page
1 parent 6b2829d commit 5d26088

6 files changed

Lines changed: 48 additions & 35 deletions

File tree

Infini-iOS/BLE/BLEManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
8686
if infiniTime != nil {
8787
myCentral.cancelPeripheralConnection(infiniTime)
8888
firstConnect = true
89+
isConnectedToPinetime = false
8990
}
9091
}
9192

Infini-iOS/ContentView.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ struct ContentView: View {
2525
}
2626

2727

28-
2928
var body: some View {
3029
let drag = DragGesture()
3130
.onEnded {
@@ -41,6 +40,7 @@ struct ContentView: View {
4140
// pageSwitcher.connectViewLoad = true
4241
}
4342
}
43+
4444
return NavigationView {
4545
GeometryReader { geometry in
4646
ZStack(alignment: .leading) {
@@ -52,9 +52,12 @@ struct ContentView: View {
5252
.offset(x: self.pageSwitcher.showMenu ? geometry.size.width/2 : 0)
5353
.disabled(self.pageSwitcher.showMenu ? true : false)
5454
.onAppear(){
55-
if autoconnect && bleManager.isSwitchedOn {
56-
self.bleManager.startScanning()
57-
}
55+
// if autoconnect is set, start scan ASAP, but give bleManager half a second to start up
56+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
57+
if autoconnect && bleManager.isSwitchedOn {
58+
self.bleManager.startScanning()
59+
}
60+
})
5861
if (autoconnect && autoconnectUUID == "") || (!autoconnect && !bleManager.isConnectedToPinetime) {
5962
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
6063
withAnimation {

Infini-iOS/Settings/SettingsView.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@ struct Settings_Page: View {
2727
.padding()
2828
Form {
2929
Section(header: Text("Connection")) {
30-
Toggle("Autoconnect to Nearest PineTime", isOn: $autoconnect)
30+
Toggle("Autoconnect to PineTime", isOn: $autoconnect)
3131
if autoconnect {
32-
Text("Autoconnect is currently experimental! Connection is made based on device UUID, which I am only sort of sure is static.").foregroundColor(Color.red)
33-
}
34-
Button {
35-
autoconnectUUID = bleManager.setAutoconnectUUID
36-
print(autoconnectUUID)
37-
} label: {
38-
Text("Select Current Device for Autoconnect")
32+
Text("Autoconnect is currently experimental! Connection is made based on device UUID, which I am only sort of sure is static.").foregroundColor(Color.red)
33+
Button {
34+
autoconnectUUID = bleManager.setAutoconnectUUID
35+
print(autoconnectUUID)
36+
} label: {
37+
Text("Use Current Device for Autoconnect")
38+
.foregroundColor(Color.white)
39+
}
40+
Button {
41+
autoconnectUUID = ""
42+
print(autoconnectUUID)
43+
} label: {
44+
Text("Clear Autoconnect Device")
45+
.foregroundColor(Color.white)
46+
}
3947
}
4048

49+
4150
}
4251
Section(header: Text("Notifications")) {
4352
Toggle("Enable Watch Notifications", isOn: $watchNotifications)

Infini-iOS/View Components/BLEConnectView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct Connect: View {
3535
HStack {
3636
Button(action: {
3737
self.bleManager.deviceToConnect = peripheral.peripheralHash
38-
self.bleManager.connect(peripheral: self.bleManager.peripheralDictionary[peripheral.peripheralHash]!)
38+
if !self.bleManager.isConnectedToPinetime {
39+
self.bleManager.connect(peripheral: self.bleManager.peripheralDictionary[peripheral.peripheralHash]!)
40+
}
3941
presentation.wrappedValue.dismiss()
4042
}) {
4143
Text(peripheral.name)

Infini-iOS/View Components/BLEStatusView.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,14 @@ struct DeviceView: View {
5050
.padding(.horizontal, 20)
5151
}
5252
} else {
53-
Button(action: {
54-
self.bleManager.disconnect()
55-
}) {
56-
Text("Disconnect from PineTime")
57-
.padding()
58-
.padding(.vertical, 7)
59-
.frame(maxWidth: .infinity, alignment: .center)
60-
.background(Color.darkGray)
61-
.foregroundColor(Color.gray)
62-
.cornerRadius(10)
63-
.padding(.horizontal, 20)
64-
}.disabled(true)
53+
Text("Disconnected")
54+
.padding()
55+
.padding(.vertical, 7)
56+
.frame(maxWidth: .infinity, alignment: .center)
57+
.background(Color.darkGray)
58+
.foregroundColor(Color.gray)
59+
.cornerRadius(10)
60+
.padding(.horizontal, 20)
6561
}
6662
}//.padding()
6763
}

Infini-iOS/View Components/SideMenu.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ struct SideMenu: View {
5959

6060
Spacer()
6161
HStack {
62-
Button(action: {
63-
pageSwitcher.connectViewLoad = true
64-
pageSwitcher.showMenu = false
65-
}) {
66-
Image(systemName: "radiowaves.right")
67-
.foregroundColor(.gray)
68-
.imageScale(.large)
69-
Text("Connect to PineTime")
70-
.foregroundColor(.gray)
71-
.padding(5)
62+
if !self.bleManager.isConnectedToPinetime {
63+
Button(action: {
64+
pageSwitcher.connectViewLoad = true
65+
pageSwitcher.showMenu = false
66+
}) {
67+
Image(systemName: "radiowaves.right")
68+
.foregroundColor(.gray)
69+
.imageScale(.large)
70+
Text("Connect to PineTime")
71+
.foregroundColor(.gray)
72+
.padding(5)
73+
}
7274
}
7375
}
7476
.padding(.top, 100)

0 commit comments

Comments
 (0)