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

@@ -17,6 +17,7 @@ import 'package:window_manager/window_manager.dart';
import '../../../../api/api.dart';
import '../../../../api/model/downloader_config.dart';
import '../../../../core/common/start_config.dart';
import '../../../../core/libgopeed_boot.dart';
import '../../../../database/database.dart';
import '../../../../database/entity.dart';
import '../../../../i18n/message.dart';
@@ -110,6 +111,7 @@ class AppController extends GetxController with WindowListener, TrayListener {
void onClose() {
_linkSubscription?.cancel();
trayManager.removeListener(this);
LibgopeedBoot.instance.stop();
}
@override
@@ -240,7 +242,14 @@ class AppController extends GetxController with WindowListener, TrayListener {
MenuItem.separator(),
MenuItem(
label: 'exit'.tr,
onClick: (menuItem) => {windowManager.destroy()},
onClick: (menuItem) async {
try {
await LibgopeedBoot.instance.stop();
} catch (e) {
logger.w("libgopeed stop fail", e);
}
windowManager.destroy();
},
),
]);
if (!Util.isLinux()) {
@@ -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);
});
}
}