release
Laurent 3 years ago
parent 038107cd80
commit c274a8f97a
  1. 2
      LaunchWidget/LaunchWidget.intentdefinition
  2. 16
      LaunchWidget/LaunchWidget.swift
  3. 13
      LaunchWidget/SingleCountdownView.swift
  4. 8
      LeCountdown.xcodeproj/project.pbxproj
  5. 2
      LeCountdown/AppDelegate.swift
  6. 12
      LeCountdown/CountdownScheduler.swift

@ -78,7 +78,7 @@
</dict> </dict>
<dict> <dict>
<key>INIntentParameterArraySizeSize</key> <key>INIntentParameterArraySizeSize</key>
<integer>2</integer> <integer>1</integer>
<key>INIntentParameterArraySizeSizeClass</key> <key>INIntentParameterArraySizeSizeClass</key>
<string>AccessoryRectangular</string> <string>AccessoryRectangular</string>
</dict> </dict>

@ -48,13 +48,7 @@ struct Provider: IntentTimelineProvider {
} }
struct SimpleEntry: TimelineEntry { struct SimpleEntry: TimelineEntry {
let countdowns: [Countdown] let countdowns: [Countdown]
// let id: String
// let name: String?
// let duration: Double
let date: Date let date: Date
let configuration: SelectCountdownIntent let configuration: SelectCountdownIntent
} }
@ -64,7 +58,7 @@ struct CountdownSimpleWidgetView: View {
let countdown: Countdown let countdown: Countdown
var body: some View { var body: some View {
CountdownView(countdown: countdown) SingleCountdownView(countdown: countdown)
.widgetURL(countdown.url) .widgetURL(countdown.url)
} }
@ -75,14 +69,14 @@ struct CountdownMultiWidgetView: View {
let countdowns: [Countdown] let countdowns: [Countdown]
var body: some View { var body: some View {
CountdownMultiView(countdowns: countdowns) MultiCountdownView(countdowns: countdowns)
} }
} }
struct VoidView : View { struct VoidView : View {
var body: some View { var body: some View {
Text("Nothing here") Text("Configure me!")
} }
} }
@ -102,7 +96,7 @@ struct LaunchWidgetEntryView : View {
VoidView() VoidView()
} }
default: default:
CountdownMultiView(countdowns: entry.countdowns) MultiCountdownView(countdowns: entry.countdowns)
// case .systemMedium: GameStatusWithLastTurnResult(gameStatus) // case .systemMedium: GameStatusWithLastTurnResult(gameStatus)
// case .systemLarge: GameStatusWithStatistics(gameStatus) // case .systemLarge: GameStatusWithStatistics(gameStatus)
@ -127,7 +121,7 @@ struct LaunchWidget: Widget {
} }
.configurationDisplayName("Launch Widget") .configurationDisplayName("Launch Widget")
.description("Select and launch your countdowns") .description("Select and launch your countdowns")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryRectangular]) .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryRectangular, .accessoryCircular])
} }
} }

