Compare commits
2
Commits
6c0b6e3068
...
74606e5046
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74606e5046 | ||
|
|
517a4e4fdc |
@@ -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) {
|
||||
|
||||
@@ -111,9 +111,52 @@ enum PickerSelfTest {
|
||||
|
||||
print("PICKER-SELFTEST PASS rect=\(format(got.rect))")
|
||||
fflush(stdout)
|
||||
|
||||
runRegionPersistPhase()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
/// Phase 2: writes a known region under `CaptureRegion.defaultsKey`, reloads it through
|
||||
/// `AppModel.loadPersistedRegion()` (the same path init uses), then restores whatever
|
||||
/// value was stored before so a real picked region is untouched.
|
||||
private static func runRegionPersistPhase() {
|
||||
let defaults = UserDefaults.standard
|
||||
let previous = defaults.data(forKey: CaptureRegion.defaultsKey)
|
||||
|
||||
let known = CaptureRegion(
|
||||
displayID: CGMainDisplayID(),
|
||||
rect: CGRect(x: 10, y: 10, width: 100, height: 100),
|
||||
capturedScale: 2.0
|
||||
)
|
||||
var failure: String?
|
||||
if let encoded = try? JSONEncoder().encode(known) {
|
||||
defaults.set(encoded, forKey: CaptureRegion.defaultsKey)
|
||||
if let loaded = AppModel.loadPersistedRegion() {
|
||||
if loaded.rect != known.rect {
|
||||
failure = "expected=\(format(known.rect)) got=\(format(loaded.rect))"
|
||||
}
|
||||
} else {
|
||||
failure = "loadPersistedRegion returned nil"
|
||||
}
|
||||
} else {
|
||||
failure = "could not encode CaptureRegion"
|
||||
}
|
||||
|
||||
if let previous {
|
||||
defaults.set(previous, forKey: CaptureRegion.defaultsKey)
|
||||
} else {
|
||||
defaults.removeObject(forKey: CaptureRegion.defaultsKey)
|
||||
}
|
||||
|
||||
if let failure {
|
||||
print("REGION-PERSIST FAIL \(failure)")
|
||||
fflush(stdout)
|
||||
exit(1)
|
||||
}
|
||||
print("REGION-PERSIST PASS")
|
||||
fflush(stdout)
|
||||
}
|
||||
|
||||
private static func interpolate(_ step: Int) -> NSPoint {
|
||||
let t = CGFloat(step) / CGFloat(dragSteps)
|
||||
return NSPoint(
|
||||
|
||||
Reference in New Issue
Block a user