import 'package:get/get.dart';

import '../plugins/keyboard_android_platform.dart';

/// 悬浮窗工具类
class FloatingWindowHelper {
  FloatingWindowHelper._();

  /// 是否有悬浮权限
  static RxBool hasFloatingWindowPermission = false.obs;

  /// 初始化
  static void init() {
    KeyboardAndroidPlatform.hasFloatingWindowPermission().then((hasPermission) {
      hasFloatingWindowPermission.value = hasPermission;
    });
  }

  /// 更新权限状态
  static void updatePermissionState() {
    KeyboardAndroidPlatform.hasFloatingWindowPermission().then((hasPermission) {
      hasFloatingWindowPermission.value = hasPermission;
    });
  }

  /// 显示悬浮窗
  static void showFloatingBall() {
    // 检查是否有悬浮窗权限
    KeyboardAndroidPlatform.hasFloatingWindowPermission().then((hasPermission) {
      // 有权限，则启动悬浮窗
      if (hasPermission) {
        KeyboardAndroidPlatform.enableFloatingWindow(true);
      }
    });
  }
}
