Fix ring health persistence and page acknowledgements

This commit is contained in:
James Babcock committed 2026-09-17 20:23:15 -07:00
1 parent 22c851a6b9
commit c595cb4b6e
10 files changed
+472 -92

No files matched your search

+13 -18
View File
@@ -42,27 +42,13 @@ class FileBackend implements HealthStorageBackend {
}
append(name: string, text: string): void {
try {
// `File.fromPath` creates the file when it is missing, and
// `appendTextSync` is the durable single-call append - deliberately not
// read-modify-write, which would put every record already on disk at
// risk on every new one.
File.fromPath(pathFor(name)).appendTextSync(text, (error) => {
console.warn(`health store append failed (${name})`, error);
});
} catch (error) {
console.warn(`health store append threw (${name})`, error);
}
// NativeScript reports IO failures through callbacks as well as throws.
// Propagate both so the caller retains the unconsumed ring batch.
checkedFileOperation((onError) => File.fromPath(pathFor(name)).appendTextSync(text, onError));
}
write(name: string, text: string): void {
try {
File.fromPath(pathFor(name)).writeTextSync(text, (error) => {
console.warn(`health store write failed (${name})`, error);
});
} catch (error) {
console.warn(`health store write threw (${name})`, error);
}
checkedFileOperation((onError) => File.fromPath(pathFor(name)).writeTextSync(text, onError));
}
list(): string[] {
@@ -77,6 +63,15 @@ class FileBackend implements HealthStorageBackend {
}
}
/** Convert a synchronous NativeScript error callback into a thrown failure. */
export function checkedFileOperation(operation: (onError: (error: any) => void) => void): void {
let failure: Error | undefined;
operation((error) => {
failure = error instanceof Error ? error : new Error(error?.message ?? String(error));
});
if (failure) throw failure;
}
let store: HealthStore | null = null;
/** The app's one health store. Created on first use. */