初始化
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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');
|
||||
}
|
||||
Reference in New Issue
Block a user