mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
- Group the large widget into running/active sections, show up to nine sessions, and use the last human prompt as the subtitle. - Show compact status icons plus web-style relative times, right-aligned. - Mirror the per-install push key into the protected App Group container so the Live Activity extension and NSE can decrypt while the data-protection Keychain is unavailable on the Lock Screen. - Redesign the Lock Screen card and Dynamic Island compact/expanded/minimal states; Live Activities are now opt-in and recovered activities are ended when disabled. - Rename the app and widget display name to Happy Coding; bump the local build to 10. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
53 lines
2.0 KiB
Swift
53 lines
2.0 KiB
Swift
import Foundation
|
|
|
|
/// App Group mirror of the per-install push key used by Live Activities.
|
|
///
|
|
/// The widget extension renders Live Activity content while the device is
|
|
/// locked, where the data-protection Keychain can be unavailable
|
|
/// (`errSecNotAvailable`, -25291). The key is therefore mirrored into the
|
|
/// same protected App Group container as the widget snapshot; the container
|
|
/// is shared only with HAPI's own extensions and the file is protected with
|
|
/// `completeUntilFirstUserAuthentication`.
|
|
public enum LiveActivityKeyStore {
|
|
public static let fileName = "live-activity-key"
|
|
public static let keyByteCount = 32
|
|
|
|
public static func load() -> Data? {
|
|
guard let directory = WidgetSnapshotStore.containerURL() else { return nil }
|
|
return load(from: directory)
|
|
}
|
|
|
|
public static func load(from directory: URL) -> Data? {
|
|
let url = directory.appendingPathComponent(fileName, isDirectory: false)
|
|
guard let data = try? Data(contentsOf: url), data.count == keyByteCount else {
|
|
return nil
|
|
}
|
|
return data
|
|
}
|
|
|
|
@discardableResult
|
|
public static func save(_ key: Data) -> Bool {
|
|
guard let directory = WidgetSnapshotStore.containerURL() else { return false }
|
|
return save(key, to: directory)
|
|
}
|
|
|
|
@discardableResult
|
|
public static func save(_ key: Data, to directory: URL) -> Bool {
|
|
guard key.count == keyByteCount else { return false }
|
|
do {
|
|
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
|
let url = directory.appendingPathComponent(fileName, isDirectory: false)
|
|
try key.write(to: url, options: .atomic)
|
|
#if os(iOS) && !targetEnvironment(macCatalyst)
|
|
try? FileManager.default.setAttributes(
|
|
[.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication],
|
|
ofItemAtPath: url.path
|
|
)
|
|
#endif
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
}
|