diet-guard/app/lib/main.dart
Krzysztof kuhy Rudnicki c12faa3920
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
app: package the desktop app as the web build, and delete the Linux embedder
Completes the move: `linux/` is gone, replaced by the web build served by the
wrapper in a Chrome `--app` window. The icons and the .desktop installer move
out of `linux/` first -- they are not Flutter scaffolding and are still
needed; the entry now points at the packaged launcher and matches the
`--class=diet_guard_app` the wrapper passes, so the taskbar shows the app's
icon rather than a browser's.

install_arch.sh carries over the three traps each of which produced an
install that looked fine until launched: `dart build cli` rather than
`dart compile exe` (which refuses any package whose dependency graph has
native build hooks), `options=('!strip')` (makepkg would otherwise discard
the AOT snapshot, leaving a binary that runs as the bare Dart VM printing a
usage message), and no browser in `depends` (this machine's policy uninstalls
`chromium` seconds later, failing dependency resolution).

Also adds the frame-cadence instrument the performance claim is measured
with, armed by `--dart-define=DIET_GUARD_FRAME_STATS=1` and read with
`String.fromEnvironment` -- `bool.fromEnvironment` only accepts the literal
`true`, so `=1` would evaluate to false and a whole run would silently
produce no data. It reports frame-to-frame cadence rather than build/raster
durations, since work that fits the budget says nothing about the frame rate
actually achieved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 16:32:24 +02:00

57 lines
2.1 KiB
Dart

/// App entry point: initializes local storage services, registers the
/// background due-slot check, then shows the primary meal-logging screen.
library;
import 'dart:async';
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/background_tasks.dart';
import 'package:diet_guard_app/services/foodbank_service.dart';
import 'package:diet_guard_app/services/frame_stats.dart';
import 'package:diet_guard_app/services/log_storage_service.dart';
import 'package:diet_guard_app/services/notification_service.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await LogStorageService.init();
await AppSettingsService.init();
await FoodBankService.init();
final notifications = await NotificationService.init();
// Deliberately *not* awaited before the first frame: the browser's
// `Notification.requestPermission()` does not complete until the user
// answers the prompt, so awaiting it here left the desktop app as a blank
// white window behind the permission bubble. Scheduling is likewise
// platform-specific (WorkManager on Android, an in-page timer in the
// browser -- see background_tasks.dart) and equally not worth a delayed
// first frame.
// coverage:ignore-start
unawaited(
notifications.requestPermission().then((_) {
return initBackgroundTasks();
}),
);
// coverage:ignore-end
// Off unless armed with --dart-define=DIET_GUARD_FRAME_STATS=1.
// coverage:ignore-start
if (frameStatsEnabled) startFrameStats();
// coverage:ignore-end
runApp(const DietGuardApp());
}
/// Root widget for the Diet Guard companion app.
class DietGuardApp extends StatelessWidget {
/// Creates the [DietGuardApp] root widget.
const DietGuardApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Diet Guard',
theme: ThemeData(colorSchemeSeed: Colors.teal, useMaterial3: true),
home: const LogMealScreen(),
);
}
}