stahl/ios/Shell/Lock.swift
Markus Zoppelt 54b44f7c1e feat(ios): Face ID, 120 Hz, ticks and icon variants
- With the lock on in Settings, the app opens on the vault, and Face ID (or
  the passcode) turns it open with a knock. Coming back from the background
  asks again; a cancelled prompt leaves the door with a way to retry.
- 120 Hz on ProMotion iPhones, which hold an app to 60 Hz unless it asks.
- A swipe in from the left edge goes back.
- A light tick for each day a finger crosses on a chart, each slice of the
  donut, and the point where a pull refreshes; a knock when it does.
- Dark and tinted app icons, rendered from the door shader with the rest.
2026-11-08 08:47:11 +01:00

44 lines
1.5 KiB
Swift

// Face ID, Touch ID or the passcode before the vault opens, when Settings asks for it.
import LocalAuthentication
import UIKit
enum Lock {
private static let key = "lock-the-vault"
/// Whether the person asked for the lock, in Stahl's Settings.
static var enabled: Bool {
get { UserDefaults.standard.bool(forKey: key) }
set { UserDefaults.standard.set(newValue, forKey: key) }
}
/// Whether this device can lock anything: it has a passcode, at least.
static var available: Bool {
LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
}
/// Whether the lock is on and can work: without a passcode, a lock would only lock the
/// person out.
static var active: Bool { enabled && available }
/// What the device calls its lock.
static var name: String {
let context = LAContext()
_ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
switch context.biometryType {
case .faceID: return "Face ID"
case .touchID: return "Touch ID"
case .opticID: return "Optic ID"
default: return "Passcode"
}
}
/// Ask, with the passcode as the way in when Face ID doesn't recognise the face.
static func ask(then: @escaping (Bool) -> Void) {
LAContext().evaluatePolicy(
.deviceOwnerAuthentication, localizedReason: "Open the vault"
) { opened, _ in
DispatchQueue.main.async { then(opened) }
}
}
}