mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
After this change, a developer can now clone the project and run without the build failing due to lint errors! 😃
* I ran `swiftlint --fix` to resolve many auto-correctable issues (mostly whitespace)
* Excluded the `Meshtastic/Protobufs` directory from lint, since that code is automatically generated.
* Converted some single letter method parameters to lowercase.
* Converted several instances `force_cast` to instead use `guard` or `if let` to unwrap optional values. During this change, some of the SwiftUI views became "too complex to be solved in a reasonable time", so I broke up the views into distinct sub-expressions.
I was able to build and run the app on an iOS simulator.
55 lines
1.6 KiB
Swift
55 lines
1.6 KiB
Swift
//
|
|
// MQTTIcon.swift
|
|
// Meshtastic
|
|
//
|
|
// Created by Matthew Davies on 4/1/24.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct MQTTIcon: View {
|
|
var connected: Bool = false
|
|
var uplink: Bool = false
|
|
var downlink: Bool = false
|
|
var topic: String = ""
|
|
|
|
@State var isPopoverOpen = false
|
|
|
|
var body: some View {
|
|
Button( action: {
|
|
if topic.length > 0 {self.isPopoverOpen.toggle()}
|
|
}) {
|
|
// the last one defaults to just showing up/down if it isn't specified b/c on the mqtt config screen, there's no information about uplink/downlink and no good alternative icon
|
|
Image(systemName: uplink && downlink ? "arrow.up.arrow.down.circle.fill" : uplink ? "arrow.up.circle.fill" : downlink ? "arrow.down.circle.fill" : "arrow.up.arrow.down.circle.fill")
|
|
.imageScale(.large)
|
|
.foregroundColor(connected ? .green : .gray)
|
|
.symbolRenderingMode(.hierarchical)
|
|
}.popover(isPresented: self.$isPopoverOpen, arrowEdge: .bottom, content: {
|
|
VStack(spacing: 0.5) {
|
|
Text("Topic: " + topic)
|
|
.padding(20)
|
|
Button("close", action: { self.isPopoverOpen = false }).padding([.bottom], 20)
|
|
}
|
|
.presentationCompactAdaptation(.popover)
|
|
})
|
|
}
|
|
}
|
|
|
|
struct MQTTIcon_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
VStack {
|
|
MQTTIcon(connected: true)
|
|
MQTTIcon(connected: false)
|
|
|
|
MQTTIcon(connected: true, uplink: true, downlink: true)
|
|
MQTTIcon(connected: false, uplink: true, downlink: true)
|
|
|
|
MQTTIcon(connected: true, uplink: true)
|
|
MQTTIcon(connected: false, uplink: true)
|
|
|
|
MQTTIcon(connected: true, downlink: true)
|
|
MQTTIcon(connected: false, downlink: true)
|
|
}.previewLayout(.fixed(width: 25, height: 220))
|
|
}
|
|
}
|