From 1a6ec3f9ad7ead5ec4533ad61b7627de415d442c Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:12:39 +0530 Subject: [PATCH] feat(assistant): Improve screen context processing with model selection --- lib/core/utils/android_assistant_handler.dart | 30 ++++++++++++++++++- lib/features/chat/views/chat_page.dart | 6 ++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/core/utils/android_assistant_handler.dart b/lib/core/utils/android_assistant_handler.dart index 4b03461..42a8368 100644 --- a/lib/core/utils/android_assistant_handler.dart +++ b/lib/core/utils/android_assistant_handler.dart @@ -40,7 +40,7 @@ class AndroidAssistantHandler { Future _handleMethodCall(MethodCall call) async { if (call.method == 'analyzeScreen') { final String context = call.arguments as String; - _ref.read(screenContextProvider.notifier).setContext(context); + await _processScreenContext(context); } else if (call.method == 'analyzeScreenshot') { final String screenshotPath = call.arguments as String; await _processScreenshot(screenshotPath); @@ -49,6 +49,34 @@ class AndroidAssistantHandler { } } + Future _processScreenContext(String context) async { + try { + DebugLogger.log('Processing screen context', scope: 'assistant'); + + // Wait for app to be ready (authenticated and model available) + final navState = _ref.read(authNavigationStateProvider); + final model = _ref.read(selectedModelProvider); + + if (navState != AuthNavigationState.authenticated || model == null) { + DebugLogger.log('App not ready for screen context processing', scope: 'assistant'); + return; + } + + // Navigate to chat if not already there + final isOnChatRoute = NavigationService.currentRoute == Routes.chat; + if (!isOnChatRoute) { + // Navigation will happen via auth state + return; + } + + // Set the screen context + _ref.read(screenContextProvider.notifier).setContext(context); + DebugLogger.log('Screen context set successfully', scope: 'assistant'); + } catch (e) { + DebugLogger.log('Failed to process screen context: $e', scope: 'assistant'); + } + } + Future _processScreenshot(String screenshotPath) async { try { DebugLogger.log('Processing screenshot: $screenshotPath', scope: 'assistant'); diff --git a/lib/features/chat/views/chat_page.dart b/lib/features/chat/views/chat_page.dart index 98ee420..06fad40 100644 --- a/lib/features/chat/views/chat_page.dart +++ b/lib/features/chat/views/chat_page.dart @@ -315,12 +315,10 @@ class _ChatPageState extends ConsumerState { // Clear the context so we don't process it again WidgetsBinding.instance.addPostFrameCallback((_) { ref.read(screenContextProvider.notifier).setContext(null); - // Pre-fill the input or send a message - // For now, let's just pre-fill the input with a prompt - // TODO: Ideally we should add this as a system message or attachment + final currentModel = ref.read(selectedModelProvider); _handleMessageSend( "Here is the content of my screen:\n\n$screenContext\n\nCan you summarize this?", - null, + currentModel, ); }); }