Meshtastic-Apple/Meshtastic/AppIntents/DisconnectNodeIntent.swift
2025-04-02 18:02:27 -07:00

31 lines
788 B
Swift

//
// DisconnectNodeIntent.swift
// Meshtastic
//
// Created by Benjamin Faershtein on 4/2/25.
//
import Foundation
import AppIntents
struct DisconnectNodeIntent: AppIntent {
static var title: LocalizedStringResource = "Disconnect Node"
static var description: IntentDescription = "Disconnect the currently connected node"
func perform() async throws -> some IntentResult {
if !BLEManager.shared.isConnected {
throw AppIntentErrors.AppIntentError.notConnected
}
if let connectedPeripheral = BLEManager.shared.connectedPeripheral,
connectedPeripheral.peripheral.state == .connected {
BLEManager.shared.disconnectPeripheral(reconnect: false)
} else {
throw AppIntentErrors.AppIntentError.message("Error disconnecting node")
}
return .result()
}
}