start method
Starts the server and returns the URL OpenRouter should redirect to.
timeout caps how long the server waits for the callback; after it
elapses the server closes and waitForCode completes with null.
Implementation
Future<String> start({Duration timeout = const Duration(minutes: 5)}) async {
await close();
_codeCompleter = Completer<String?>();
_server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
final server = _server!;
final url = callbackUrl!;
_timeoutTimer = Timer(timeout, () {
final completer = _codeCompleter;
if (completer != null && !completer.isCompleted) {
completer.complete(null);
}
unawaited(close());
});
server.listen(_handleRequest, onDone: _onDone);
return url;
}