feat: support flutter 3.10 (#154)

This commit is contained in:
Levi authored and GitHub committed 2023-07-15 14:52:59 +08:00
1 parent 99de0aaf9b
commit 3087796ef5
6 files changed
+1170 -458

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ on:
env: env:
GO_VERSION: 1.19 GO_VERSION: 1.19
FLUTTER_VERSION: 3.7.12 FLUTTER_VERSION: 3.10.6
permissions: permissions:
contents: write contents: write
+1 -1
View File
@@ -28,7 +28,7 @@ on:
env: env:
GO_VERSION: 1.19 GO_VERSION: 1.19
FLUTTER_VERSION: 3.7.12 FLUTTER_VERSION: 3.10.6
jobs: jobs:
# lint: # lint:
@@ -17,7 +17,6 @@ LibgopeedBoot create() => LibgopeedBootNative();
class LibgopeedBootNative implements LibgopeedBoot { class LibgopeedBootNative implements LibgopeedBoot {
late LibgopeedInterface _libgopeed; late LibgopeedInterface _libgopeed;
late SendPort _childSendPort;
LibgopeedBootNative() { LibgopeedBootNative() {
if (!Util.isDesktop()) { if (!Util.isDesktop()) {
@@ -44,12 +43,8 @@ class LibgopeedBootNative implements LibgopeedBoot {
@override @override
Future<void> stop() async { Future<void> stop() async {
if (Util.isDesktop()) {
await _ffiStop();
} else {
await _libgopeed.stop(); await _libgopeed.stop();
} }
}
_ffiInit() { _ffiInit() {
var libName = "libgopeed."; var libName = "libgopeed.";
@@ -67,90 +62,9 @@ class LibgopeedBootNative implements LibgopeedBoot {
// FFI run in isolate // FFI run in isolate
Future<int> _ffiStart(StartConfig cfg) async { Future<int> _ffiStart(StartConfig cfg) async {
var startCompleter = Completer<int>(); return await Isolate.run(() async {
var mainReceive = ReceivePort();
var isolate = await Isolate.spawn((SendPort sendPort) {
_ffiInit(); _ffiInit();
var childReceive = ReceivePort(); return await _libgopeed.start(cfg);
sendPort.send(childReceive.sendPort);
childReceive.listen((message) async {
late _Result result;
try {
if (message is _StartParam) {
result = _StartResult();
(result as _StartResult).port = await _libgopeed.start(message.cfg);
}
if (message is _StopParam) {
result = _StopResult();
await _libgopeed.stop();
childReceive.close();
Isolate.exit(sendPort);
}
} on Exception catch (e) {
result.exception = e;
}
sendPort.send(result);
}); });
}, mainReceive.sendPort);
var childCompleter = Completer<void>();
mainReceive.listen((message) {
if (message is SendPort) {
_childSendPort = message;
childCompleter.complete();
}
if (message is _StartResult) {
if (message.exception != null) {
startCompleter.completeError(message.exception!);
} else {
startCompleter.complete(message.port!);
}
}
if (message is _StopResult) {
isolate.kill();
if (message.exception != null) {
_stopCompleter.completeError(message.exception!);
} else {
_stopCompleter.complete();
}
}
});
await childCompleter.future;
_childSendPort.send(_StartParam(cfg: cfg));
return startCompleter.future;
}
late Completer<void> _stopCompleter;
Future<void> _ffiStop() async {
_stopCompleter = Completer<void>();
_childSendPort.send(_StopParam());
return _stopCompleter.future;
} }
} }
class _Result {
Exception? exception;
_Result();
}
class _StartParam {
final StartConfig cfg;
_StartParam({required this.cfg});
}
class _StartResult extends _Result {
int? port;
_StartResult();
}
class _StopParam {}
class _StopResult extends _Result {
_StopResult();
}
File diff suppressed because it is too large. Load diff
+221 -214
View File
File diff suppressed because it is too large. Load diff
+5 -7
View File
@@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.3.5+1 version: 1.3.5+1
environment: environment:
sdk: ">=2.17.6 <3.0.0" sdk: '>=3.0.0 <4.0.0'
# Dependencies specify other packages that your package needs in order to work. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions
@@ -46,7 +46,7 @@ dependencies:
macos_secure_bookmarks: ^0.2.1 macos_secure_bookmarks: ^0.2.1
rounded_loading_button: ^2.1.0 rounded_loading_button: ^2.1.0
url_launcher: ^6.1.6 url_launcher: ^6.1.6
shared_preferences: ^2.0.15 shared_preferences: ^2.2.0
logger: ^1.3.0 logger: ^1.3.0
desktop_drop: ^0.3.3 desktop_drop: ^0.3.3
package_info_plus: ^4.0.0 package_info_plus: ^4.0.0
@@ -67,14 +67,11 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
ffigen: ^6.1.2 ffigen: ^8.0.2
# build json model: flutter pub run build_runner build --delete-conflicting-outputs # build json model: flutter pub run build_runner build --delete-conflicting-outputs
build_runner: ^2.2.1 build_runner: ^2.2.1
json_serializable: ^6.3.2 json_serializable: ^6.3.2
flutter_launcher_icons: flutter_launcher_icons: ^0.13.1
git:
url: https://github.com/fluttercommunity/flutter_launcher_icons.git
ref: v0.11.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
@@ -128,6 +125,7 @@ flutter_icons:
generate: true generate: true
image_path: "assets/icon/icon_macos_1024.png" image_path: "assets/icon/icon_macos_1024.png"
# flutter pub run ffigen
ffigen: ffigen:
name: LibgopeedBind name: LibgopeedBind
description: Bindings to gopeed library. description: Bindings to gopeed library.