refactor: Remove _processScreenContext and directly set screen context in _handleMethodCall.

This commit is contained in:
cogwheel0
2025-11-22 12:01:17 +05:30
parent 0414f1fb98
commit 8ed75f8f14
2 changed files with 133 additions and 185 deletions

View File

@@ -40,7 +40,7 @@ class AndroidAssistantHandler {
Future<void> _handleMethodCall(MethodCall call) async {
if (call.method == 'analyzeScreen') {
final String context = call.arguments as String;
await _processScreenContext(context);
_ref.read(screenContextProvider.notifier).setContext(context);
} else if (call.method == 'analyzeScreenshot') {
final String screenshotPath = call.arguments as String;
await _processScreenshot(screenshotPath);
@@ -49,34 +49,6 @@ class AndroidAssistantHandler {
}
}
Future<void> _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<void> _processScreenshot(String screenshotPath) async {
try {
DebugLogger.log('Processing screenshot: $screenshotPath', scope: 'assistant');