fix: load persisted capture region at launch; REGION-PERSIST selftest phase
Ben-reported: picker opened on every activation. AppModel.init set region = nil and never read UserDefaults back; saving worked, every launch forgot it. init now loads via loadPersistedRegion() (decode + isStillValid). Selftest phase 2 writes a known region, reloads through the same path, asserts the rect, restores the user's stored value. Coordinator ran it: PICKER-SELFTEST PASS + REGION-PERSIST PASS, 90/90 tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,7 @@ public final class AppModel {
|
||||
captures: [],
|
||||
pdfFileName: nil
|
||||
)
|
||||
self.region = nil
|
||||
self.region = Self.loadPersistedRegion()
|
||||
self.screenRecordingGranted = ScreenCapturer.isScreenRecordingGranted
|
||||
// Seeded from FolderSettings.resolve() via resolvedAppSupportPaths — never .standard().
|
||||
let folders = FolderSettings.resolve()
|
||||
@@ -237,6 +237,14 @@ public final class AppModel {
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
|
||||
static func loadPersistedRegion() -> CaptureRegion? {
|
||||
guard let data = UserDefaults.standard.data(forKey: CaptureRegion.defaultsKey),
|
||||
let decoded = try? JSONDecoder().decode(CaptureRegion.self, from: data),
|
||||
decoded.isStillValid
|
||||
else { return nil }
|
||||
return decoded
|
||||
}
|
||||
|
||||
private func persistRegion(_ picked: CaptureRegion) {
|
||||
replaceRegion(picked)
|
||||
if let encoded = try? JSONEncoder().encode(picked) {
|
||||
|
||||
Reference in New Issue
Block a user