make live activity menu item toggle properly

This commit is contained in:
Garth Vander Houwen 2023-03-01 23:49:38 -08:00
parent 4ca3cf89ab
commit 00d9f7b474
3 changed files with 87 additions and 19 deletions

View file

@ -225,7 +225,7 @@ struct Connect: View {
HStack(alignment: .center) {
Spacer()
#if targetEnvironment(macCatalyst)
#if targetEnvironment(macCatalyst)
if bleManager.connectedPeripheral != nil {
@ -246,7 +246,7 @@ struct Connect: View {
.controlSize(.large)
.padding()
}
#endif
#endif
Spacer()
}
.padding(.bottom, 10)
@ -336,6 +336,7 @@ func startNodeActivity() {
}
func endActivity() {
liveActivityStarted = false
Task {
if #available(iOS 16.2, *) {
for activity in Activity<MeshActivityAttributes>.activities {

View file

@ -1,20 +1,66 @@
////
//// Widgets.swift
//// Widgets
////
//// Created by Garth Vander Houwen on 2/28/23.
////
//
// WidgetsBundle.swift
// Widgets
//import WidgetKit
//import SwiftUI
//
// Created by Garth Vander Houwen on 2/28/23.
//struct Provider: TimelineProvider {
// func placeholder(in context: Context) -> SimpleEntry {
// SimpleEntry(date: Date())
// }
//
import WidgetKit
import SwiftUI
@main
struct Widgets: WidgetBundle {
var body: some Widget {
// MARK: - Live Activity Widgets
#if canImport(ActivityKit)
MeshActivityWidget()
#endif
}
}
// func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
// let entry = SimpleEntry(date: Date())
// completion(entry)
// }
//
// func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
// var entries: [SimpleEntry] = []
//
// // Generate a timeline consisting of five entries an hour apart, starting from the current date.
// let currentDate = Date()
// for hourOffset in 0 ..< 5 {
// let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
// let entry = SimpleEntry(date: entryDate)
// entries.append(entry)
// }
//
// let timeline = Timeline(entries: entries, policy: .atEnd)
// completion(timeline)
// }
//}
//
//struct SimpleEntry: TimelineEntry {
// let date: Date
//}
//
//struct WidgetsEntryView : View {
// var entry: Provider.Entry
//
// var body: some View {
// Text(entry.date, style: .time)
// }
//}
//
//struct Widgets: Widget {
// let kind: String = "Widgets"
//
// var body: some WidgetConfiguration {
// StaticConfiguration(kind: kind, provider: Provider()) { entry in
// WidgetsEntryView(entry: entry)
// }
// .configurationDisplayName("My Widget")
// .description("This is an example widget.")
// }
//}
//
//struct Widgets_Previews: PreviewProvider {
// static var previews: some View {
// WidgetsEntryView(entry: SimpleEntry(date: Date()))
// .previewContext(WidgetPreviewContext(family: .systemSmall))
// }
//}

View file

@ -0,0 +1,21 @@
//
// WidgetsBundle.swift
// Widgets
//
// Created by Garth Vander Houwen on 2/28/23.
//
import WidgetKit
import SwiftUI
@available(iOSApplicationExtension 16.2, *)
@main
struct WidgetsBundle: WidgetBundle {
var body: some Widget {
//Widgets()
#if canImport(ActivityKit)
WidgetsLiveActivity()
#endif
}
}