feat: home screen quick actions (long press app icon)

Adds four UIApplicationShortcutItems registered dynamically at launch:
  • Add Task — opens the add-task sheet immediately, any tab
  • Today — switches to the Today tab
  • Calendar — switches to the Calendar tab
  • Workout — switches to the Workout tab (only registered if the
    workout tab is enabled in settings; re-registers when the setting changes)

Cold-launch and foreground-activation paths both handled via AppDelegate.
ShortcutHandler singleton bridges UIKit callbacks to SwiftUI via @Published.
This commit is contained in:
kutesir
2026-05-30 02:38:15 +03:00
parent e0e4f709b6
commit cab5c4ef05
4 changed files with 116 additions and 3 deletions

View File

@@ -0,0 +1,70 @@
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"
}
// 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.addTask.rawValue,
localizedTitle: "Add Task",
localizedSubtitle: "Create a new reminder",
icon: UIApplicationShortcutIcon(systemImageName: "plus.circle.fill")
),
UIApplicationShortcutItem(
type: QuickAction.today.rawValue,
localizedTitle: "Today",
localizedSubtitle: "Tasks & agenda",
icon: UIApplicationShortcutIcon(systemImageName: "checkmark.circle")
),
UIApplicationShortcutItem(
type: QuickAction.calendar.rawValue,
localizedTitle: "Calendar",
localizedSubtitle: "Month view",
icon: UIApplicationShortcutIcon(systemImageName: "calendar")
),
]
if showWorkout {
items.append(UIApplicationShortcutItem(
type: QuickAction.workout.rawValue,
localizedTitle: "Workout",
localizedSubtitle: "Today's session",
icon: UIApplicationShortcutIcon(systemImageName: "dumbbell.fill")
))
}
UIApplication.shared.shortcutItems = items
}
}