-
-
Notifications
You must be signed in to change notification settings - Fork 113
Add share contact via QR (and untested scanning of contact QR codes) #1225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
05397db
Add shared contact functionality (WIP)
thebentern 6fc6a8f
Fix QR code generation being slow as ball and log error
thebentern 9a5b3d7
Update Meshtastic/Views/Nodes/NodeList.swift
thebentern bb43a1e
Update Meshtastic/Views/Nodes/Helpers/ShareContactQRDialog.swift
thebentern 1b00ea7
Update Meshtastic/MeshtasticApp.swift
thebentern 2857ed3
Update Meshtastic/Extensions/CoreData/NodeInfoEntityToNodeInfo.swift
thebentern 01893e0
Copilot jacked up my braces
thebentern bf55f35
Update Meshtastic/Extensions/CoreData/NodeInfoEntityToNodeInfo.swift
thebentern 382402a
Update Meshtastic/Extensions/CoreData/NodeInfoEntityToNodeInfo.swift
thebentern d5ce823
Defaults
thebentern be36dc6
Import Contact App Shortcut and add a share url button to the page
RCGV1 863f51b
Update ShareContactQRDialog.swift
thebentern 9be356a
Merge pull request #1226 from RCGV1/user-import-intent
thebentern de3f834
Updated protobufs
thebentern bd70589
Missed a couple
thebentern 7196596
Update Localizable.xcstrings
thebentern 3d04610
Plumb proto
thebentern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// AddContactIntent.swift | ||
// Meshtastic | ||
// | ||
// Created by Benjamin Faershtein on 5/13/25. | ||
// | ||
|
||
import AppIntents | ||
import MeshtasticProtobufs | ||
|
||
struct AddContactIntent: AppIntent { | ||
static var title: LocalizedStringResource = "Add Contact" | ||
static var description: IntentDescription = "Takes a Meshtastic contact URL and saves it to the nodes database" | ||
|
||
@Parameter(title: "Contact URL", description: "The URL for the node to add") | ||
var contactUrl: 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 | ||
} | ||
|
||
if contactUrl.absoluteString.lowercased().contains("meshtastic.org/v/#") { | ||
|
||
let components = self.contactUrl.absoluteString.components(separatedBy: "#") | ||
// Extract contact information from the URL | ||
if let contactData = components.last { | ||
thebentern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let decodedString = contactData.base64urlToBase64() | ||
if let decodedData = Data(base64Encoded: decodedString) { | ||
do { | ||
let success = BLEManager.shared.addContactFromURL(base64UrlString: contactData) | ||
if !success { | ||
throw AppIntentErrors.AppIntentError.message("Failed to add contact") | ||
} | ||
|
||
} catch { | ||
throw AppIntentErrors.AppIntentError.message("Failed to parse contact data: \(error.localizedDescription)") | ||
|
||
} | ||
} | ||
} | ||
// Return a success result | ||
return .result() | ||
} else { | ||
throw AppIntentErrors.AppIntentError.message("The URL is not a valid Meshtastic contact link") | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Meshtastic/Extensions/CoreData/NodeInfoEntityToNodeInfo.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// NodeInfoEntityToNodeInfo.swift | ||
// Meshtastic | ||
// | ||
// Utility to convert NodeInfoEntity (Core Data) to NodeInfo (protobuf) | ||
|
||
import Foundation | ||
import MeshtasticProtobufs | ||
|
||
extension NodeInfoEntity { | ||
func toProto() -> NodeInfo { | ||
var userProto = User() | ||
if let user = self.user { | ||
userProto.id = user.userId ?? "" | ||
userProto.longName = user.longName ?? "" | ||
userProto.shortName = user.shortName ?? "" | ||
userProto.hwModel = HardwareModel(rawValue: Int(user.hwModelId)) ?? .unset | ||
userProto.isLicensed = user.isLicensed | ||
userProto.role = Config.DeviceConfig.Role(rawValue: Int(user.role)) ?? .client | ||
userProto.publicKey = user.publicKey?.subdata(in: 0..<user.publicKey!.count) ?? Data() | ||
} | ||
var node = NodeInfo() | ||
node.num = UInt32(self.num) | ||
node.user = userProto | ||
thebentern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Add more fields as needed | ||
return node | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.