mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Additional live activity cleanup
This commit is contained in:
parent
a07f0f6817
commit
832154a103
4 changed files with 36 additions and 23 deletions
|
|
@ -681,20 +681,21 @@ func telemetryPacket(packet: MeshPacket, connectedNode: Int64, context: NSManage
|
|||
if connectedNode != Int64(packet.from) {
|
||||
print("💾 Telemetry Saved for Node: \(packet.from)")
|
||||
} else if telemetry.metricsType == 0 {
|
||||
// Update our live activity if there is one running
|
||||
if #available(iOS 16.2, *) {
|
||||
var future = Calendar.current.date(byAdding: .minute, value: (Int(0) ), to: Date())!
|
||||
future = Calendar.current.date(byAdding: .second, value: (Int(60) ), to: future)!
|
||||
let date = Date.now...future
|
||||
let updatedMeshStatus = MeshActivityAttributes.MyActivityStatus(timerRange: date, connected: true, channelUtilization: telemetry.channelUtilization, airtime: telemetry.airUtilTx, batteryLevel: UInt32(telemetry.batteryLevel))
|
||||
let oneMinuteLater = Calendar.current.date(byAdding: .minute, value: (Int(1) ), to: Date())!
|
||||
let date = Date.now...oneMinuteLater
|
||||
let updatedMeshStatus = MeshActivityAttributes.MeshActivityStatus(timerRange: date, connected: true, channelUtilization: telemetry.channelUtilization, airtime: telemetry.airUtilTx, batteryLevel: UInt32(telemetry.batteryLevel))
|
||||
|
||||
let alertConfiguration = AlertConfiguration(title: "Mesh activity update", body: "Updated Metrics Data.", sound: .default)
|
||||
let alertConfiguration = AlertConfiguration(title: "Mesh activity update", body: "Updated Device Metrics Data.", sound: .default)
|
||||
let updatedContent = ActivityContent(state: updatedMeshStatus, staleDate: nil)
|
||||
print("Update live activity.")
|
||||
|
||||
let stuff = Activity<MeshActivityAttributes>.activities.first(where: { $0.attributes.nodeNum == connectedNode })
|
||||
if stuff != nil {
|
||||
let meshActivity = Activity<MeshActivityAttributes>.activities.first(where: { $0.attributes.nodeNum == connectedNode })
|
||||
if meshActivity != nil {
|
||||
Task {
|
||||
await stuff?.update(updatedContent, alertConfiguration: alertConfiguration)
|
||||
await meshActivity?.update(updatedContent, alertConfiguration: alertConfiguration)
|
||||
//await meshActivity?.update(updatedContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ struct Connect: View {
|
|||
func startNodeActivity() {
|
||||
if #available(iOS 16.2, *) {
|
||||
liveActivityStarted = true
|
||||
let timerSeconds = 300
|
||||
let timerSeconds = 60
|
||||
|
||||
let mostRecent = node?.telemetries?.lastObject as! TelemetryEntity
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import WidgetKit
|
|||
import SwiftUI
|
||||
|
||||
struct MeshActivityAttributes: ActivityAttributes {
|
||||
public typealias MyActivityStatus = ContentState
|
||||
public typealias MeshActivityStatus = ContentState
|
||||
public struct ContentState: Codable, Hashable {
|
||||
// Dynamic stateful properties about your activity go here!
|
||||
var timerRange: ClosedRange<Date>
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ struct WidgetsLiveActivity: Widget {
|
|||
var body: some WidgetConfiguration {
|
||||
|
||||
ActivityConfiguration(for: MeshActivityAttributes.self) { context in
|
||||
LiveActivityView(nodeName: context.attributes.name, connected: context.state.connected, channelUtilization: context.state.channelUtilization, airtime: context.state.airtime, batteryLevel: context.state.batteryLevel, timerRange: context.state.timerRange)
|
||||
LiveActivityView(nodeName: context.attributes.name, channelUtilization: context.state.channelUtilization, airtime: context.state.airtime, batteryLevel: context.state.batteryLevel, timerRange: context.state.timerRange)
|
||||
.widgetURL(URL(string: "meshtastic://node/\(context.attributes.name)"))
|
||||
|
||||
} dynamicIsland: { context in
|
||||
DynamicIsland {
|
||||
DynamicIslandExpandedRegion(.leading) {
|
||||
NodeInfoView(nodeName: context.attributes.name, connected: context.state.connected, channelUtilization: context.state.channelUtilization, airtime: context.state.airtime, batteryLevel: context.state.batteryLevel)
|
||||
NodeInfoView(nodeName: context.attributes.name, timerRange: context.state.timerRange, channelUtilization: context.state.channelUtilization, airtime: context.state.airtime, batteryLevel: context.state.batteryLevel)
|
||||
.tint(Color("LightIndigo"))
|
||||
.padding(.top)
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ struct LiveActivityView: View {
|
|||
@Environment(\.isLuminanceReduced) var isLuminanceReduced
|
||||
|
||||
var nodeName: String
|
||||
var connected: Bool
|
||||
//var connected: Bool
|
||||
var channelUtilization: Float
|
||||
var airtime: Float
|
||||
var batteryLevel: UInt32
|
||||
|
|
@ -102,7 +102,7 @@ struct LiveActivityView: View {
|
|||
Image(colorScheme == .light ? "logo-black" : "logo-white")
|
||||
.clipShape(ContainerRelativeShape())
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
NodeInfoView(nodeName: nodeName, connected: connected, channelUtilization: channelUtilization, airtime: airtime, batteryLevel: batteryLevel)
|
||||
NodeInfoView(nodeName: nodeName, timerRange: timerRange, channelUtilization: channelUtilization, airtime: airtime, batteryLevel: batteryLevel)
|
||||
Spacer()
|
||||
TimerView(timerRange: timerRange)
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ struct NodeInfoView: View {
|
|||
@Environment(\.isLuminanceReduced) var isLuminanceReduced
|
||||
|
||||
var nodeName: String
|
||||
var connected: Bool
|
||||
var timerRange: ClosedRange<Date>
|
||||
var channelUtilization: Float
|
||||
var airtime: Float
|
||||
var batteryLevel: UInt32
|
||||
|
|
@ -130,11 +130,6 @@ struct NodeInfoView: View {
|
|||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.tint)
|
||||
.fixedSize()
|
||||
Text(connected ? "Connected" : "Not Connected")
|
||||
.font(.callout)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.tint)
|
||||
.fixedSize()
|
||||
Text("\(String(format: "Ch. Util: %.2f", channelUtilization))%")
|
||||
.font(.subheadline)
|
||||
.fontWeight(.medium)
|
||||
|
|
@ -153,6 +148,12 @@ struct NodeInfoView: View {
|
|||
.foregroundStyle(.secondary)
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
.fixedSize()
|
||||
Text(Date().formatted())
|
||||
.font(.subheadline)
|
||||
.fontWeight(.medium)
|
||||
.foregroundStyle(.secondary)
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -163,10 +164,22 @@ struct TimerView: View {
|
|||
var timerRange: ClosedRange<Date>
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .trailing) {
|
||||
VStack(alignment: .center) {
|
||||
Text("NEXT")
|
||||
.font(.caption)
|
||||
.fontWeight(.medium)
|
||||
.foregroundStyle(.secondary)
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
.fixedSize()
|
||||
Text("UPDATE")
|
||||
.font(.caption)
|
||||
.fontWeight(.medium)
|
||||
.foregroundStyle(.secondary)
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
.fixedSize()
|
||||
Text(timerInterval: timerRange, countsDown: true)
|
||||
.monospacedDigit()
|
||||
.multilineTextAlignment(.trailing)
|
||||
.multilineTextAlignment(.center)
|
||||
.frame(width: 80)
|
||||
.font(.callout)
|
||||
.fontWeight(.semibold)
|
||||
|
|
@ -175,7 +188,6 @@ struct TimerView: View {
|
|||
.resizable()
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: 30, height: 30)
|
||||
.padding(.trailing, 7)
|
||||
.opacity(isLuminanceReduced ? 0.5 : 1.0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue