Update SecureStorageSample

This commit is contained in:
Matt Bruce 2026-01-16 16:56:36 -06:00
parent 3139270a86
commit e025e435bc

View File

@ -80,10 +80,10 @@ struct PlatformSyncDemo: View {
Button(action: testPlatformError) { Button(action: testPlatformError) {
HStack { HStack {
Image(systemName: "exclamationmark.triangle") Image(systemName: "exclamationmark.triangle")
Text("Test Platform Restriction") Text("Test Current Availability")
} }
} }
.foregroundStyle(.orange) .foregroundStyle(Color.Status.warning)
.disabled(isLoading) .disabled(isLoading)
} }
@ -98,8 +98,8 @@ struct PlatformSyncDemo: View {
Section { Section {
Text(statusMessage) Text(statusMessage)
.font(.caption) .font(.caption)
.foregroundStyle(statusMessage.contains("Error") ? .red : .foregroundStyle(statusMessage.contains("Error") ? Color.Status.error :
statusMessage.contains("") ? .orange : .green) statusMessage.contains("") ? Color.Status.warning : Color.Status.success)
} }
} }
@ -114,6 +114,7 @@ struct PlatformSyncDemo: View {
LabeledContent("Platform", value: selectedPlatform.displayName) LabeledContent("Platform", value: selectedPlatform.displayName)
LabeledContent("Sync", value: selectedSync.displayName) LabeledContent("Sync", value: selectedSync.displayName)
LabeledContent("Max Auto-Sync Size", value: "50 KB") LabeledContent("Max Auto-Sync Size", value: "50 KB")
LabeledContent("Key Name", value: StorageKeys.SyncableSettingKey().name)
} }
Section("Watch Notes") { Section("Watch Notes") {
@ -182,12 +183,17 @@ struct PlatformSyncDemo: View {
private func testPlatformError() { private func testPlatformError() {
isLoading = true isLoading = true
Task { Task {
let key = StorageKeys.WatchVibrationKey()
do { do {
let key = StorageKeys.SyncableSettingKey(
availability: selectedPlatform,
syncPolicy: selectedSync
)
_ = try await StorageRouter.shared.get(key) _ = try await StorageRouter.shared.get(key)
statusMessage = "⚠ Accessed successfully (running on Watch?)" statusMessage = "✓ Current availability allows iPhone access"
} catch StorageError.watchOnlyKeyAccessedOnPhone(let name) { } catch StorageError.watchOnlyKeyAccessedOnPhone(let name) {
statusMessage = "⚠ Expected Error: Key '\(name)' is watchOnly, accessed from iPhone" statusMessage = "⚠ Expected Error: Key '\(name)' is watchOnly, accessed from iPhone"
} catch StorageError.notFound {
statusMessage = "⚠ No stored value. Availability allows access."
} catch { } catch {
statusMessage = "Error: \(error.localizedDescription)" statusMessage = "Error: \(error.localizedDescription)"
} }