mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Add SwiftUI previews for simple helper views Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for action buttons, ChannelForm, MetricsColumnDetail, and DeviceOnboarding Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for config views, log views, AppLog, Firmware, AppData, and UserConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add preview for PositionConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Fix formatting bugs in #Preview blocks: restore missing .environmentObject/.environment modifiers and add proper tab indentation Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/7eeb7a54-7928-466f-8e39-b00d0012a09d Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Linting fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
import SwiftUI
|
|
import OSLog
|
|
struct TraceRouteButton: View {
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
|
|
var node: NodeInfoEntity
|
|
|
|
@State
|
|
private var isPresentingTraceRouteSentAlert: Bool = false
|
|
|
|
var body: some View {
|
|
RateLimitedButton(key: "traceroute", rateLimit: 30.0) {
|
|
Task {
|
|
do {
|
|
try await accessoryManager.sendTraceRouteRequest(
|
|
destNum: node.user?.num ?? 0,
|
|
wantResponse: true
|
|
)
|
|
Task {
|
|
isPresentingTraceRouteSentAlert = true
|
|
}
|
|
} catch {
|
|
Logger.mesh.warning("Failed to send traceroute request: \(error)")
|
|
}
|
|
}
|
|
} label: { completion in
|
|
if let completion, completion.percentComplete > 0.0 {
|
|
Label {
|
|
Text("Trace Route (in \(completion.secondsRemaining.formatted(.number.precision(.fractionLength(0))))s)")
|
|
.foregroundStyle(.secondary)
|
|
} icon: {
|
|
Image("progress.ring.dashed", variableValue: completion.percentComplete)
|
|
.foregroundStyle(.secondary)
|
|
}.disabled(true)
|
|
} else {
|
|
Label {
|
|
Text("Trace Route")
|
|
} icon: {
|
|
Image(systemName: "signpost.right.and.left")
|
|
.symbolRenderingMode(.hierarchical)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let context = PersistenceController.preview.container.viewContext
|
|
let node = NodeInfoEntity(context: context)
|
|
node.num = 123456789
|
|
let user = UserEntity(context: context)
|
|
user.longName = "Test Node"
|
|
user.shortName = "TN"
|
|
node.user = user
|
|
return TraceRouteButton(node: node)
|
|
.environmentObject(AccessoryManager.shared)
|
|
}
|