diff --git a/LaunchWidget/LaunchWidget.intentdefinition b/LaunchWidget/LaunchWidget.intentdefinition
index afad2f3..8050ce0 100644
--- a/LaunchWidget/LaunchWidget.intentdefinition
+++ b/LaunchWidget/LaunchWidget.intentdefinition
@@ -78,7 +78,7 @@
INIntentParameterArraySizeSize
- 2
+ 1
INIntentParameterArraySizeSizeClass
AccessoryRectangular
diff --git a/LaunchWidget/LaunchWidget.swift b/LaunchWidget/LaunchWidget.swift
index 60e6c6a..ffac9d0 100644
--- a/LaunchWidget/LaunchWidget.swift
+++ b/LaunchWidget/LaunchWidget.swift
@@ -48,13 +48,7 @@ struct Provider: IntentTimelineProvider {
}
struct SimpleEntry: TimelineEntry {
-
let countdowns: [Countdown]
-
-// let id: String
-// let name: String?
-// let duration: Double
-
let date: Date
let configuration: SelectCountdownIntent
}
@@ -64,7 +58,7 @@ struct CountdownSimpleWidgetView: View {
let countdown: Countdown
var body: some View {
- CountdownView(countdown: countdown)
+ SingleCountdownView(countdown: countdown)
.widgetURL(countdown.url)
}
@@ -75,14 +69,14 @@ struct CountdownMultiWidgetView: View {
let countdowns: [Countdown]
var body: some View {
- CountdownMultiView(countdowns: countdowns)
+ MultiCountdownView(countdowns: countdowns)
}
}
struct VoidView : View {
var body: some View {
- Text("Nothing here")
+ Text("Configure me!")
}
}
@@ -102,7 +96,7 @@ struct LaunchWidgetEntryView : View {
VoidView()
}
default:
- CountdownMultiView(countdowns: entry.countdowns)
+ MultiCountdownView(countdowns: entry.countdowns)
// case .systemMedium: GameStatusWithLastTurnResult(gameStatus)
// case .systemLarge: GameStatusWithStatistics(gameStatus)
@@ -127,7 +121,7 @@ struct LaunchWidget: Widget {
}
.configurationDisplayName("Launch Widget")
.description("Select and launch your countdowns")
- .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryRectangular])
+ .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryRectangular, .accessoryCircular])
}
}
diff --git a/LaunchWidget/CountdownView.swift b/LaunchWidget/SingleCountdownView.swift
similarity index 61%
rename from LaunchWidget/CountdownView.swift
rename to LaunchWidget/SingleCountdownView.swift
index abaa0dd..0f126d6 100644
--- a/LaunchWidget/CountdownView.swift
+++ b/LaunchWidget/SingleCountdownView.swift
@@ -9,7 +9,7 @@ import SwiftUI
import WidgetKit
import CoreData
-struct CountdownView: View {
+struct SingleCountdownView: View {
@Environment(\.widgetFamily) var family: WidgetFamily
@@ -21,6 +21,7 @@ struct CountdownView: View {
Text(countdown.duration.minuteSecond)
}
.font(self.font)
+ .widgetURL(countdown.url)
}
private var font: Font {
@@ -34,7 +35,7 @@ struct CountdownView: View {
}
-struct CountdownMultiView: View {
+struct MultiCountdownView: View {
@Environment(\.widgetFamily) var family: WidgetFamily
@@ -42,20 +43,24 @@ struct CountdownMultiView: View {
var body: some View {
- HStack {
- ForEach(countdowns) { countdown in
-
- Link(destination: countdown.url) {
- VStack {
- Text(countdown.name ?? "")
- Text(countdown.duration.minuteSecond)
+ if countdowns.isEmpty {
+ VoidView()
+ } else {
+ HStack {
+ ForEach(countdowns) { countdown in
+
+ Link(destination: countdown.url) {
+ VStack {
+ Text(countdown.name ?? "")
+ Text(countdown.duration.minuteSecond)
+ }
+ .font(self.font)
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
}
- .font(self.font)
- .frame(maxWidth: .infinity, maxHeight: .infinity)
+
}
-
- }
- }.frame(maxWidth: .infinity)
+ }.frame(maxWidth: .infinity)
+ }
}
@@ -73,8 +78,8 @@ struct CountdownMultiView: View {
struct CountdownView_Previews: PreviewProvider {
static var previews: some View {
- CountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryRectangular))
- CountdownMultiView(countdowns: self.countdowns(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .systemMedium))
+ SingleCountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryRectangular))
+ MultiCountdownView(countdowns: self.countdowns(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .systemMedium))
}
static func countdowns(context: NSManagedObjectContext) -> [Countdown] {
diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj
index 411d4b3..acc5607 100644
--- a/LeCountdown.xcodeproj/project.pbxproj
+++ b/LeCountdown.xcodeproj/project.pbxproj
@@ -31,7 +31,7 @@
C438C7E02981216300BF3EF9 /* LaunchWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */; };
C438C7E32981216300BF3EF9 /* LaunchWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = C438C7CE2981216200BF3EF9 /* LaunchWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
C438C7E82981255D00BF3EF9 /* TimeInterval+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */; };
- C438C7EB2981266F00BF3EF9 /* CountdownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7E92981260D00BF3EF9 /* CountdownView.swift */; };
+ C438C7EB2981266F00BF3EF9 /* SingleCountdownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7E92981260D00BF3EF9 /* SingleCountdownView.swift */; };
C438C7F229812BB200BF3EF9 /* Intents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C438C7F129812BB200BF3EF9 /* Intents.framework */; };
C438C7F529812BB200BF3EF9 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7F429812BB200BF3EF9 /* IntentHandler.swift */; };
C438C7F929812BB200BF3EF9 /* LaunchIntents.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = C438C7F029812BB200BF3EF9 /* LaunchIntents.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -127,7 +127,7 @@
C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = LaunchWidget.intentdefinition; sourceTree = ""; };
C438C7DC2981216300BF3EF9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
C438C7DE2981216300BF3EF9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
- C438C7E92981260D00BF3EF9 /* CountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountdownView.swift; sourceTree = ""; };
+ C438C7E92981260D00BF3EF9 /* SingleCountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleCountdownView.swift; sourceTree = ""; };
C438C7F029812BB200BF3EF9 /* LaunchIntents.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = LaunchIntents.appex; sourceTree = BUILT_PRODUCTS_DIR; };
C438C7F129812BB200BF3EF9 /* Intents.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Intents.framework; path = System/Library/Frameworks/Intents.framework; sourceTree = SDKROOT; };
C438C7F429812BB200BF3EF9 /* IntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentHandler.swift; sourceTree = ""; };
@@ -267,7 +267,7 @@
C438C7D52981216200BF3EF9 /* LaunchWidgetBundle.swift */,
C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */,
C438C7D92981216200BF3EF9 /* LaunchWidget.swift */,
- C438C7E92981260D00BF3EF9 /* CountdownView.swift */,
+ C438C7E92981260D00BF3EF9 /* SingleCountdownView.swift */,
C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */,
C438C7DC2981216300BF3EF9 /* Assets.xcassets */,
C438C7DE2981216300BF3EF9 /* Info.plist */,
@@ -553,7 +553,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- C438C7EB2981266F00BF3EF9 /* CountdownView.swift in Sources */,
+ C438C7EB2981266F00BF3EF9 /* SingleCountdownView.swift in Sources */,
C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */,
C438C8172982BE9C00BF3EF9 /* Model+Extensions.swift in Sources */,
C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */,
diff --git a/LeCountdown/AppDelegate.swift b/LeCountdown/AppDelegate.swift
index ee3f404..e222119 100644
--- a/LeCountdown/AppDelegate.swift
+++ b/LeCountdown/AppDelegate.swift
@@ -29,7 +29,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
print("willPresent notification")
completionHandler([.banner, .sound])
- AppEnvironment.sun.endCountdown(countdownId: notification.request.identifier)
+ AppEnvironment.sun.endCountdown(countdownId: notification.request.identifier, cancel: false)
}
diff --git a/LeCountdown/CountdownScheduler.swift b/LeCountdown/CountdownScheduler.swift
index c525d8d..6ad0cab 100644
--- a/LeCountdown/CountdownScheduler.swift
+++ b/LeCountdown/CountdownScheduler.swift
@@ -19,7 +19,7 @@ class CountdownScheduler {
func cancelCurrentNotifications(countdown: Countdown) {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [countdown.stringId])
- AppEnvironment.sun.endCountdown(countdownId: countdown.stringId)
+ AppEnvironment.sun.endCountdown(countdownId: countdown.stringId, cancel: false)
}
fileprivate func _scheduleCountdownNotification(countdown: Countdown, handler: @escaping (Result) -> Void) {
@@ -87,9 +87,11 @@ class AppEnvironment : ObservableObject {
}
}
- func endCountdown(countdownId: String) {
+ func endCountdown(countdownId: String, cancel: Bool) {
DispatchQueue.main.async {
- self._recordActivityIfPossible(countdownId: countdownId)
+ if !cancel {
+ self._recordActivity(countdownId: countdownId)
+ }
self.notificationDates.removeValue(forKey: countdownId)
}
}
@@ -98,12 +100,12 @@ class AppEnvironment : ObservableObject {
let now = Date()
for (key, value) in self.notificationDates {
if value.end < now {
- self.endCountdown(countdownId: key)
+ self.endCountdown(countdownId: key, cancel: false)
}
}
}
- fileprivate func _recordActivityIfPossible(countdownId: String) {
+ fileprivate func _recordActivity(countdownId: String) {
let context = PersistenceController.shared.container.viewContext
if let countdown = context.object(stringId: countdownId) as? Countdown,
let dateInterval = self.notificationDates[countdownId] {