From 2fd8c4e5531a0a4571d17d13263fb782bb83f60b Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Sat, 7 Nov 2026 12:33:31 +0800 Subject: [PATCH] feat(ios): make the session-detail widget configurable - Replace the automatic Focus card with Session Detail configured by a session picker (AppIntentConfiguration + AppEntity). - Multiple Session Detail widgets can be added and stacked in a Smart Stack, each bound to a different session. - Keep the automatic fallback when no session is selected or it vanished. - Bump the local build to 31. via [HAPI](https://hapi.run) Co-Authored-By: HAPI Co-Authored-By: Claude Code --- ios/Hapi.xcodeproj/project.pbxproj | 12 ++-- ios/HapiWidgets/HapiHomeWidget.swift | 94 +++++++++++++++++++++++++-- ios/HapiWidgets/Localizable.xcstrings | 34 ++++++++++ 3 files changed, 129 insertions(+), 11 deletions(-) diff --git a/ios/Hapi.xcodeproj/project.pbxproj b/ios/Hapi.xcodeproj/project.pbxproj index 8d169974..f285753a 100644 --- a/ios/Hapi.xcodeproj/project.pbxproj +++ b/ios/Hapi.xcodeproj/project.pbxproj @@ -481,7 +481,7 @@ CODE_SIGN_ENTITLEMENTS = Hapi/Hapi.entitlements; "CODE_SIGN_ENTITLEMENTS[sdk=macosx*]" = "Hapi/Hapi-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = NO; DEVELOPMENT_TEAM = X75CUV458P; ENABLE_PREVIEWS = YES; @@ -516,7 +516,7 @@ CODE_SIGN_ENTITLEMENTS = Hapi/Hapi.entitlements; "CODE_SIGN_ENTITLEMENTS[sdk=macosx*]" = "Hapi/Hapi-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = NO; DEVELOPMENT_TEAM = X75CUV458P; ENABLE_PREVIEWS = YES; @@ -549,7 +549,7 @@ CODE_SIGN_ENTITLEMENTS = HapiNotificationService/HapiNotificationService.entitlements; "CODE_SIGN_ENTITLEMENTS[sdk=macosx*]" = "HapiNotificationService/HapiNotificationService-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = NO; DEVELOPMENT_TEAM = X75CUV458P; GENERATE_INFOPLIST_FILE = YES; @@ -578,7 +578,7 @@ CODE_SIGN_ENTITLEMENTS = HapiNotificationService/HapiNotificationService.entitlements; "CODE_SIGN_ENTITLEMENTS[sdk=macosx*]" = "HapiNotificationService/HapiNotificationService-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = NO; DEVELOPMENT_TEAM = X75CUV458P; GENERATE_INFOPLIST_FILE = YES; @@ -607,7 +607,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_ENTITLEMENTS = HapiWidgets/HapiWidgets.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = X75CUV458P; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HapiWidgets/Info.plist; @@ -637,7 +637,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_ENTITLEMENTS = HapiWidgets/HapiWidgets.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = X75CUV458P; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HapiWidgets/Info.plist; diff --git a/ios/HapiWidgets/HapiHomeWidget.swift b/ios/HapiWidgets/HapiHomeWidget.swift index 25dd33a5..b1a8be5b 100644 --- a/ios/HapiWidgets/HapiHomeWidget.swift +++ b/ios/HapiWidgets/HapiHomeWidget.swift @@ -1,3 +1,4 @@ +import AppIntents import HapiProtocol import SwiftUI import UIKit @@ -830,20 +831,103 @@ private struct HapiModeWidgetView: View { /// One-session detail card: the task, the latest assistant result and progress. struct HapiFocusWidget: Widget { var body: some WidgetConfiguration { - StaticConfiguration(kind: WidgetSnapshotStore.focusWidgetKind, provider: HapiWidgetProvider()) { entry in + AppIntentConfiguration( + kind: WidgetSnapshotStore.focusWidgetKind, + intent: FocusConfigurationIntent.self, + provider: FocusProvider() + ) { entry in HapiFocusWidgetView(entry: entry) } - .configurationDisplayName("Focus") - .description("Task and latest result for one session.") + .configurationDisplayName("Session Detail") + .description("Task and latest result for a chosen session.") .supportedFamilies([.systemLarge]) } } +struct HapiFocusEntry: TimelineEntry { + let date: Date + let snapshot: WidgetSnapshot + let sessionId: String? +} + +struct FocusProvider: AppIntentTimelineProvider { + func placeholder(in context: Context) -> HapiFocusEntry { + HapiFocusEntry(date: Date(), snapshot: .empty, sessionId: nil) + } + + func snapshot(for configuration: FocusConfigurationIntent, in context: Context) async -> HapiFocusEntry { + HapiFocusEntry( + date: Date(), + snapshot: WidgetSnapshotStore.load() ?? .empty, + sessionId: configuration.session?.id + ) + } + + func timeline(for configuration: FocusConfigurationIntent, in context: Context) async -> Timeline { + let now = Date() + let entry = HapiFocusEntry( + date: now, + snapshot: WidgetSnapshotStore.load() ?? .empty, + sessionId: configuration.session?.id + ) + return Timeline(entries: [entry], policy: .after(now.addingTimeInterval(5 * 60))) + } +} + +struct FocusConfigurationIntent: WidgetConfigurationIntent { + static var title: LocalizedStringResource = "Session Detail" + static var description = IntentDescription("Pick a session for the detail card.") + + @Parameter(title: "Session") + var session: SessionEntity? + + static var parameterSummary: some ParameterSummary { + Summary("Show \(\.$session)") + } +} + +struct SessionEntity: AppEntity { + let id: String + let title: String + let project: String + + static var typeDisplayRepresentation: TypeDisplayRepresentation = "Session" + static var defaultQuery = SessionEntityQuery() + + var displayRepresentation: DisplayRepresentation { + DisplayRepresentation( + title: "\(title)", + subtitle: project.isEmpty ? nil : "\(project)" + ) + } +} + +struct SessionEntityQuery: EntityQuery { + func entities(for identifiers: [String]) async throws -> [SessionEntity] { + let wanted = Set(identifiers) + return allEntities().filter { wanted.contains($0.id) } + } + + func suggestedEntities() async throws -> [SessionEntity] { + allEntities() + } + + private func allEntities() -> [SessionEntity] { + (WidgetSnapshotStore.load()?.sessions ?? []).map { + SessionEntity(id: $0.id, title: $0.title, project: $0.project) + } + } +} + private struct HapiFocusWidgetView: View { - let entry: HapiWidgetEntry + let entry: HapiFocusEntry private var session: WidgetSnapshot.Session? { - entry.snapshot.sessions.first { $0.isUnread == true && $0.status != .working } + if let selected = entry.sessionId, + let match = entry.snapshot.sessions.first(where: { $0.id == selected }) { + return match + } + return entry.snapshot.sessions.first { $0.isUnread == true && $0.status != .working } ?? entry.snapshot.sessions.first { $0.status == .working } ?? entry.snapshot.sessions.first { $0.isUnread == true } ?? entry.snapshot.sessions.first diff --git a/ios/HapiWidgets/Localizable.xcstrings b/ios/HapiWidgets/Localizable.xcstrings index a0493583..8977a517 100644 --- a/ios/HapiWidgets/Localizable.xcstrings +++ b/ios/HapiWidgets/Localizable.xcstrings @@ -374,6 +374,40 @@ } } } + }, + "Session Detail" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Детали сеанса" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "会话详情" + } + } + } + }, + "Session" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Сеанс" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "会话" + } + } + } } }, "version" : "1.0"