mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Bump version * Message list performance fixes into 2.7.6 (#1475) * Remove extra want config call when adding a contact * App badge and unnecessary notification fixes (#1455) * - Fix for app badge not going to zero if a message arrives while you have that chat open - Fix for push notifications popping up when a message is received while that chat is open * Fix for cancelling notifications, works now. And scroll to bottom of conversation upon new message * Fix: Channels help grammer fix (#1452) * remove outdated TCP not available on Apple devices (#1450) * Update initial onboarding view * remove toggle gating for mac * Update crash reporting opt out in real time * Update onboarding text * Use mDNS text records for node name * TCP IP and port on the connection screen * Hide app icon chooser on mac * Infinite loop hang bugfixes and performance improvements for both `UserMessageList` and `ChannelMessageList` (#1465) * 2.7.5 Working Changes (#1460) * Remove extra want config call when adding a contact * App badge and unnecessary notification fixes (#1455) * - Fix for app badge not going to zero if a message arrives while you have that chat open - Fix for push notifications popping up when a message is received while that chat is open * Fix for cancelling notifications, works now. And scroll to bottom of conversation upon new message * Fix: Channels help grammer fix (#1452) * remove outdated TCP not available on Apple devices (#1450) * Update initial onboarding view * remove toggle gating for mac * Update crash reporting opt out in real time * Update onboarding text --------- Co-authored-by: Gnome Adrift <646322+gnomeadrift@users.noreply.github.com> Co-authored-by: Zain Kergaye <62440012+ZainKergaye@users.noreply.github.com> Co-authored-by: NillRudd <102033730+NillRudd@users.noreply.github.com> * UserEntity: add mostRecentMessage and unreadMessages with early exit when lastMessage is nil, and fetch 1 row (not N) otherwise * UserList: replace 5 slow calls to user.messageList with new fast calls * NodeList: always put the connected node at the top of list (if it matches the node filters) * ChannelEntity: add faster mostRecentPrivateMessage and unreadMessages which fetch 1 row (not N) * ChannelList: replace 5 calls to channel.allPrivateMessage with new fast calls * Fix incorrect appState.unreadDirectMessages calculations * MyInfoEntity: also fix unreadMessages count here to be fast, and use it for appState.unreadChannelMessages * UserMessageList: use @FetchRequest to prevent the N^2 behavior that was happening in calls to allPrivateMessages * Refactor ChannelEntityExtension and MyInfoEntityExtension to be more similar to UserEntityExtension * Remove SwiftUI-infinite-loop-causing `.id(redrawTapbacksTrigger)` in ChannelMessageList and UserMessageList (duplicate row ids) * MyInfoEntityExtension: exclude emoji tapbacks (which never get marked as read anyway) from unread message count * Add SaveChannelLinkData so MessageText and MeshtasticApp can use .sheet(item: ...) and avoid infinite loop hang due to Binding rebuild * ChannelMessageList and UserMessageList: switch to stable messageId for ForEach SwiftUI row identity * ChannelMessageList and UserMessageList: debouncedScrollToBottom; keyboardWillShowNotification/keyboardDidShowNotification * ChannelMessageList and UserMessageList: scroll to bottom onFirstAppear * ChannelMessageList and UserMessageList: block spurious markMessagesAsRead when this View is not active --------- Co-authored-by: Garth Vander Houwen <garth@meshtastic.com> Co-authored-by: Gnome Adrift <646322+gnomeadrift@users.noreply.github.com> Co-authored-by: Zain Kergaye <62440012+ZainKergaye@users.noreply.github.com> Co-authored-by: NillRudd <102033730+NillRudd@users.noreply.github.com> * message-list-performance: revert scrolling changes (#1472) * Reverte0f0b4a0f7(ChannelMessageList and UserMessageList: scroll to bottom onFirstAppear) * Revert "ChannelMessageList and UserMessageList: debouncedScrollToBottom; keyboardWillShowNotification/keyboardDidShowNotification" This reverts commitee1a7c4415. --------- Co-authored-by: Gnome Adrift <646322+gnomeadrift@users.noreply.github.com> Co-authored-by: Zain Kergaye <62440012+ZainKergaye@users.noreply.github.com> Co-authored-by: NillRudd <102033730+NillRudd@users.noreply.github.com> Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Mike Robbins <mrobbins@alum.mit.edu> * Explicitly set unmessagable, seems unnessary * Add back missing mesh map features * Fix: "Retrieving nodes" significantly slower after reconnect extracted from #1424 (#1477) * Fix: "Retrieving nodes" significantly slower after reconnect (#1424) The node database retrieval was calling context.save() for every single NodeInfo packet received (250 saves for 250 nodes). This caused severe performance degradation on reconnect when CoreData had accumulated state. Root Cause: - nodeInfoPacket() called context.save() immediately for each node - With 250 nodes, this meant 250 individual CoreData save operations - On first connection, CoreData is fresh and fast - On reconnect, CoreData has accumulated change tracking, undo management, and memory pressure, making each save progressively slower - This resulted in 10+ second retrieval times vs 1-2 seconds initially Solution: - Added deferSave parameter to nodeInfoPacket() function - During database retrieval (.retrievingDatabase state), defer all saves - Perform a single batch save when database retrieval completes (when NONCE_ONLY_DB configCompleteID is received) - This reduces 250 saves to 1 save Performance Impact: - Eliminates N individual saves during node database sync - Reduces database retrieval time back to 1-2 seconds on reconnect - Matches first-connection performance consistently Fixes #1424 * Revert *MessageListUnified files --------- Co-authored-by: Martin Bogomolni <martinbogo@gmail.com> Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Hide route lines filter from mesh map * Mesh Map: fuzz imprecise locations so they're distinguishable and clickable at the highest zoom levels (#1478) Co-authored-by: Garth Vander Houwen <garth@meshtastic.com> * Fix bad merge * Update Meshtastic/Extensions/CoreData/UserEntityExtension.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Extensions/CoreData/ChannelEntityExtension.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Extensions/CoreData/MyInfoEntityExtension.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Extensions/CoreData/ChannelEntityExtension.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Keep list of previous manual connections (#1484) * Keep list of previous manual connections * More descriptive manual connection rows * Merge fixes and new way to show IP on Connect view --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Show who relayed messages (#1486) * Add identification for node that relayed text messages and add count for ammount of relayers of your message * Ack Relays * upsertPositionPacket: don't use future timestamps to set node's lastHeard (#1488) * R1 NEO * Neo * Update Meshtastic/Views/Settings/AppSettings.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove bad if * Git rid of extra environment variable * Update Meshtastic/Accessory/Transports/TCP/TCPTransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * MeshMap performance: quick wins (#1490) * MeshMap: change onMapCameraChange frequency to .onEnd so that zooming doesn't cause continuous SwiftUI reevaluation on every frame * MeshMapContent: factor out reducedPrecisionMapCircles into a separate function * MeshMapContent: when multiple reducedPrecisionCircles have the same (lat,lon,radius), just draw one (big perf boost in dense areas) * NodeMap performance improvements for high # positions history (#1480) * NodeMapContent: move Route Lines out of ForEach * NodeMapContent: move Convex Hull out of ForEach * NodeMapContent: Replace `position.nodePosition?` with `node` * NodeMapContent: drop unnecessary LazyVStack in showNodeHistory * NodeMapContent: hoist out nodeColorSwift * Move lineCoords, loraCoords calculations within showRouteLines, showConvexHull respectively * Hoist out repeated node.metadata?.positionFlags lookups / PositionFlags creation * NodeMapContent: remove unused @State * NodeMapSwiftUI: add NodeMapContentEquatableWrapper and NodeMapContentSignature to prevent frequent NodeMapContent recomputation and infinite render loops * NodeMapSwiftUI: disable animation during SwiftUI transactions * NodeMapContent: hoist nodeBorderColor and set allowsHitTesting(false) on history point views * NodeMapContent: prerenderHistoryPointCircle and prerenderHistoryPointArrow to avoid thousands of vector draw operations * NodeMapContent: Shared coordinate list for Route Lines and Convex Hull * NodeMapContent.prerenderHistoryPointArrow: add .frame(width: 16, height: 16) * Fix wantRangeTestPackets to correctly follow rangeTestConfig.enabled (#1489) * Fix interval drop down formatter * Clean up channel qr code functionality. * perferredPeripheralId fix * Set opt in * Retry once 5 second timer. dont throw the error * Queue for peripherals * Fix: hoplimit of dms would always fallback to hops away of the node even when configured hops was higher (#1495) * fix hops setting in dms * Fix hops for exchange position * Final fix * Don't favorite client base * Update device hardware * Prevent nil environment metrics * Bump datadog sdk * fix setting device telemetry enabled (#1515) * Update Muzi R1 Neo to actively supported * fix setting device telemetry enabled --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Don't subscribe to mqtt topic if downlink is not on (#1501) * Dont sub if no downlink * moved reload mqtt connect config * Preview enabled in connected devices (#1509) * Update Muzi R1 Neo to actively supported * Preview enabled in connected devices * Fixing indentation * Fixing indentation --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * UpdateCoreData.updateAnyPacketFrom: mirror firmware's lastHeard/snr/rssi/hopsAway update logic from NodeDB::updateFrom (#1492) * `CLIENT_BASE` add-favorite/role-change confirmation dialog (#1493) * FavoriteNodeButton: refactor task out * AccessoryManager.connectedDeviceRole helper * FavoriteNodeButton: show confirmation dialog when a CLIENT_BASE is trying to add a favorite * addContactFromURL: add comment referencing upcoming change in https://github.com/meshtastic/firmware/pull/8495 * DeviceConfig: role picker: show a warning when selecting CLIENT_BASE, similar to warning shown for ROUTER * Adjust device configuration Client Base warning text * Compass view (#1521) * Added compass view * Added Compass View * Node colors in compass * Update Muzi R1 Neo to actively supported * Update PositionPopover.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update CompassView.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update CompassView.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Helpers/CompassView.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Helpers/CompassView.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove discovery queue * revert problematic retry functionalliy * format file * Update & improve zh-Hans translation (#1523) * Update Muzi R1 Neo to actively supported * update & improve zh-Hans translation rt --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Update protobufs to 2.7.1 * Add long-turbo preset * Disable Range Test module when primary channel is public/unsecured (#1512) * Update Muzi R1 Neo to actively supported * Disable Range Test module when primary channel is public/unsecured Updated RangeTestConfig.swift to determine whether the primary channel (index 0) is operating without encryption or with a 1-byte minimal PSK. Disabled Range Test UI controls when on a public/default channel to prevent user interaction. Added safety enforcement in the save operation: Range Test enabled flag is automatically forced to false before sending updates to the device. Introduced a computed property isPrimaryChannelPublic following existing code patterns and security indicators (e.g., hexDescription PSK length). Matches the behavior implemented in the Android client for consistent policy across platforms. --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Add new device images * Remove print statement, get rid of cut and paste error --------- Co-authored-by: Gnome Adrift <646322+gnomeadrift@users.noreply.github.com> Co-authored-by: Zain Kergaye <62440012+ZainKergaye@users.noreply.github.com> Co-authored-by: NillRudd <102033730+NillRudd@users.noreply.github.com> Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Mike Robbins <mrobbins@alum.mit.edu> Co-authored-by: Martin Bogomolni <martinbogo@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: jake-b <1012393+jake-b@users.noreply.github.com> Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Charles Pinesky <25388414+Vaidios@users.noreply.github.com> Co-authored-by: Radio <35003866+radiolee@users.noreply.github.com> Co-authored-by: Jason Houk <dubsectordevelopment@gmail.com>
456 lines
14 KiB
Swift
456 lines
14 KiB
Swift
import CoreBluetooth
|
|
import OSLog
|
|
import SwiftUI
|
|
import Foundation
|
|
import MapKit
|
|
|
|
struct DeviceOnboarding: View {
|
|
enum SetupGuide: Hashable {
|
|
case notifications
|
|
case location
|
|
case localNetwork
|
|
case bluetooth
|
|
}
|
|
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
@State var navigationPath: [SetupGuide] = []
|
|
@State var locationStatus = LocationsHandler.shared.manager.authorizationStatus
|
|
@AppStorage("provideLocation") private var provideLocation: Bool = false
|
|
@AppStorage("provideLocationInterval") private var provideLocationInterval: Int = 30
|
|
@Environment(\.dismiss) var dismiss
|
|
/// The Title View
|
|
var title: some View {
|
|
VStack {
|
|
Text("Welcome to")
|
|
.font(.title2.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Text("Meshtastic")
|
|
.font(.largeTitle.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
}
|
|
|
|
var welcomeView: some View {
|
|
VStack {
|
|
ScrollView(.vertical) {
|
|
VStack {
|
|
// Title
|
|
title
|
|
.padding(.top)
|
|
// Onboarding
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
makeRow(
|
|
icon: "antenna.radiowaves.left.and.right",
|
|
title: String(localized: "Stay Connected Anywhere"),
|
|
subtitle: String(localized: "Communicate off-the-grid with your friends and community without cell service.")
|
|
)
|
|
makeRow(
|
|
icon: "point.3.connected.trianglepath.dotted",
|
|
title: String(localized: "Create Your Own Networks"),
|
|
subtitle: String(localized: "Easily set up private mesh networks for secure and reliable communication in remote areas.")
|
|
)
|
|
makeRow(
|
|
icon: "location",
|
|
title: String(localized: "Track and Share Locations"),
|
|
subtitle: String(localized: "Share your location in real-time and keep your group coordinated with integrated GPS features.")
|
|
)
|
|
makeRow(
|
|
icon: "person.2.shield",
|
|
title: String(localized: "User Privacy"),
|
|
subtitle: String(localized: "Meshtastic does not collect any personal information. We do anonymously collect usage and crash data to improve the app. You can opt out under app settings.")
|
|
)
|
|
}
|
|
.padding()
|
|
}
|
|
.interactiveDismissDisabled()
|
|
}
|
|
Spacer()
|
|
Button {
|
|
Task {
|
|
await goToNextStep(after: nil)
|
|
}
|
|
} label: {
|
|
Text("Get started")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
var notificationView: some View {
|
|
VStack {
|
|
ScrollView(.vertical) {
|
|
VStack {
|
|
Text("App Notifications")
|
|
.font(.largeTitle.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
Spacer()
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("Send Notifications")
|
|
.font(.title2.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
makeRow(
|
|
icon: "message",
|
|
title: String(localized: "Incoming Messages"),
|
|
subtitle: String(localized: "Notifications for channel and direct messages.")
|
|
)
|
|
makeRow(
|
|
icon: "flipphone",
|
|
title: String(localized: "New Nodes"),
|
|
subtitle: String(localized: "Notifications for newly discovered nodes.")
|
|
)
|
|
makeRow(
|
|
icon: "battery.25percent",
|
|
title: String(localized: "Low Battery"),
|
|
subtitle: String(localized: "Notifications for low battery alerts for the connected device.")
|
|
)
|
|
Text("Critical Alerts")
|
|
.font(.title2.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
makeRow(
|
|
icon: "exclamationmark.triangle.fill",
|
|
subtitle: String(localized: "Select packets sent as critical will ignore the mute switch and Do Not Disturb settings in the OS notification center.")
|
|
)
|
|
}
|
|
.padding()
|
|
}
|
|
Spacer()
|
|
Button {
|
|
Task {
|
|
await requestNotificationsPermissions()
|
|
await goToNextStep(after: .notifications)
|
|
}
|
|
} label: {
|
|
Text("Configure notification permissions")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
var locationView: some View {
|
|
VStack {
|
|
ScrollView(.vertical) {
|
|
VStack {
|
|
Text("Phone Location")
|
|
.font(.largeTitle.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text(createLocationString())
|
|
.font(.body.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
makeRow(
|
|
icon: "location",
|
|
title: String(localized: "Share Location"),
|
|
subtitle: String(localized: "Use your phone GPS to send locations to your node to instead of using a hardware GPS on your node.")
|
|
)
|
|
Toggle(isOn: $provideLocation ) {
|
|
Label {
|
|
Text("Enable Location Sharing")
|
|
} icon: {
|
|
Image(systemName: "location.circle")
|
|
}
|
|
}
|
|
.fixedSize()
|
|
.scaleEffect(0.85)
|
|
.padding(.leading, 52)
|
|
.tint(.accentColor)
|
|
.onChange(of: provideLocation) {
|
|
UserDefaults.provideLocationInterval = 30
|
|
UserDefaults.enableSmartPosition = true
|
|
}
|
|
makeRow(
|
|
icon: "lines.measurement.horizontal",
|
|
title: String(localized: "Distance Measurements"),
|
|
subtitle: String(localized: "Display the distance between your phone and other Meshtastic nodes with positions.")
|
|
)
|
|
makeRow(
|
|
icon: "line.3.horizontal.decrease.circle",
|
|
title: String(localized: "Distance Filters"),
|
|
subtitle: String(localized: "Filter the node list and mesh map based on proximity to your phone.")
|
|
)
|
|
makeRow(
|
|
icon: "mappin",
|
|
title: String(localized: "Mesh Map Location"),
|
|
subtitle: String(localized: "Enables the blue location dot for your phone in the mesh map.")
|
|
)
|
|
}
|
|
.padding()
|
|
}
|
|
Spacer()
|
|
Button {
|
|
Task {
|
|
await requestLocationPermissions()
|
|
}
|
|
} label: {
|
|
Text("Configure Location Permissions")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.padding()
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
var localNetworkView: some View {
|
|
VStack {
|
|
ScrollView(.vertical) {
|
|
VStack {
|
|
Text("Local Network Access")
|
|
.font(.largeTitle.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text(createLocalNetworkString())
|
|
.font(.body.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
makeRow(
|
|
icon: "network",
|
|
title: "Network-based Nodes".localized,
|
|
subtitle: "The Meshtastic App can connect to and manage network-enabled nodes.".localized
|
|
)
|
|
makeRow(
|
|
icon: "person.and.background.dotted",
|
|
title: "Background Connections".localized,
|
|
subtitle: "Background network connections are not supported and may disconnect when you leave the app.".localized
|
|
)
|
|
makeRow(
|
|
icon: "arrow.trianglehead.2.clockwise",
|
|
title: "Minimum Firmware Version".localized,
|
|
subtitle: "For the best connection experience, minimum firmware version 2.7.4 is required.".localized
|
|
)
|
|
}
|
|
.padding()
|
|
}
|
|
Spacer()
|
|
Button {
|
|
Task {
|
|
await requestLocalNetworkPermissions()
|
|
await goToNextStep(after: .localNetwork)
|
|
}
|
|
} label: {
|
|
Text("Configure Local Network Access")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.padding()
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
var bluetoothView: some View {
|
|
VStack {
|
|
ScrollView(.vertical) {
|
|
VStack {
|
|
Text("Bluetooth Connectivity")
|
|
.font(.largeTitle.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text(createBluetoothString())
|
|
.font(.body.bold())
|
|
.multilineTextAlignment(.center)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
makeRow(
|
|
icon: "custom.bluetooth",
|
|
title: "Bluetooth Connected Nodes".localized,
|
|
subtitle: "The most reliable messaging experience is with Bluetooth Low Energy connected nodes.".localized
|
|
)
|
|
makeRow(
|
|
icon: "person.and.background.dotted",
|
|
title: "Background Connections".localized,
|
|
subtitle: "Bluetooth Low Energy supports background connections. When possible, the application will remain connected to these accessories while the app is in the background.".localized
|
|
)
|
|
}
|
|
.padding()
|
|
}
|
|
Spacer()
|
|
Button {
|
|
Task {
|
|
await requestBluetoothPermissions()
|
|
await goToNextStep(after: .bluetooth)
|
|
}
|
|
} label: {
|
|
Text("Configure Bluetooth Connectivity")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.padding()
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack(path: $navigationPath) {
|
|
welcomeView
|
|
.navigationDestination(for: SetupGuide.self) { guide in
|
|
switch guide {
|
|
case .notifications:
|
|
notificationView
|
|
case .location:
|
|
locationView
|
|
case .bluetooth:
|
|
bluetoothView
|
|
case .localNetwork:
|
|
localNetworkView
|
|
}
|
|
}
|
|
}
|
|
.toolbar(.hidden)
|
|
}
|
|
|
|
@ViewBuilder
|
|
func makeRow(
|
|
icon: String,
|
|
title: String = "",
|
|
subtitle: String
|
|
) -> some View {
|
|
HStack(alignment: .center) {
|
|
if icon.starts(with: "custom.") {
|
|
Image(icon)
|
|
.resizable()
|
|
.symbolRenderingMode(.multicolor)
|
|
.font(.subheadline)
|
|
.aspectRatio(contentMode: .fit)
|
|
.padding(.horizontal)
|
|
.padding(.vertical, 8)
|
|
.frame(width: 72, height: 60)
|
|
} else {
|
|
Image(systemName: icon)
|
|
.resizable()
|
|
.symbolRenderingMode(.multicolor)
|
|
.font(.subheadline)
|
|
.aspectRatio(contentMode: .fit)
|
|
.padding(.horizontal)
|
|
.padding(.vertical, 8)
|
|
.frame(width: 72, height: 60)
|
|
}
|
|
VStack(alignment: .leading) {
|
|
Text(title)
|
|
.font(.subheadline.weight(.semibold))
|
|
.foregroundColor(.primary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Text(subtitle)
|
|
.font(.subheadline)
|
|
.foregroundColor(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}.multilineTextAlignment(.leading)
|
|
}.accessibilityElement(children: .combine)
|
|
}
|
|
// MARK: Navigation
|
|
func goToNextStep(after step: SetupGuide?) async {
|
|
switch step {
|
|
case .none:
|
|
let status = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus
|
|
let criticalAlert = await UNUserNotificationCenter.current().notificationSettings().criticalAlertSetting
|
|
if status == .notDetermined && criticalAlert == .notSupported {
|
|
navigationPath.append(.notifications)
|
|
} else {
|
|
fallthrough
|
|
}
|
|
case .notifications:
|
|
locationStatus = LocationsHandler.shared.manager.authorizationStatus
|
|
if locationStatus == .notDetermined || locationStatus == .restricted || locationStatus == .denied {
|
|
navigationPath.append(.location)
|
|
} else {
|
|
fallthrough
|
|
}
|
|
case .location:
|
|
locationStatus = LocationsHandler.shared.manager.authorizationStatus
|
|
if locationStatus != .notDetermined && locationStatus != .restricted {
|
|
navigationPath.append(.localNetwork)
|
|
}
|
|
case .localNetwork:
|
|
navigationPath.append(.bluetooth)
|
|
|
|
case .bluetooth:
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
// MARK: Formatting
|
|
func createLocationString() -> AttributedString {
|
|
var fullText = AttributedString(localized: "Meshtastic uses your phone's location to enable a number of features. You can update your location permissions at any time from settings.")
|
|
if let range = fullText.range(of: String(localized: "settings")) {
|
|
fullText[range].link = URL(string: UIApplication.openSettingsURLString)!
|
|
fullText[range].foregroundColor = .blue
|
|
}
|
|
return fullText
|
|
}
|
|
|
|
func createLocalNetworkString() -> AttributedString {
|
|
var fullText = AttributedString("Meshtastic accesses your local network to connect to TCP-based accessories. You can update the local network permissions at any time from settings.")
|
|
if let range = fullText.range(of: "settings") {
|
|
fullText[range].link = URL(string: UIApplication.openSettingsURLString)!
|
|
fullText[range].foregroundColor = .blue
|
|
}
|
|
return fullText
|
|
}
|
|
|
|
func createBluetoothString() -> AttributedString {
|
|
var fullText = AttributedString("Meshtastic uses Bluetooth to connect to BLE-based accessories. You can update the permissions at any time from settings.")
|
|
if let range = fullText.range(of: "settings") {
|
|
fullText[range].link = URL(string: UIApplication.openSettingsURLString)!
|
|
fullText[range].foregroundColor = .blue
|
|
}
|
|
return fullText
|
|
}
|
|
|
|
// MARK: Permission Checks
|
|
func requestNotificationsPermissions() async {
|
|
let center = UNUserNotificationCenter.current()
|
|
do {
|
|
let success = try await center.requestAuthorization(options: [.alert, .badge, .sound, .criticalAlert])
|
|
if success {
|
|
Logger.services.info("Notification permissions are enabled")
|
|
} else {
|
|
Logger.services.info("Notification permissions denied")
|
|
}
|
|
} catch {
|
|
Logger.services.error("Notification permissions error: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
|
|
func requestLocationPermissions() async {
|
|
locationStatus = await LocationsHandler.shared.requestLocationAlwaysPermissions()
|
|
if locationStatus != .notDetermined {
|
|
Logger.services.info("Location permissions are enabled")
|
|
} else {
|
|
Logger.services.info("Location permissions denied")
|
|
}
|
|
await goToNextStep(after: .location)
|
|
}
|
|
|
|
func requestLocalNetworkPermissions() async {
|
|
_ = await TCPTransport.requestLocalNetworkAuthorization()
|
|
}
|
|
|
|
func requestBluetoothPermissions() async {
|
|
_ = await BluetoothAuthorizationHelper.requestBluetoothAuthorization()
|
|
}
|
|
|
|
}
|