78 lines
2.5 KiB
Swift
78 lines
2.5 KiB
Swift
import UIKit
|
|
import SwiftUI
|
|
|
|
// MARK: - Quick action identifiers
|
|
|
|
enum QuickAction: String {
|
|
case addTask = "com.kutesir.kisanical.addTask"
|
|
case today = "com.kutesir.kisanical.today"
|
|
case calendar = "com.kutesir.kisanical.calendar"
|
|
case workout = "com.kutesir.kisanical.workout"
|
|
case next3 = "com.kutesir.kisanical.next3days"
|
|
}
|
|
|
|
// MARK: - Singleton observable handler
|
|
|
|
final class ShortcutHandler: ObservableObject {
|
|
static let shared = ShortcutHandler()
|
|
@Published var pending: QuickAction?
|
|
|
|
private init() {}
|
|
|
|
func handle(_ type: String) {
|
|
guard let action = QuickAction(rawValue: type) else { return }
|
|
DispatchQueue.main.async { self.pending = action }
|
|
}
|
|
|
|
func consume() {
|
|
pending = nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Shortcut registration
|
|
|
|
extension ShortcutHandler {
|
|
static func registerShortcuts() {
|
|
let ud = UserDefaults.standard
|
|
let showWorkout = ud.object(forKey: "showWorkoutTab") as? Bool ?? true
|
|
|
|
var items: [UIApplicationShortcutItem] = [
|
|
UIApplicationShortcutItem(
|
|
type: QuickAction.today.rawValue,
|
|
localizedTitle: "Tasks",
|
|
localizedSubtitle: "Open your task list",
|
|
icon: UIApplicationShortcutIcon(systemImageName: "checkmark.circle.fill")
|
|
),
|
|
UIApplicationShortcutItem(
|
|
type: QuickAction.addTask.rawValue,
|
|
localizedTitle: "Add Task",
|
|
localizedSubtitle: "Create a new reminder",
|
|
icon: UIApplicationShortcutIcon(systemImageName: "plus.circle.fill")
|
|
),
|
|
UIApplicationShortcutItem(
|
|
type: QuickAction.calendar.rawValue,
|
|
localizedTitle: "Calendar",
|
|
localizedSubtitle: "Month view",
|
|
icon: UIApplicationShortcutIcon(systemImageName: "calendar")
|
|
),
|
|
UIApplicationShortcutItem(
|
|
type: QuickAction.next3.rawValue,
|
|
localizedTitle: "Next 3 Days",
|
|
localizedSubtitle: "Upcoming tasks",
|
|
icon: UIApplicationShortcutIcon(systemImageName: "calendar.badge.clock")
|
|
),
|
|
]
|
|
|
|
if showWorkout {
|
|
items.append(UIApplicationShortcutItem(
|
|
type: QuickAction.workout.rawValue,
|
|
localizedTitle: "Workout",
|
|
localizedSubtitle: "Today's session",
|
|
icon: UIApplicationShortcutIcon(systemImageName: "dumbbell.fill")
|
|
))
|
|
}
|
|
|
|
UIApplication.shared.shortcutItems = items
|
|
}
|
|
}
|