Files
huangguo_android/m3u8_downloader-master/lib/callback_dispatcher.dart
T
2026-09-15 15:44:13 +07:00

32 lines
1.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:io';
import 'dart:ui';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
// 必须标注:原生启动后台 isolate 时要从 native 闭包化这个入口函数,
// 新版 Flutter/Dart 不加 @pragma('vm:entry-point') 会报 "To closurize ... it must be annotated"
// 后台 isolate 起不来 → 下载进度/成功回调永远到不了 Dart,进度条不刷新。
@pragma('vm:entry-point')
void callbackDispatcher() {
// Initialize state necessary for MethodChannels.
WidgetsFlutterBinding.ensureInitialized();
const MethodChannel backgroundChannel = MethodChannel('vincent/m3u8_downloader_background', JSONMethodCodec());
backgroundChannel.setMethodCallHandler((MethodCall call) async {
final dynamic args = call.arguments;
final CallbackHandle handle = CallbackHandle.fromRawHandle(args[0]);
final Function? closure = PluginUtilities.getCallbackFromHandle(handle);
if (closure == null) {
print('Fatal: could not find callback');
exit(-1);
}
closure(args[1]);
});
backgroundChannel.invokeMethod('didInitializeDispatcher');
}