Fixes countdown refresh

release
Laurent 3 years ago
parent ec1a7327b8
commit a85d23d18e
  1. 2
      LaunchIntents/IntentHandler.swift
  2. 28
      LaunchWidget/LaunchWidget.intentdefinition
  3. 21
      LaunchWidget/LaunchWidget.swift
  4. 10
      LaunchWidgetExtension.entitlements
  5. 18
      LeCountdown.xcodeproj/project.pbxproj
  6. 8
      LeCountdown/Info.plist
  7. 24
      LeCountdown/Model/CoreDataRequests.swift
  8. 15
      LeCountdown/Model/Model+Extensions.swift
  9. 20
      LeCountdown/Views/ContentView.swift
  10. 5
      LeCountdown/Widget/IntentDataProvider.swift

@ -43,8 +43,6 @@ class IntentHandler: INExtension, SelectCountdownIntentHandling {
}
let cp = CountdownProperties(identifier: countdown.objectID.uriRepresentation().absoluteString, display: displayName)
cp.name = countdown.activity?.name
cp.duration = NSNumber(value: countdown.duration)
return cp
}

@ -182,34 +182,6 @@
<key>INTypePropertyType</key>
<string>SpeakableString</string>
</dict>
<dict>
<key>INTypePropertyDisplayName</key>
<string>Name</string>
<key>INTypePropertyDisplayNameID</key>
<string>1g3sqi</string>
<key>INTypePropertyDisplayPriority</key>
<integer>5</integer>
<key>INTypePropertyName</key>
<string>name</string>
<key>INTypePropertyTag</key>
<integer>100</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDisplayName</key>
<string>Duration</string>
<key>INTypePropertyDisplayNameID</key>
<string>NjMwkO</string>
<key>INTypePropertyDisplayPriority</key>
<integer>6</integer>
<key>INTypePropertyName</key>
<string>duration</string>
<key>INTypePropertyTag</key>
<integer>102</integer>
<key>INTypePropertyType</key>
<string>Decimal</string>
</dict>
</array>
</dict>
</array>

@ -16,15 +16,26 @@ struct Provider: IntentTimelineProvider {
func getSnapshot(for configuration: SelectCountdownIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
guard let countdown = configuration.countdown,
let identifier = countdown.identifier,
let duration = countdown.duration else {
guard let cp = configuration.countdown,
let identifier = cp.identifier,
let countdown = IntentDataProvider.main.countdown(id: identifier) else {
print("WARNING PLACEHOLDER!")
completion(placeholder(in: context))
let entry = SimpleEntry(id: "",
name: "Not found",
duration: 0.0,
date: Date(),
configuration: configuration)
completion(entry)
return
}
let entry = SimpleEntry(id: identifier, name: countdown.name, duration: duration.doubleValue, date: Date(), configuration: configuration)
let entry = SimpleEntry(id: identifier,
name: countdown.name,
duration: countdown.duration,
date: Date(),
configuration: configuration)
completion(entry)
}

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.staxriver.countdown</string>
</array>
</dict>
</plist>

@ -45,6 +45,12 @@
C438C80D2982847300BF3EF9 /* CoreDataRequests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C80C2982847300BF3EF9 /* CoreDataRequests.swift */; };
C438C80F29828B8600BF3EF9 /* RecordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C80E29828B8600BF3EF9 /* RecordsView.swift */; };
C438C81129829EAF00BF3EF9 /* PropertyWrappers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */; };
C438C8152982BD9000BF3EF9 /* IntentDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7FE2981300500BF3EF9 /* IntentDataProvider.swift */; };
C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */; };
C438C8172982BE9C00BF3EF9 /* Model+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C806298195E600BF3EF9 /* Model+Extensions.swift */; };
C438C8182982BFC100BF3EF9 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DC8297AE73D003FAB80 /* Persistence.swift */; };
C438C8192982BFDB00BF3EF9 /* NSManagedContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */; };
C438C81A2982BFF100BF3EF9 /* NSManagedContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -133,6 +139,7 @@
C438C80C2982847300BF3EF9 /* CoreDataRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataRequests.swift; sourceTree = "<group>"; };
C438C80E29828B8600BF3EF9 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = "<group>"; };
C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappers.swift; sourceTree = "<group>"; };
C438C8122982BAA100BF3EF9 /* LaunchWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LaunchWidgetExtension.entitlements; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -180,6 +187,7 @@
C4060DB3297AE73B003FAB80 = {
isa = PBXGroup;
children = (
C438C8122982BAA100BF3EF9 /* LaunchWidgetExtension.entitlements */,
C4060DBE297AE73B003FAB80 /* LeCountdown */,
C4060DD5297AE73D003FAB80 /* LeCountdownTests */,
C4060DDF297AE73D003FAB80 /* LeCountdownUITests */,
@ -549,10 +557,15 @@
files = (
C438C7EB2981266F00BF3EF9 /* CountdownView.swift in Sources */,
C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */,
C438C8172982BE9C00BF3EF9 /* Model+Extensions.swift in Sources */,
C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */,
C438C8152982BD9000BF3EF9 /* IntentDataProvider.swift in Sources */,
C438C7DF2981216300BF3EF9 /* LaunchWidget.intentdefinition in Sources */,
C438C7E82981255D00BF3EF9 /* TimeInterval+Extensions.swift in Sources */,
C438C7D82981216200BF3EF9 /* LaunchWidgetLiveActivity.swift in Sources */,
C438C8192982BFDB00BF3EF9 /* NSManagedContext+Extensions.swift in Sources */,
C438C7DA2981216200BF3EF9 /* LaunchWidget.swift in Sources */,
C438C8182982BFC100BF3EF9 /* Persistence.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -563,6 +576,7 @@
C438C7F529812BB200BF3EF9 /* IntentHandler.swift in Sources */,
C438C80529813FB400BF3EF9 /* TimeInterval+Extensions.swift in Sources */,
C438C802298132B900BF3EF9 /* LeCountdown.xcdatamodeld in Sources */,
C438C81A2982BFF100BF3EF9 /* NSManagedContext+Extensions.swift in Sources */,
C438C8012981327600BF3EF9 /* Persistence.swift in Sources */,
C438C7FD29812BF700BF3EF9 /* LaunchWidget.intentdefinition in Sources */,
C438C800298130E900BF3EF9 /* IntentDataProvider.swift in Sources */,
@ -723,7 +737,6 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = LeCountdown/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
@ -755,7 +768,6 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = LeCountdown/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
@ -854,6 +866,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = LaunchWidgetExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 526E96RFNP;
@ -881,6 +894,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = LaunchWidgetExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 526E96RFNP;

@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>SelectCountdownIntent</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
@ -9,9 +13,5 @@
<key>UISceneConfigurations</key>
<dict/>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>SelectCountdownIntent</string>
</array>
</dict>
</plist>

@ -6,23 +6,37 @@
//
import Foundation
import CoreData
enum CountdownException : Error {
case entityNameNotFound
}
class CoreDataRequests {
static func getOrCreateActivity(name: String) -> Activity {
static func findBy<T : NSManagedObject, V>(property: String, value: V) throws -> T? {
let context = PersistenceController.shared.container.viewContext
let request = Activity.fetchRequest()
request.predicate = NSPredicate(format: "name like %@", name)
if let entityName = T.entity().name {
let fetchRequest = NSFetchRequest<T>(entityName: entityName)
fetchRequest.predicate = NSPredicate(format: "%K == %@", argumentArray: [property, value])
let results = try context.fetch(fetchRequest)
return results.first
} else {
throw CountdownException.entityNameNotFound
}
}
static func getOrCreateActivity(name: String) -> Activity {
do {
let results = try context.fetch(request)
if let activity = results.first {
if let activity: Activity = try findBy(property: #keyPath(Activity.name), value: name) {
return activity
}
} catch {
print("error = \(error)")
}
let context = PersistenceController.shared.container.viewContext
let activity = Activity(context: context)
activity.name = name
return activity

@ -10,20 +10,9 @@ import SwiftUI
extension Countdown {
var endDate: Date? {
return AppEnvironment.sun.notificationDates[self.stringId]?.end
}
var isLive: Bool {
return endDate != nil
}
var colorForStatus: Color {
if isLive {
return Color(red: 0.9, green: 1.0, blue: 0.95)
} else {
return Color(red: 0.9, green: 0.95, blue: 1.0)
}
var name: String? {
return self.activity?.name
}
}

@ -160,6 +160,26 @@ struct ContentView: View {
}
fileprivate extension Countdown {
var endDate: Date? {
return AppEnvironment.sun.notificationDates[self.stringId]?.end
}
var isLive: Bool {
return endDate != nil
}
var colorForStatus: Color {
if isLive {
return Color(red: 0.9, green: 1.0, blue: 0.95)
} else {
return Color(red: 0.9, green: 0.95, blue: 1.0)
}
}
}
//private let itemFormatter: DateFormatter = {
// let formatter = DateFormatter()
// formatter.dateStyle = .short

@ -18,4 +18,9 @@ class IntentDataProvider {
return try context.fetch(request)
}
func countdown(id: String) -> Countdown? {
let context = PersistenceController.shared.container.viewContext
return context.object(stringId: id) as? Countdown
}
}

Loading…
Cancel
Save