mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Added Save Channel Settings Intent
This commit is contained in:
parent
51c8e16879
commit
f90f292c42
3 changed files with 78 additions and 0 deletions
|
|
@ -2782,6 +2782,9 @@
|
|||
},
|
||||
"Channel Role" : {
|
||||
|
||||
},
|
||||
"Channel URL" : {
|
||||
|
||||
},
|
||||
"Channel Utilization %@%% " : {
|
||||
|
||||
|
|
@ -18850,6 +18853,9 @@
|
|||
},
|
||||
"Save" : {
|
||||
|
||||
},
|
||||
"Save Channel Settings" : {
|
||||
|
||||
},
|
||||
"Save User Config to %@?" : {
|
||||
|
||||
|
|
@ -20399,6 +20405,9 @@
|
|||
},
|
||||
"Supported I2C Connected sensors will be detected automatically, sensors are BMP280, BME280, BME680, MCP9808, INA219, INA260, LPS22 and SHTC3." : {
|
||||
|
||||
},
|
||||
"Takes a Meshtastic channel URL and saves the channel settings." : {
|
||||
|
||||
},
|
||||
"tapback" : {
|
||||
"localizations" : {
|
||||
|
|
@ -21099,6 +21108,9 @@
|
|||
},
|
||||
"The state of the LED (on/off)" : {
|
||||
|
||||
},
|
||||
"The URL for the channel settings" : {
|
||||
|
||||
},
|
||||
"There has been no response to a request for device metadata over the admin channel for this node." : {
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
6DEDA55C2A9592F900321D2E /* MessageEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */; };
|
||||
B399E8A42B6F486400E4488E /* RetryButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B399E8A32B6F486400E4488E /* RetryButton.swift */; };
|
||||
B3E905B12B71F7F300654D07 /* TextMessageField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E905B02B71F7F300654D07 /* TextMessageField.swift */; };
|
||||
BC6B45FF2CB2F98900723CEB /* SaveChannelSettingsIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC6B45FE2CB2F98900723CEB /* SaveChannelSettingsIntent.swift */; };
|
||||
BCB613812C67290800485544 /* SendWaypointIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB613802C67290800485544 /* SendWaypointIntent.swift */; };
|
||||
BCB613832C672A2600485544 /* MessageChannelIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB613822C672A2600485544 /* MessageChannelIntent.swift */; };
|
||||
BCB613852C68703800485544 /* NodePositionIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB613842C68703800485544 /* NodePositionIntent.swift */; };
|
||||
|
|
@ -276,6 +277,7 @@
|
|||
6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageEntityExtension.swift; sourceTree = "<group>"; };
|
||||
B399E8A32B6F486400E4488E /* RetryButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetryButton.swift; sourceTree = "<group>"; };
|
||||
B3E905B02B71F7F300654D07 /* TextMessageField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextMessageField.swift; sourceTree = "<group>"; };
|
||||
BC6B45FE2CB2F98900723CEB /* SaveChannelSettingsIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveChannelSettingsIntent.swift; sourceTree = "<group>"; };
|
||||
BCB613802C67290800485544 /* SendWaypointIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendWaypointIntent.swift; sourceTree = "<group>"; };
|
||||
BCB613822C672A2600485544 /* MessageChannelIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageChannelIntent.swift; sourceTree = "<group>"; };
|
||||
BCB613842C68703800485544 /* NodePositionIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodePositionIntent.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -590,6 +592,7 @@
|
|||
BCE2D3C42C7AE369008E6199 /* RestartNodeIntent.swift */,
|
||||
BCE2D3C82C7C377F008E6199 /* FactoryResetNodeIntent.swift */,
|
||||
BCE2D3C62C7B0D0A008E6199 /* ShortcutsProvider.swift */,
|
||||
BC6B45FE2CB2F98900723CEB /* SaveChannelSettingsIntent.swift */,
|
||||
);
|
||||
path = AppIntents;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -1474,6 +1477,7 @@
|
|||
DDDB444429F8A8DD00EE2349 /* Float.swift in Sources */,
|
||||
DDAB580F2B0DAFBC00147258 /* LocationEntityExtension.swift in Sources */,
|
||||
B3E905B12B71F7F300654D07 /* TextMessageField.swift in Sources */,
|
||||
BC6B45FF2CB2F98900723CEB /* SaveChannelSettingsIntent.swift in Sources */,
|
||||
D93068D72B8146690066FBC8 /* MessageText.swift in Sources */,
|
||||
DDC2E15826CE248E0042C5E4 /* MeshtasticApp.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
62
Meshtastic/AppIntents/SaveChannelSettingsIntent.swift
Normal file
62
Meshtastic/AppIntents/SaveChannelSettingsIntent.swift
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// SaveChannelSettingsIntent.swift
|
||||
// Meshtastic
|
||||
//
|
||||
// Created by Benjamin Faershtein on 10/6/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AppIntents
|
||||
|
||||
// Define the AppIntent for saving channel settings from a URL
|
||||
struct SaveChannelSettingsIntent: AppIntent {
|
||||
// Define a title and description for the intent
|
||||
static var title: LocalizedStringResource = "Save Channel Settings"
|
||||
static var description: IntentDescription = "Takes a Meshtastic channel URL and saves the channel settings."
|
||||
|
||||
// Define the input for the intent (the channel URL)
|
||||
@Parameter(title: "Channel URL", description: "The URL for the channel settings")
|
||||
var channelUrl: URL
|
||||
|
||||
// Define the function that performs the main logic
|
||||
func perform() async throws -> some IntentResult {
|
||||
// Ensure the BLE Manager is connected
|
||||
if !BLEManager.shared.isConnected {
|
||||
throw AppIntentErrors.AppIntentError.notConnected
|
||||
}
|
||||
|
||||
// Ensure the URL contains the expected "meshtastic.org/e/#" structure
|
||||
if channelUrl.absoluteString.lowercased().contains("meshtastic.org/e/#") {
|
||||
// Split the URL to get the portion after "#"
|
||||
let components = channelUrl.absoluteString.components(separatedBy: "#")
|
||||
|
||||
// Add channels flag based on the URL query parameter (if present)
|
||||
let addChannels = Bool(channelUrl["add"] ?? "false") ?? false
|
||||
|
||||
var channelSettings: String?
|
||||
|
||||
// Extract the Base64 encoded channel settings (after "#")
|
||||
if let lastComponent = components.last {
|
||||
channelSettings = lastComponent.components(separatedBy: "?").first // Ignore any query parameters
|
||||
}
|
||||
|
||||
// If valid channel settings are extracted, attempt to save them
|
||||
if let channelSettings = channelSettings {
|
||||
print(channelSettings)
|
||||
// Call the BLEManager to save the channel settings
|
||||
let saveResult = BLEManager.shared.saveChannelSet(base64UrlString: channelSettings, addChannels: addChannels)
|
||||
|
||||
if !saveResult {
|
||||
throw AppIntentErrors.AppIntentError.message("Failed to save the channel settings.")
|
||||
}
|
||||
} else {
|
||||
throw AppIntentErrors.AppIntentError.message("Invalid Channel URL: Unable to extract settings.")
|
||||
}
|
||||
|
||||
// Return a success result
|
||||
return .result()
|
||||
} else {
|
||||
throw AppIntentErrors.AppIntentError.message("The URL is not a valid Meshtastic channel link.")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue