minor improvements

main
Laurent 3 years ago
parent 1cba6e5c88
commit cd34b42882
  1. 6
      LeCountdown.xcodeproj/project.pbxproj
  2. 8
      LeCountdown/Intent/StartTimerIntent.swift
  3. 2
      LeCountdown/Intent/TimerIdentifierAppEntity.swift
  4. 5
      LeCountdown/Model/NSManagedContext+Extensions.swift
  5. 1
      LeCountdown/TimerRouter.swift
  6. 5
      LeCountdown/Utils/AppError.swift

@ -42,6 +42,8 @@
C4286EA32A1503320070D075 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */; };
C4286EA42A1503330070D075 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */; };
C4286EA62A150A7E0070D075 /* TimePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286EA52A150A7E0070D075 /* TimePickerView.swift */; };
C4286EAD2A1775390070D075 /* AppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E952A14EC4E0070D075 /* AppError.swift */; };
C4286EAE2A17753A0070D075 /* AppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E952A14EC4E0070D075 /* AppError.swift */; };
C42E96FB29E59E72005B1B8C /* BackgroundBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42E96FA29E59E72005B1B8C /* BackgroundBlurView.swift */; };
C42E96FD29E5B06D005B1B8C /* ActivityCalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42E96FC29E5B06D005B1B8C /* ActivityCalendarView.swift */; };
C42E96FE29E5B5CD005B1B8C /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B6429A3C37D00CB4FBA /* Filter.swift */; };
@ -748,6 +750,7 @@
C438C80A2981DE1A00BF3EF9 /* Utils */ = {
isa = PBXGroup;
children = (
C4286E952A14EC4E0070D075 /* AppError.swift */,
C4BA2AFC299A3A3700CB4FBA /* AppleMusicPlayer.swift */,
C4556F7029E40DCF00DEB40B /* Codable+Extensions.swift */,
C4742B5629840F6400D5D950 /* CoolPic.swift */,
@ -763,7 +766,6 @@
C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */,
C473C33B29ACEC4F0056B38A /* Tip.swift */,
C4BA2B7829A65C1400CB4FBA /* UIDevice+Extensions.swift */,
C4286E952A14EC4E0070D075 /* AppError.swift */,
);
path = Utils;
sourceTree = "<group>";
@ -1360,6 +1362,7 @@
C47C933729F01B7A00C780E2 /* Codable+Extensions.swift in Sources */,
C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */,
C4BA2B16299BE6A000CB4FBA /* IntervalGroup+CoreDataClass.swift in Sources */,
C4286EAE2A17753A0070D075 /* AppError.swift in Sources */,
C4F8B18B298AC288005C86A5 /* Record+CoreDataClass.swift in Sources */,
C4F8B195298AC288005C86A5 /* Activity+CoreDataClass.swift in Sources */,
C4BA2B22299BE82E00CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift in Sources */,
@ -1454,6 +1457,7 @@
C4A16DC929D311C800143D5E /* Extensions.swift in Sources */,
C473C2F529A8DAF30056B38A /* PropertyWrappers.swift in Sources */,
C473C2F029A8CFFC0056B38A /* TimerRouter.swift in Sources */,
C4286EAD2A1775390070D075 /* AppError.swift in Sources */,
C438C800298130E900BF3EF9 /* IntentDataProvider.swift in Sources */,
C473C33A29ACDBD70056B38A /* TipView.swift in Sources */,
);

@ -36,16 +36,16 @@ struct StartTimerIntent: AudioStartingIntent {
if let abstractTimer = IntentDataProvider.main.timer(id: timerIdentifier.id) {
do {
let _ = try await TimerRouter.performAction(timer: abstractTimer)
print("perform() success !")
_ = try await TimerRouter.performAction(timer: abstractTimer)
return .result(value: 1)
} catch {
Logger.error(error)
// let dialog: IntentDialog = "\(error.localizedDescription)"
return .result(value: 0)
throw error
}
} else {
throw AppError.timerNotFound(id: timerIdentifier.id)
}
return .result(value: 0)
}
func timerEntities() -> [TimerIdentifierAppEntity] {

@ -10,7 +10,7 @@ import AppIntents
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
struct TimerIdentifierAppEntity: AppEntity {
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Timer Identifier")
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Timer Identifier")
struct TimerIdentifierAppEntityQuery: EntityQuery {
func entities(for identifiers: [TimerIdentifierAppEntity.ID]) async throws -> [TimerIdentifierAppEntity] {

@ -12,7 +12,7 @@ extension NSManagedObjectContext {
func object<T: NSManagedObject>(stringId: String) -> T? {
guard let url = URL(string: stringId) else { return nil }
guard let objectId = PersistenceController.shared.container.persistentStoreCoordinator.managedObjectID(forURIRepresentation: url) else { return nil }
guard let objectId: NSManagedObjectID = PersistenceController.shared.container.persistentStoreCoordinator.managedObjectID(forURIRepresentation: url) else { return nil }
return self.object(with: objectId) as? T
}
@ -47,9 +47,6 @@ extension NSManagedObjectContext {
}
}
// public func fetch<T>(_ request: NSFetchRequest<T>) throws -> [T] where T : NSFetchRequestResult
func fetch<T>(entityName: String, predicate: NSPredicate? = nil, sortDescriptor: NSSortDescriptor? = nil) -> [T] where T : NSFetchRequestResult {
let request = NSFetchRequest<T>(entityName: entityName)
request.predicate = predicate

@ -48,6 +48,7 @@ class TimerRouter {
fileprivate static func _launchCountdown(_ countdown: Countdown, handler: @escaping (Result<Void, Error>) -> Void) {
UNUserNotificationCenter.current().getNotificationSettings { settings in
DispatchQueue.main.async {
CountdownScheduler.master.scheduleIfPossible(countdown: countdown) { result in
switch result {

@ -10,11 +10,14 @@ import Foundation
enum AppError: LocalizedError {
case defaultError(error: Error)
case timerNotFound(id: String)
var errorDescription: String? {
switch self {
case .defaultError(let error):
return error.localizedDescription
case .timerNotFound(let id):
return "Timer not found: \(id)"
}
}
@ -22,6 +25,8 @@ enum AppError: LocalizedError {
switch self {
case .defaultError(let error):
return error.localizedDescription
case .timerNotFound:
return "Timer not found"
}
}

Loading…
Cancel
Save