mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/5b7576a8-e0c0-4036-8b7e-8f2e6fbfa4d7 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
46 lines
1.3 KiB
Swift
46 lines
1.3 KiB
Swift
//
|
|
// ChannelLock.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) Garth Vander Houwen 6/22/25.
|
|
//
|
|
import SwiftUI
|
|
|
|
struct ChannelLock: View {
|
|
|
|
@ObservedObject var channel: ChannelEntity
|
|
var body: some View {
|
|
/// Unencrypted - using no key at all or a known 1 byte key
|
|
if channel.psk?.hexDescription.count ?? 0 < 3 {
|
|
let preciseLoction = 17...32
|
|
// Using precise location and have MQTT uplink enabled
|
|
if channel.uplinkEnabled && preciseLoction ~= (Int(channel.positionPrecision)) {
|
|
Image(systemName: "lock.open.trianglebadge.exclamationmark.fill")
|
|
.foregroundColor(.red)
|
|
// Using precise location
|
|
} else if preciseLoction ~= (Int(channel.positionPrecision)) {
|
|
Image(systemName: "lock.open.fill")
|
|
.foregroundColor(.red)
|
|
// Just unencrypted without any location or MQTT
|
|
} else {
|
|
Image(systemName: "lock.open.fill")
|
|
.foregroundColor(.yellow)
|
|
}
|
|
} else {
|
|
Image(systemName: "lock.fill")
|
|
.foregroundColor(.green)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let context = PersistenceController.preview.container.viewContext
|
|
let encryptedChannel = ChannelEntity(context: context)
|
|
encryptedChannel.psk = Data([0x01, 0x02, 0x03, 0x04])
|
|
let unencryptedChannel = ChannelEntity(context: context)
|
|
unencryptedChannel.psk = Data()
|
|
return HStack(spacing: 16) {
|
|
ChannelLock(channel: encryptedChannel)
|
|
ChannelLock(channel: unencryptedChannel)
|
|
}
|
|
}
|