content: import 'dart:io';
  
  import 'package:dartotsu_extension_bridge/Mangayomi/Eval/dart/model/source_preference.dart';
  import 'package:dartotsu_extension_bridge/Mangayomi/Models/Source.dart';
  import 'package:dartotsu_extension_bridge/Settings/Settings.dart';
  import 'package:isar/isar.dart';
  import 'package:path/path.dart' as path;
  import 'package:path_provider/path_provider.dart';
  import 'package:permission_handler/permission_handler.dart';
  
  class StorageProvider {
    Future<bool> requestPermission() async {
      Permission permission = Permission.manageExternalStorage;
      if (Platform.isAndroid) {
        if (await permission.isGranted) {
          return true;
        } else {
          final result = await permission.request();
          if (result == PermissionStatus.granted) {
            return true;
          }
          return false;
        }
      }
      return true;
    }
  
    Future<Directory?> getDatabaseDirectory() async {
      final dir = await getApplicationDocumentsDirectory();
      if (Platform.isAndroid || Platform.isIOS || Platform.isMacOS) {
        return dir;
      } else {
        String dbDir = path.join(dir.path, 'AnymeX', 'databases');
        await Directory(dbDir).create(recursive: true);
        return Directory(dbDir);
      }
    }
  
    Future<Isar> initDB(String? path, {bool inspector = false}) async {
      Directory? dir;
      if (path == null) {
        dir = await getDatabaseDirectory();
      } else {
        dir = Directory(path);
      }
  
      final isar = Isar.openSync([
        MSourceSchema,
        SourcePreferenceSchema,
        SourcePreferenceStringValueSchema,
        BridgeSettingsSchema
      ], directory: dir!.path, name: "AnymeX", inspector: inspector);
  
      return isar;
    }
  }
  