@ -9,7 +9,7 @@ import SwiftUI
import WidgetKit import WidgetKit
import CoreData import CoreData
struct CountdownView: View { struct SingleCountdownView: View {
@Environment(\.widgetFamily) var family: WidgetFamily @Environment(\.widgetFamily) var family: WidgetFamily
@ -21,6 +21,7 @@ struct CountdownView: View {
Text(countdown.duration.minuteSecond) Text(countdown.duration.minuteSecond)
} }
.font(self.font) .font(self.font)
.widgetURL(countdown.url)
} }
private var font: Font { private var font: Font {
@ -34,7 +35,7 @@ struct CountdownView: View {
} }
struct CountdownMultiView: View { struct MultiCountdownView: View {
@Environment(\.widgetFamily) var family: WidgetFamily @Environment(\.widgetFamily) var family: WidgetFamily
@ -42,6 +43,9 @@ struct CountdownMultiView: View {
var body: some View { var body: some View {
if countdowns.isEmpty {
VoidView()
} else {
HStack { HStack {
ForEach(countdowns) { countdown in ForEach(countdowns) { countdown in
@ -56,6 +60,7 @@ struct CountdownMultiView: View {
} }
}.frame(maxWidth: .infinity) }.frame(maxWidth: .infinity)
}
} }
@ -73,8 +78,8 @@ struct CountdownMultiView: View {
struct CountdownView_Previews: PreviewProvider { struct CountdownView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
CountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryRectangular)) SingleCountdownView(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)) MultiCountdownView(countdowns: self.countdowns(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .systemMedium))
} }
static func countdowns(context: NSManagedObjectContext) -> [Countdown] { static func countdowns(context: NSManagedObjectContext) -> [Countdown] {

@ -31,7 +31,7 @@
C438C7E02981216300BF3EF9 /* LaunchWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */; }; 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, ); }; }; 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 */; }; 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 */; }; C438C7F229812BB200BF3EF9 /* Intents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C438C7F129812BB200BF3EF9 /* Intents.framework */; };
C438C7F529812BB200BF3EF9 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7F429812BB200BF3EF9 /* IntentHandler.swift */; }; 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, ); }; }; 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 = "<group>"; }; C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = LaunchWidget.intentdefinition; sourceTree = "<group>"; };
C438C7DC2981216300BF3EF9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; C438C7DC2981216300BF3EF9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C438C7DE2981216300BF3EF9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; C438C7DE2981216300BF3EF9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C438C7E92981260D00BF3EF9 /* CountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountdownView.swift; sourceTree = "<group>"; }; C438C7E92981260D00BF3EF9 /* SingleCountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleCountdownView.swift; sourceTree = "<group>"; };
C438C7F029812BB200BF3EF9 /* LaunchIntents.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = LaunchIntents.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 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; }; 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 = "<group>"; }; C438C7F429812BB200BF3EF9 /* IntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentHandler.swift; sourceTree = "<group>"; };
@ -267,7 +267,7 @@
C438C7D52981216200BF3EF9 /* LaunchWidgetBundle.swift */, C438C7D52981216200BF3EF9 /* LaunchWidgetBundle.swift */,
C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */, C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */,
C438C7D92981216200BF3EF9 /* LaunchWidget.swift */, C438C7D92981216200BF3EF9 /* LaunchWidget.swift */,
C438C7E92981260D00BF3EF9 /* CountdownView.swift */, C438C7E92981260D00BF3EF9 /* SingleCountdownView.swift */,
C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */, C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */,
C438C7DC2981216300BF3EF9 /* Assets.xcassets */, C438C7DC2981216300BF3EF9 /* Assets.xcassets */,
C438C7DE2981216300BF3EF9 /* Info.plist */, C438C7DE2981216300BF3EF9 /* Info.plist */,
@ -553,7 +553,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
C438C7EB2981266F00BF3EF9 /* CountdownView.swift in Sources */, C438C7EB2981266F00BF3EF9 /* SingleCountdownView.swift in Sources */,
C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */, C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */,
C438C8172982BE9C00BF3EF9 /* Model+Extensions.swift in Sources */, C438C8172982BE9C00BF3EF9 /* Model+Extensions.swift in Sources */,
C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */, C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */,

@ -29,7 +29,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
print("willPresent notification") print("willPresent notification")
completionHandler([.banner, .sound]) completionHandler([.banner, .sound])
AppEnvironment.sun.endCountdown(countdownId: notification.request.identifier) AppEnvironment.sun.endCountdown(countdownId: notification.request.identifier, cancel: false)
} }

@ -19,7 +19,7 @@ class CountdownScheduler {
func cancelCurrentNotifications(countdown: Countdown) { func cancelCurrentNotifications(countdown: Countdown) {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [countdown.stringId]) 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<Date?, Error>) -> Void) { fileprivate func _scheduleCountdownNotification(countdown: Countdown, handler: @escaping (Result<Date?, Error>) -> Void) {
@ -87,9 +87,11 @@ class AppEnvironment : ObservableObject {
} }
} }
func endCountdown(countdownId: String) { func endCountdown(countdownId: String, cancel: Bool) {
DispatchQueue.main.async { DispatchQueue.main.async {
self._recordActivityIfPossible(countdownId: countdownId) if !cancel {
self._recordActivity(countdownId: countdownId)
}
self.notificationDates.removeValue(forKey: countdownId) self.notificationDates.removeValue(forKey: countdownId)
} }
} }
@ -98,12 +100,12 @@ class AppEnvironment : ObservableObject {
let now = Date() let now = Date()
for (key, value) in self.notificationDates { for (key, value) in self.notificationDates {
if value.end < now { 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 let context = PersistenceController.shared.container.viewContext
if let countdown = context.object(stringId: countdownId) as? Countdown, if let countdown = context.object(stringId: countdownId) as? Countdown,
let dateInterval = self.notificationDates[countdownId] { let dateInterval = self.notificationDates[countdownId] {

Loading…
Cancel
Save