Settings sync between the dashboard and the app

- Dashboard (settingsync.py): the plugins' settings go into a synced
  settings.db, one row per setting (the row id is the setting's key, so the
  phone and the dashboard edit the same row; the later change wins) plus each
  field as the plugin declares it. Fields marked "local" (addresses, paths on
  one machine) and the plugins' on / off stay out. Values set on another
  device are checked as the Settings page does before they're saved; a
  refused one is written back with the dashboard's value.
- App 1.1.7: a Settings page (the gear on every tab) built from those fields,
  synced both ways. Food targets, the cycle, the work day and the body profile
  read the synced values; with a dashboard that doesn't sync settings yet,
  they still come from its Health summaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-10-26 16:30:00 +02:00
parent 98b110dd56
commit 820aca7d92
25 changed files with 606 additions and 41 deletions

View file

@ -7,6 +7,7 @@
// note, source} — imported ones have id "vital:<t>", ones typed here a random id.
import 'dart:math';
import '../app/prefs.dart';
import '../sync/store.dart';
import 'cycle_model.dart' show iso, parseDay, daysBetween, today;
import 'summaries.dart';
@ -27,9 +28,18 @@ const fields = {
};
const fatDayFields = {'weight', 'waist', 'hip', 'neck', 'fat_scale'};
/// The values set on the dashboard (Settings ▸ Health), from its person summary (profileOf).
/// The dashboard's Settings ▸ Health (synced: prefs.dart); until they've come, its person summary (profileOf).
class Profile {
const Profile({this.sex = female, this.birth, this.height});
static Profile of(SyncStore store) {
final p = Prefs(store), s = profileOf(store);
final b = DateTime.tryParse(p.get<String>('health.birth_date', ''));
final h = p.number('health.height', 0).toDouble();
return Profile(sex: p.get<String>('health.sex', s.sex), birth: b == null ? s.birth : DateTime.utc(b.year, b.month, b.day),
height: h > 0 ? h : s.height);
}
final String sex;
final DateTime? birth;
final double? height;