mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-29 16:43:33 +01:00
Compare commits
4 Commits
3cd04e60dc
...
e0a4f71953
| Author | SHA1 | Date | |
|---|---|---|---|
| e0a4f71953 | |||
| 1190e2d079 | |||
| 9d63c33fa7 | |||
| 6c2c365a69 |
2
.github/workflows/release-apk.yml
vendored
2
.github/workflows/release-apk.yml
vendored
@ -60,7 +60,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: subosito/flutter-action@v2
|
- uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
flutter-version: 3.50.0
|
flutter-version: 3.50.1
|
||||||
channel: stable
|
channel: stable
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
|
|||||||
@ -115,6 +115,7 @@ repos:
|
|||||||
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
||||||
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
||||||
- sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays
|
- sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays
|
||||||
|
- kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit
|
||||||
- rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
|
- rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
|
||||||
- claude-agent-sdk==0.2.184
|
- claude-agent-sdk==0.2.184
|
||||||
- httpx==0.28.1
|
- httpx==0.28.1
|
||||||
|
|||||||
@ -22,6 +22,11 @@ mixin LogMealLoggedMixin<T extends StatefulWidget>
|
|||||||
/// The rows under the action row, oldest first.
|
/// The rows under the action row, oldest first.
|
||||||
List<LoggedMeal> loggedRows = const [];
|
List<LoggedMeal> loggedRows = const [];
|
||||||
|
|
||||||
|
/// The latest open-or-resume chain. Tests await it instead of guessing how
|
||||||
|
/// long real file I/O takes (a fixed sleep flaked under load).
|
||||||
|
@visibleForTesting
|
||||||
|
Future<void> openChain = Future<void>.value();
|
||||||
|
|
||||||
/// Replaces the rows with [meals]: a new log retires the previous ones.
|
/// Replaces the rows with [meals]: a new log retires the previous ones.
|
||||||
void showLogged(List<LoggedMeal> meals) {
|
void showLogged(List<LoggedMeal> meals) {
|
||||||
if (mounted) setState(() => loggedRows = meals);
|
if (mounted) setState(() => loggedRows = meals);
|
||||||
@ -57,12 +62,15 @@ mixin LogMealLoggedMixin<T extends StatefulWidget>
|
|||||||
// single-flight, so calling super too would let the auto-log run before
|
// single-flight, so calling super too would let the auto-log run before
|
||||||
// the pull finished). Pause still pushes through the sync mixin.
|
// the pull finished). Pause still pushes through the sync mixin.
|
||||||
if (state == AppLifecycleState.resumed) {
|
if (state == AppLifecycleState.resumed) {
|
||||||
unawaited(onOpenedOrResumed());
|
startOpenChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.didChangeAppLifecycleState(state);
|
super.didChangeAppLifecycleState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Starts [onOpenedOrResumed] and keeps its future in [openChain].
|
||||||
|
void startOpenChain() => openChain = onOpenedOrResumed();
|
||||||
|
|
||||||
/// What a fresh open or a resume does: show the screen from the local log,
|
/// What a fresh open or a resume does: show the screen from the local log,
|
||||||
/// pull what other devices logged, then auto-log what is still due.
|
/// pull what other devices logged, then auto-log what is still due.
|
||||||
Future<void> onOpenedOrResumed() async {
|
Future<void> onOpenedOrResumed() async {
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class _LogMealScreenState extends State<LogMealScreen>
|
|||||||
unawaited(_onDescChanged());
|
unawaited(_onDescChanged());
|
||||||
// Health first, so a device that stalled earlier says so before a tick.
|
// Health first, so a device that stalled earlier says so before a tick.
|
||||||
unawaited(refreshSyncHealth());
|
unawaited(refreshSyncHealth());
|
||||||
unawaited(onOpenedOrResumed());
|
startOpenChain();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import 'package:diet_guard_app/widgets/meal_schedule_editor.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:sync_settings_ui/sync_settings_ui.dart';
|
import 'package:sync_settings_ui/sync_settings_ui.dart';
|
||||||
@ -241,6 +242,10 @@ class _SettingsScreenState extends State<SettingsScreen>
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Align(alignment: Alignment.centerLeft, child: _status),
|
Align(alignment: Alignment.centerLeft, child: _status),
|
||||||
],
|
],
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
const Divider(),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
const Align(alignment: Alignment.centerLeft, child: KuhyCredit()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -542,10 +542,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: health
|
name: health
|
||||||
sha256: "8dd9625c9c26379a5753ad24c33af1d3dc5ce1f36f19c03e17c676c2f8fdbb80"
|
sha256: "683d15fdde49a942bacce871faf3090bda3c1f5dad995725337aeb1dfd348e6d"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "13.3.2"
|
version: "14.0.0"
|
||||||
hooks:
|
hooks:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -682,6 +682,15 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.12.0"
|
version: "4.12.0"
|
||||||
|
kuhy_credit:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "kuhy_credit/flutter"
|
||||||
|
ref: "kuhy-credit-v0.3.0"
|
||||||
|
resolved-ref: c3946412729991bf1e9c3b6a5cc55dbe80419fc0
|
||||||
|
url: "https://github.com/kuhyx/utils"
|
||||||
|
source: git
|
||||||
|
version: "0.3.0"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -2,7 +2,7 @@ name: diet_guard_app
|
|||||||
description: "Companion phone app for diet_guard: log meals on the go."
|
description: "Companion phone app for diet_guard: log meals on the go."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 1.0.186+1
|
version: 1.0.190+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.12.2
|
sdk: ^3.12.2
|
||||||
@ -48,11 +48,16 @@ dependencies:
|
|||||||
url: https://github.com/kuhyx/utils
|
url: https://github.com/kuhyx/utils
|
||||||
ref: google_account_token-v0.1.0
|
ref: google_account_token-v0.1.0
|
||||||
path: google_account_token
|
path: google_account_token
|
||||||
health: 13.3.2
|
health: 14.0.0
|
||||||
http: 1.6.0
|
http: 1.6.0
|
||||||
idb_shim: 2.11.3
|
idb_shim: 2.11.3
|
||||||
# Camera/gallery photo as transient input to Claude (never stored or synced).
|
# Camera/gallery photo as transient input to Claude (never stored or synced).
|
||||||
image_picker: 1.2.4
|
image_picker: 1.2.4
|
||||||
|
kuhy_credit:
|
||||||
|
git:
|
||||||
|
url: https://github.com/kuhyx/utils
|
||||||
|
ref: kuhy-credit-v0.3.0
|
||||||
|
path: kuhy_credit/flutter
|
||||||
material_ui: 1.11.1
|
material_ui: 1.11.1
|
||||||
path: 1.9.1
|
path: 1.9.1
|
||||||
path_provider: 2.1.6
|
path_provider: 2.1.6
|
||||||
|
|||||||
@ -65,13 +65,20 @@ void main() {
|
|||||||
// GitHubMirrorScreen loads its settings via a fire-and-forget Future in
|
// GitHubMirrorScreen loads its settings via a fire-and-forget Future in
|
||||||
// initState that Flutter's frame scheduler does not track -- same pitfall
|
// initState that Flutter's frame scheduler does not track -- same pitfall
|
||||||
// as HistoryScreen/LogMealScreen.
|
// as HistoryScreen/LogMealScreen.
|
||||||
Future<void> settle(WidgetTester tester) async {
|
// [until]: keep pumping (max 5 s) until it is found -- a sync tick's real
|
||||||
|
// I/O outlasts the fixed 200 ms on a loaded machine.
|
||||||
|
Future<void> settle(WidgetTester tester, {Finder? until}) async {
|
||||||
tester.view.physicalSize = const Size(800, 1400);
|
tester.view.physicalSize = const Size(800, 1400);
|
||||||
tester.view.devicePixelRatio = 1.0;
|
tester.view.devicePixelRatio = 1.0;
|
||||||
addTearDown(tester.view.resetPhysicalSize);
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
addTearDown(tester.view.resetDevicePixelRatio);
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
final deadline = DateTime.now().add(const Duration(seconds: 5));
|
||||||
await tester.pumpAndSettle();
|
do {
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
} while (until != null &&
|
||||||
|
until.evaluate().isEmpty &&
|
||||||
|
DateTime.now().isBefore(deadline));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drains the device flow's real `Future.delayed` poll (GitHubDeviceAuth
|
/// Drains the device flow's real `Future.delayed` poll (GitHubDeviceAuth
|
||||||
@ -167,7 +174,7 @@ void main() {
|
|||||||
await settle(tester);
|
await settle(tester);
|
||||||
|
|
||||||
await tester.tap(controlByLabel('Sync now'));
|
await tester.tap(controlByLabel('Sync now'));
|
||||||
await settle(tester);
|
await settle(tester, until: cueLabelled('Synced.'));
|
||||||
|
|
||||||
expect(cueLabelled('Synced.'), findsOneWidget);
|
expect(cueLabelled('Synced.'), findsOneWidget);
|
||||||
});
|
});
|
||||||
@ -197,7 +204,7 @@ void main() {
|
|||||||
await settle(tester);
|
await settle(tester);
|
||||||
|
|
||||||
await tester.tap(controlByLabel('Sync now'));
|
await tester.tap(controlByLabel('Sync now'));
|
||||||
await settle(tester);
|
await settle(tester, until: cueLabelled('Synced.'));
|
||||||
|
|
||||||
expect(cueLabelled('Synced.'), findsOneWidget);
|
expect(cueLabelled('Synced.'), findsOneWidget);
|
||||||
final status = await SyncHealth.read();
|
final status = await SyncHealth.read();
|
||||||
@ -228,7 +235,7 @@ void main() {
|
|||||||
await settle(tester);
|
await settle(tester);
|
||||||
|
|
||||||
await tester.tap(controlByLabel('Sync now'));
|
await tester.tap(controlByLabel('Sync now'));
|
||||||
await settle(tester);
|
await settle(tester, until: cueOfKind(CueKind.error));
|
||||||
|
|
||||||
expect(cueOfKind(CueKind.error), findsOneWidget);
|
expect(cueOfKind(CueKind.error), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -47,7 +47,7 @@ void main() {
|
|||||||
|
|
||||||
Future<void> open(WidgetTester tester) async {
|
Future<void> open(WidgetTester tester) async {
|
||||||
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
|
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
|
||||||
await settle(tester);
|
await settleOpen(tester);
|
||||||
}
|
}
|
||||||
|
|
||||||
testWidgets('opening in due mode logs the due dishes with no tap', (
|
testWidgets('opening in due mode logs the due dishes with no tap', (
|
||||||
@ -72,7 +72,11 @@ void main() {
|
|||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
await open(tester);
|
await open(tester);
|
||||||
await tester.tap(byIconLabel('Undo').first);
|
await tester.tap(byIconLabel('Undo').first);
|
||||||
await settle(tester);
|
await settleUntil(
|
||||||
|
tester,
|
||||||
|
() async =>
|
||||||
|
(await LogStorageService.instance.todayEntries()).length == 1,
|
||||||
|
);
|
||||||
expect(find.byIcon(Icons.restaurant), findsOneWidget);
|
expect(find.byIcon(Icons.restaurant), findsOneWidget);
|
||||||
var live = await LogStorageService.instance.todayEntries();
|
var live = await LogStorageService.instance.todayEntries();
|
||||||
expect(live.map((e) => e.desc), ['Danie 2']);
|
expect(live.map((e) => e.desc), ['Danie 2']);
|
||||||
@ -130,7 +134,7 @@ void main() {
|
|||||||
(state as WidgetsBindingObserver).didChangeAppLifecycleState(
|
(state as WidgetsBindingObserver).didChangeAppLifecycleState(
|
||||||
AppLifecycleState.resumed,
|
AppLifecycleState.resumed,
|
||||||
);
|
);
|
||||||
await settle(tester);
|
await settleOpen(tester);
|
||||||
|
|
||||||
final entries = await LogStorageService.instance.todayEntries();
|
final entries = await LogStorageService.instance.todayEntries();
|
||||||
expect(entries.map((e) => e.desc), ['Danie 1', 'Danie 2']);
|
expect(entries.map((e) => e.desc), ['Danie 1', 'Danie 2']);
|
||||||
|
|||||||
@ -38,7 +38,7 @@ void main() {
|
|||||||
|
|
||||||
Future<void> open(WidgetTester tester) async {
|
Future<void> open(WidgetTester tester) async {
|
||||||
await tester.pumpWidget(MaterialApp(home: LogMealScreen(relay: relay)));
|
await tester.pumpWidget(MaterialApp(home: LogMealScreen(relay: relay)));
|
||||||
await settle(tester);
|
await settleOpen(tester);
|
||||||
}
|
}
|
||||||
|
|
||||||
testWidgets('the request id is a ULID and the mode follows due mode', (
|
testWidgets('the request id is a ULID and the mode follows due mode', (
|
||||||
@ -75,7 +75,12 @@ void main() {
|
|||||||
await settle(tester);
|
await settle(tester);
|
||||||
|
|
||||||
await tester.tap(controlByLabel('Log meal'));
|
await tester.tap(controlByLabel('Log meal'));
|
||||||
await settle(tester);
|
await settleUntil(
|
||||||
|
tester,
|
||||||
|
() async =>
|
||||||
|
relay.cancelled.isNotEmpty &&
|
||||||
|
byIconLabel('Ask Claude').evaluate().isNotEmpty,
|
||||||
|
);
|
||||||
|
|
||||||
expect(relay.cancelled, [relay.sent.single.requestId]);
|
expect(relay.cancelled, [relay.sent.single.requestId]);
|
||||||
expect(byIconLabel('Ask Claude'), findsOneWidget);
|
expect(byIconLabel('Ask Claude'), findsOneWidget);
|
||||||
@ -88,7 +93,12 @@ void main() {
|
|||||||
_claudeEntry(claudeEntryId(relay.sent.single.requestId)),
|
_claudeEntry(claudeEntryId(relay.sent.single.requestId)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await settle(tester);
|
await settleUntil(
|
||||||
|
tester,
|
||||||
|
() async =>
|
||||||
|
(await LogStorageService.instance.todayEntries()).length ==
|
||||||
|
(claimed ? 2 : 1),
|
||||||
|
);
|
||||||
final live = await LogStorageService.instance.todayEntries();
|
final live = await LogStorageService.instance.todayEntries();
|
||||||
expect(live, hasLength(claimed ? 2 : 1));
|
expect(live, hasLength(claimed ? 2 : 1));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,6 +4,8 @@ library;
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:diet_guard_app/screens/log_meal_due_mixin.dart';
|
import 'package:diet_guard_app/screens/log_meal_due_mixin.dart';
|
||||||
|
import 'package:diet_guard_app/screens/log_meal_logged_mixin.dart';
|
||||||
|
import 'package:diet_guard_app/screens/log_meal_screen.dart';
|
||||||
import 'package:diet_guard_app/services/app_settings_service.dart';
|
import 'package:diet_guard_app/services/app_settings_service.dart';
|
||||||
import 'package:diet_guard_app/services/budget_history_service.dart';
|
import 'package:diet_guard_app/services/budget_history_service.dart';
|
||||||
import 'package:diet_guard_app/services/document_store_io.dart';
|
import 'package:diet_guard_app/services/document_store_io.dart';
|
||||||
@ -51,3 +53,28 @@ Future<void> settle(WidgetTester tester) async {
|
|||||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Waits for the screen's open-or-resume chain (sync, slots, catering
|
||||||
|
/// auto-log) to finish, then [settle]s.
|
||||||
|
Future<void> settleOpen(WidgetTester tester) async {
|
||||||
|
final state = tester.state(find.byType(LogMealScreen));
|
||||||
|
await (state as LogMealLoggedMixin).openChain;
|
||||||
|
await settle(tester);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [settle]s, then keeps pumping until [done] holds or [timeout] passes.
|
||||||
|
///
|
||||||
|
/// For chains a tap starts and nothing exposes: real file I/O outlasts the
|
||||||
|
/// fixed sleep in [settle] when the machine is loaded.
|
||||||
|
Future<void> settleUntil(
|
||||||
|
WidgetTester tester,
|
||||||
|
Future<bool> Function() done, {
|
||||||
|
Duration timeout = const Duration(seconds: 5),
|
||||||
|
}) async {
|
||||||
|
final deadline = DateTime.now().add(timeout);
|
||||||
|
await settle(tester);
|
||||||
|
while (!await done() && DateTime.now().isBefore(deadline)) {
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import 'package:diet_guard_app/services/firebase_backend.dart';
|
|||||||
import 'package:diet_guard_app/services/foodbank_service.dart';
|
import 'package:diet_guard_app/services/foodbank_service.dart';
|
||||||
import 'package:diet_guard_app/services/log_storage_service.dart';
|
import 'package:diet_guard_app/services/log_storage_service.dart';
|
||||||
import 'package:diet_guard_app/services/meal_schedule_service.dart';
|
import 'package:diet_guard_app/services/meal_schedule_service.dart';
|
||||||
|
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
@ -224,4 +225,17 @@ void main() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
testWidgets('shows the KuhyCredit logo at the bottom', (tester) async {
|
||||||
|
await tester.runAsync(() async {
|
||||||
|
await tester.pumpWidget(const MaterialApp(home: SettingsScreen()));
|
||||||
|
await settle(tester);
|
||||||
|
|
||||||
|
// Scroll to the bottom where KuhyCredit is placed.
|
||||||
|
await tester.ensureVisible(find.byType(KuhyCredit, skipOffstage: false));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(KuhyCredit, skipOffstage: false), findsOneWidget);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,7 @@ from diet_guard._gatelock_core import _GateState
|
|||||||
from diet_guard._gatelock_credit import arm_credit_watch
|
from diet_guard._gatelock_credit import arm_credit_watch
|
||||||
from diet_guard._gatelock_groups import GateWidgetsGroup
|
from diet_guard._gatelock_groups import GateWidgetsGroup
|
||||||
from diet_guard._gatelock_lockfile import acquire_gate_lock, release_gate_lock
|
from diet_guard._gatelock_lockfile import acquire_gate_lock, release_gate_lock
|
||||||
|
from diet_guard._gatelock_logo import place_logo
|
||||||
from diet_guard._gatelock_peerpull import arm_peer_pull
|
from diet_guard._gatelock_peerpull import arm_peer_pull
|
||||||
from diet_guard._gatelock_ui import GateCallbacks, make_vars
|
from diet_guard._gatelock_ui import GateCallbacks, make_vars
|
||||||
from diet_guard._hold import watch_hold
|
from diet_guard._hold import watch_hold
|
||||||
@ -127,8 +128,7 @@ class MealGate(_GateCalendar):
|
|||||||
self.root = GateRoot()
|
self.root = GateRoot()
|
||||||
self.root.on_callback_error = self.on_callback_error
|
self.root.on_callback_error = self.on_callback_error
|
||||||
self.root.title("Diet Gate") # OS-level app name: the one kept noun
|
self.root.title("Diet Gate") # OS-level app name: the one kept noun
|
||||||
# No colour overrides: LockConfig's defaults are the design-system palette
|
# No colour overrides: LockConfig defaults are the palette (one drifted).
|
||||||
# and _gatelock_ui reads them too (an override drifted once).
|
|
||||||
config = LockConfig(
|
config = LockConfig(
|
||||||
mode="soft" if demo_mode else "hard",
|
mode="soft" if demo_mode else "hard",
|
||||||
app_name="diet_guard",
|
app_name="diet_guard",
|
||||||
@ -172,9 +172,9 @@ class MealGate(_GateCalendar):
|
|||||||
monitor the user is actually looking at.
|
monitor the user is actually looking at.
|
||||||
"""
|
"""
|
||||||
widgets = self._build_tabs(parent, self._callbacks)
|
widgets = self._build_tabs(parent, self._callbacks)
|
||||||
|
place_logo(parent)
|
||||||
self._widgets.add(widgets, surface.output_name)
|
self._widgets.add(widgets, surface.output_name)
|
||||||
# An output coming back mid-lock gets its bindings too; tk's bind
|
# A returning output gets its bindings; re-wiring the rest is a no-op.
|
||||||
# replaces rather than stacks, so re-wiring the others is a no-op.
|
|
||||||
self._wire_events()
|
self._wire_events()
|
||||||
|
|
||||||
def teardown_surface(self, surface: SurfaceInfo) -> None:
|
def teardown_surface(self, surface: SurfaceInfo) -> None:
|
||||||
|
|||||||
27
diet_guard/_gatelock_logo.py
Normal file
27
diet_guard/_gatelock_logo.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""The kuhy logo in a corner of each gate surface (shared ``kuhy_credit``).
|
||||||
|
|
||||||
|
Uses the Tk widget from kuhy_credit (kuhy-credit-v0.3.0). A click opens the
|
||||||
|
credit panel; the site opens only on a further click, so the lock cannot be
|
||||||
|
escaped by accident. This module imports tkinter and builds widgets, so it
|
||||||
|
belongs in ``_GATE_TK_MODULES`` (see ``_gatelock_layout``).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from kuhy_credit.tk import KuhyCredit
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
__all__ = ["place_logo"]
|
||||||
|
|
||||||
|
_MARGIN = 16
|
||||||
|
|
||||||
|
|
||||||
|
def place_logo(parent: tk.Misc) -> KuhyCredit:
|
||||||
|
"""Overlay the logo on ``parent``'s bottom-right corner."""
|
||||||
|
credit = KuhyCredit(parent, theme="dark")
|
||||||
|
credit.place(relx=1, rely=1, x=-_MARGIN, y=-_MARGIN, anchor="se")
|
||||||
|
return credit
|
||||||
@ -202,6 +202,8 @@ def fake_tk() -> Iterator[None]:
|
|||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
for module in _GATE_TK_MODULES:
|
for module in _GATE_TK_MODULES:
|
||||||
stack.enter_context(patch.object(module, "tk", _FAKE_TK))
|
stack.enter_context(patch.object(module, "tk", _FAKE_TK))
|
||||||
|
# The logo is a real Canvas subclass; it cannot take a fake parent.
|
||||||
|
stack.enter_context(patch.object(_gatelock, "place_logo"))
|
||||||
stack.enter_context(patch.object(_gatelock_calendar, "ttk", _FAKE_TTK))
|
stack.enter_context(patch.object(_gatelock_calendar, "ttk", _FAKE_TTK))
|
||||||
stack.enter_context(patch.object(_gatelock_calendar_ui, "ttk", _FAKE_TTK))
|
stack.enter_context(patch.object(_gatelock_calendar_ui, "ttk", _FAKE_TTK))
|
||||||
# The schedule row's HH:MM spinboxes are ttk widgets; left real, they
|
# The schedule row's HH:MM spinboxes are ttk widgets; left real, they
|
||||||
|
|||||||
35
diet_guard/tests/test_gatelock_logo.py
Normal file
35
diet_guard/tests/test_gatelock_logo.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"""The kuhy logo sits in the bottom-right corner of every gate surface."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tkinter as tk
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from kuhy_credit.tk import KuhyCredit
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from diet_guard._gatelock_logo import place_logo
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pytest_xvfb import Xvfb
|
||||||
|
|
||||||
|
|
||||||
|
def test_place_logo_anchors_bottom_right(xvfb: Xvfb | None) -> None:
|
||||||
|
# Real Tk, so only ever on pytest-xvfb's private display -- never the user's.
|
||||||
|
if xvfb is None:
|
||||||
|
pytest.skip("needs pytest-xvfb's private display")
|
||||||
|
assert os.environ["DISPLAY"] == f":{xvfb.display}"
|
||||||
|
root = tk.Tk()
|
||||||
|
try:
|
||||||
|
root.withdraw()
|
||||||
|
frame = tk.Frame(root)
|
||||||
|
credit = place_logo(frame)
|
||||||
|
assert isinstance(credit, KuhyCredit)
|
||||||
|
assert credit.master is frame
|
||||||
|
info = credit.place_info()
|
||||||
|
assert info["anchor"] == "se"
|
||||||
|
assert (info["relx"], info["rely"]) == ("1", "1")
|
||||||
|
assert (info["x"], info["y"]) == ("-16", "-16")
|
||||||
|
finally:
|
||||||
|
root.destroy()
|
||||||
@ -7,9 +7,10 @@ dependencies = [
|
|||||||
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock",
|
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock",
|
||||||
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync",
|
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync",
|
||||||
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays",
|
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays",
|
||||||
|
"kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit",
|
||||||
"holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds",
|
"holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds",
|
||||||
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays",
|
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays",
|
||||||
"claude-agent-sdk==0.2.185",
|
"claude-agent-sdk==0.2.187",
|
||||||
"defusedxml==0.7.1",
|
"defusedxml==0.7.1",
|
||||||
"httpx==0.28.1",
|
"httpx==0.28.1",
|
||||||
"requests==2.34.2",
|
"requests==2.34.2",
|
||||||
@ -25,7 +26,7 @@ dependencies = [
|
|||||||
mcp = ["mcp==2.3.0"]
|
mcp = ["mcp==2.3.0"]
|
||||||
# Test-only: the property tests (test_claude_log.py) need it; same pin as
|
# Test-only: the property tests (test_claude_log.py) need it; same pin as
|
||||||
# requirements.txt.
|
# requirements.txt.
|
||||||
dev = ["hypothesis==6.170.15"]
|
dev = ["hypothesis==6.170.17"]
|
||||||
|
|
||||||
# Without this, setuptools' flat-layout auto-discovery treats the Flutter
|
# Without this, setuptools' flat-layout auto-discovery treats the Flutter
|
||||||
# app/ directory as a second top-level package and refuses to build.
|
# app/ directory as a second top-level package and refuses to build.
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
# Diet Guard — runtime + development dependencies
|
# Diet Guard — runtime + development dependencies
|
||||||
# Runtime: tkinter/json/hmac/fcntl (stdlib) plus gatelock and requests below.
|
# Runtime: tkinter/json/hmac/fcntl (stdlib) plus gatelock and requests below.
|
||||||
bandit==1.9.4
|
bandit==1.9.4
|
||||||
claude-agent-sdk==0.2.185
|
claude-agent-sdk==0.2.187
|
||||||
codespell==2.4.3
|
codespell==2.4.3
|
||||||
coverage==7.17.3
|
coverage==7.17.4
|
||||||
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
||||||
defusedxml==0.7.1
|
defusedxml==0.7.1
|
||||||
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
||||||
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock
|
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock
|
||||||
holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds
|
holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds
|
||||||
httpx==0.28.1
|
httpx==0.28.1
|
||||||
hypothesis==6.170.15
|
hypothesis==6.170.17
|
||||||
|
kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit
|
||||||
mcp==2.3.0
|
mcp==2.3.0
|
||||||
mypy==2.4.1
|
mypy==2.4.1
|
||||||
pre-commit==4.7.0
|
pre-commit==4.7.0
|
||||||
pydantic==2.14.3
|
pydantic==2.14.4
|
||||||
pylint==4.1.4
|
pylint==4.1.4
|
||||||
pytest==9.2.0
|
pytest==9.2.0
|
||||||
pytest-cov==7.1.0
|
pytest-cov==7.1.0
|
||||||
@ -24,5 +25,5 @@ pytest-xdist==3.8.0
|
|||||||
pytest-xvfb==3.1.1
|
pytest-xvfb==3.1.1
|
||||||
requests==2.34.2
|
requests==2.34.2
|
||||||
rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
|
rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
|
||||||
ruff==0.17.5
|
ruff==0.17.6
|
||||||
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays
|
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user