mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
This change modifies the process for generating and integrating the Meshtastic protobufs into the client application. * The generated Swift code is now in a local SPM package `MeshtasticProtobufs` * An Xcode Workspace file `Meshtastic.xcworkspace` was created to more easily manage the new build targets. * The code generation script for the protos was modified to generate the Swift code into the new location. * The README.md was updated to reflect these changes. NOTE: After merging this PR, do not open the project file `Meshtastic.xcodeproj`. You must use the workspace `Meshtastic.xcworkspace` Extracting out the generated protobuf code into its own library enables several opportunities for the project. This is just a first step, but with some more modularization, a standalone Apple Watch app or other targets starts to become a little bit more achievable to implement. After extracting the protobufs into a Swift package, I validate these changes by building and running the Meshtastic app to an iPhone 15 Pro Max, and tried changing some settings on a local node. I then messaged back and forth using two local nodes connected to two different iOS devices.
25 lines
913 B
Swift
25 lines
913 B
Swift
import Foundation
|
|
import CoreData
|
|
import MeshtasticProtobufs
|
|
|
|
extension DeviceMetadataEntity {
|
|
convenience init(
|
|
context: NSManagedObjectContext,
|
|
metadata: DeviceMetadata
|
|
) {
|
|
self.init(context: context)
|
|
self.time = Date()
|
|
self.deviceStateVersion = Int32(metadata.deviceStateVersion)
|
|
self.canShutdown = metadata.canShutdown
|
|
self.hasWifi = metadata.hasWifi_p
|
|
self.hasBluetooth = metadata.hasBluetooth_p
|
|
self.hasEthernet = metadata.hasEthernet_p
|
|
self.role = Int32(metadata.role.rawValue)
|
|
self.positionFlags = Int32(metadata.positionFlags)
|
|
// Swift does strings weird, this does work to get the version without the github hash
|
|
let lastDotIndex = metadata.firmwareVersion.lastIndex(of: ".")
|
|
var version = metadata.firmwareVersion[...(lastDotIndex ?? String.Index(utf16Offset: 6, in: metadata.firmwareVersion))]
|
|
version = version.dropLast()
|
|
self.firmwareVersion = String(version)
|
|
}
|
|
}
|