Repository Public
1// App Intents (Shortcuts, Spotlight actions, Siri): only actions that reveal nothing about the vault.2// No item title, username or secret is ever donated to the system by these intents.3import AppIntents4import SharedVaultKit56struct OpenVaultIntent: AppIntent {7 static let title: LocalizedStringResource = "Open SP Vault"8 static let description = IntentDescription("Opens SP Vault. The vault stays locked until you unlock it.")9 static let openAppWhenRun = true10 func perform() async throws -> some IntentResult { .result() }11}1213struct LockVaultIntent: AppIntent {14 static let title: LocalizedStringResource = "Lock SP Vault"15 static let description = IntentDescription("Locks the vault and wipes its keys from memory.")16 @MainActor17 func perform() async throws -> some IntentResult {18 AppModel.shared.lock()19 return .result()20 }21}2223struct GeneratePasswordIntent: AppIntent {24 static let title: LocalizedStringResource = "Generate Password"25 static let description = IntentDescription("Makes a random password on this device. Nothing is stored and nothing is sent.")2627 @Parameter(title: "Length", default: 24, inclusiveRange: (8, 64))28 var length: Int2930 @Parameter(title: "Symbols", default: true)31 var symbols: Bool3233 func perform() async throws -> some IntentResult & ReturnsValue<String> {34 .result(value: try SPV1.generatePassword(PasswordOptions(length: length, symbols: symbols)))35 }36}3738struct VaultShortcuts: AppShortcutsProvider {39 static var appShortcuts: [AppShortcut] {40 AppShortcut(intent: OpenVaultIntent(), phrases: ["Open \(.applicationName)"], shortTitle: "Open SP Vault", systemImageName: "lock.square")41 AppShortcut(intent: LockVaultIntent(), phrases: ["Lock \(.applicationName)"], shortTitle: "Lock SP Vault", systemImageName: "lock")42 AppShortcut(intent: GeneratePasswordIntent(), phrases: ["Generate a password with \(.applicationName)"], shortTitle: "Generate Password", systemImageName: "dice")43 }44}45