From f9e1794860a7b675b919584410055062fea2b384 Mon Sep 17 00:00:00 2001 From: gituser-vibes <296671358+gituser-vibes@users.noreply.github.com> Date: Wed, 24 Jun 2026 14:51:01 -0700 Subject: [PATCH] fix: don't abort startup when launched headless (no Activity) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the app is started in the background without an Activity — e.g. by Android Auto's MediaBrowserService or a media-button intent — FlutterDisplayMode.setHighRefreshRate() throws PlatformException(noActivity). Because it was awaited unguarded in main(), the exception aborted bootstrap before runApp(), so the audio handler was never registered and media browsers (Android Auto) hung indefinitely on a spinner. Wrap the non-essential high-refresh-rate call in try/catch so headless startup completes and the audio service registers. --- lib/main.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index ecf7148d..60cc48f6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -82,7 +82,16 @@ Future main(List rawArgs) async { // force High Refresh Rate on some Android devices (like One Plus) if (kIsAndroid) { - await FlutterDisplayMode.setHighRefreshRate(); + try { + await FlutterDisplayMode.setHighRefreshRate(); + } catch (e, stack) { + // When the app is cold-started headless (e.g. by Android Auto's + // MediaBrowserService) there is no attached Activity, so this throws + // PlatformException(noActivity). Refresh-rate tuning is non-essential + // and must not abort bootstrap — otherwise runApp() never runs and the + // audio handler is never registered, hanging media browsers forever. + AppLogger.reportError(e, stack); + } } if (kIsAndroid || kIsDesktop) { await NewPipeExtractor.init();