import 'dart:io'; import 'package:flutter/services.dart'; import '../print.dart'; /// خدمة التحكم بوضع النافذة العائمة (Picture-in-Picture) على أندرويد. /// تُستدعى عند بدء الرحلة لتفعيل PiP تلقائياً عند خروج المستخدم من التطبيق. class PipService { static const MethodChannel _channel = MethodChannel('intaleq/pip'); /// هل وضع PiP مدعوم على هذا الجهاز؟ static Future isPipSupported() async { if (!Platform.isAndroid) return false; try { final result = await _channel.invokeMethod('isPipSupported'); return result ?? false; } catch (e) { return false; } } /// تفعيل الدخول التلقائي لوضع PiP عند الخروج (أثناء الرحلة) static Future enablePip() async { if (!Platform.isAndroid) return; try { await _channel.invokeMethod('enablePip'); } catch (e) { Log.print('PiP enable error: \$e'); } } /// تعطيل الدخول التلقائي لوضع PiP (بعد انتهاء الرحلة) static Future disablePip() async { if (!Platform.isAndroid) return; try { await _channel.invokeMethod('disablePip'); } catch (e) { Log.print('PiP disable error: \$e'); } } /// الدخول يدوياً لوضع PiP static Future enterPip() async { if (!Platform.isAndroid) return false; try { final result = await _channel.invokeMethod('enterPip'); return result ?? false; } catch (e) { Log.print('PiP enter error: \$e'); return false; } } /// الاستماع لتغيير وضع PiP (الدخول/الخروج) static void listenToPipChanges(Function(bool isInPip) onChanged) { _channel.setMethodCallHandler((call) async { if (call.method == 'onPipChanged') { final isInPip = call.arguments as bool; onChanged(isInPip); } }); } }