From 00d9f7b4747b70d9525bcc6f9f25cc554d7f0057 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 1 Mar 2023 23:49:38 -0800 Subject: [PATCH] make live activity menu item toggle properly --- Meshtastic/Views/Bluetooth/Connect.swift | 5 +- Widgets/Widgets.swift | 80 +++++++++++++++++++----- Widgets/WidgetsBundle.swift | 21 +++++++ 3 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 Widgets/WidgetsBundle.swift diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 7c589b2c..80d65a37 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -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.activities { diff --git a/Widgets/Widgets.swift b/Widgets/Widgets.swift index a060da8b..2dccff37 100644 --- a/Widgets/Widgets.swift +++ b/Widgets/Widgets.swift @@ -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) -> ()) { +// 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)) +// } +//} diff --git a/Widgets/WidgetsBundle.swift b/Widgets/WidgetsBundle.swift new file mode 100644 index 00000000..950954a7 --- /dev/null +++ b/Widgets/WidgetsBundle.swift @@ -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 + + } +}