todo-app/lib/main.dart
Krzysztof kuhy Rudnicki c740cac2f0 Add an env-guarded frame instrument for the desktop performance work
Keeps the diagnostic used to produce docs/desktop-performance-findings.md, so
the web proof-of-concept can be measured against the same numbers rather than a
freshly-written and differently-behaving probe.

Armed only by TODO_FRAME_STATS=1, so it is inert in normal use. It reports:

- individual slow frames, not per-second percentiles -- a user-visible hitch is
  one long frame, which averaging over a 61-frame window hides completely;
- event-loop blocking via a periodic timer, which is unambiguous where frame
  gaps are not (a static UI produces no frames, so an idle user and a stalled
  isolate look identical);
- every frame when TODO_FRAME_STATS_ALL=1, for raster-cost-vs-window-size
  sweeps.

The capture screen gets a spinner under the same flag because cadence can only
be sampled while something animates continuously. Its branch is unreachable
under the test runner, hence coverage:ignore -- the suite stays at 100%.

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

54 lines
1.7 KiB
Dart

// coverage:ignore-file
// App bootstrap: wires platform DB paths (path_provider) into the repository
// and calls runApp. Exercised end-to-end by running the app, not unit tests.
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/frame_stats.dart';
import 'package:todo/ui/capture_screen.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
installFrameStats();
// Desktop platforms need the FFI sqlite implementation initialised
// before any database is opened; mobile uses the bundled library.
if (!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS)) {
sqfliteFfiInit();
}
final dir = await getApplicationSupportDirectory();
final dbPath = p.join(dir.path, 'todo.db');
final repository = await NoteRepository.open(dbPath);
runApp(TodoApp(repository: repository));
}
/// Root widget. Holds the single [NoteRepository] instance and hands it
/// to the screens that need it.
class TodoApp extends StatelessWidget {
/// Creates a [TodoApp] wrapping the given [repository].
const TodoApp({required this.repository, super.key});
/// The single, app-wide note store, injected into every screen.
final NoteRepository repository;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'todo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: CaptureScreen(repository: repository),
);
}
}