fix: clear UPNP port mapping when exist app (#624)

This commit is contained in:
Levi authored and GitHub committed 2024-07-30 18:43:54 +08:00
1 parent 3b50465708
commit 4fbe13a1f0
22 files changed
+506 -320

No files matched your search

@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';
import '../../util/util.dart';
import '../common/libgopeed_channel.dart';
@@ -17,7 +16,19 @@ class LibgopeedBootNative implements LibgopeedBoot {
late LibgopeedInterface _libgopeed;
LibgopeedBootNative() {
if (!Util.isDesktop()) {
if (Util.isDesktop()) {
var libName = "libgopeed.";
if (Platform.isWindows) {
libName += "dll";
}
if (Platform.isMacOS) {
libName += "dylib";
}
if (Platform.isLinux) {
libName += "so";
}
_libgopeed = LibgopeedFFi(LibgopeedBind(DynamicLibrary.open(libName)));
} else {
_libgopeed = LibgopeedChannel();
}
}
@@ -27,8 +38,7 @@ class LibgopeedBootNative implements LibgopeedBoot {
cfg.storage = 'bolt';
cfg.storageDir = Util.getStorageDir();
cfg.refreshInterval = 0;
var port =
Util.isDesktop() ? await _ffiStart(cfg) : await _libgopeed.start(cfg);
var port = await _libgopeed.start(cfg);
return port;
}
@@ -36,26 +46,4 @@ class LibgopeedBootNative implements LibgopeedBoot {
Future<void> stop() async {
await _libgopeed.stop();
}
_ffiInit() {
var libName = "libgopeed.";
if (Platform.isWindows) {
libName += "dll";
}
if (Platform.isMacOS) {
libName += "dylib";
}
if (Platform.isLinux) {
libName += "so";
}
_libgopeed = LibgopeedFFi(LibgopeedBind(DynamicLibrary.open(libName)));
}
// FFI run in isolate
Future<int> _ffiStart(StartConfig cfg) async {
return await Isolate.run(() async {
_ffiInit();
return await _libgopeed.start(cfg);
});
}
}