feat: support custom tracker url (#59)

This commit is contained in:
Li Wei authored and GitHub committed 2022-12-12 15:58:11 +08:00
1 parent 9ef3405e43
commit 691c2f496e
71 files changed
+2209 -891

No files matched your search

@@ -20,7 +20,7 @@ class LibgopeedFFi implements LibgopeedInterface {
var completer = Completer<int>();
var result = _libgopeed.Start(jsonEncode(cfg).toNativeUtf8().cast());
if (result.r1 != nullptr) {
completer.completeError(result.r1.cast<Utf8>().toDartString());
completer.completeError(Exception(result.r1.cast<Utf8>().toDartString()));
} else {
completer.complete(result.r0);
}
+7 -12
View File
@@ -4,19 +4,14 @@ part 'start_config.g.dart';
@JsonSerializable()
class StartConfig {
String network;
String address;
String storage;
String storageDir;
int refreshInterval;
late String network;
late String address;
late String storage;
late String storageDir;
late int refreshInterval;
late String apiToken;
StartConfig({
required this.network,
required this.address,
required this.storage,
required this.storageDir,
required this.refreshInterval,
});
StartConfig();
factory StartConfig.fromJson(Map<String, dynamic> json) =>
_$StartConfigFromJson(json);
@@ -6,13 +6,13 @@ part of 'start_config.dart';
// JsonSerializableGenerator
// **************************************************************************
StartConfig _$StartConfigFromJson(Map<String, dynamic> json) => StartConfig(
network: json['network'] as String,
address: json['address'] as String,
storage: json['storage'] as String,
storageDir: json['storageDir'] as String,
refreshInterval: json['refreshInterval'] as int,
);
StartConfig _$StartConfigFromJson(Map<String, dynamic> json) => StartConfig()
..network = json['network'] as String
..address = json['address'] as String
..storage = json['storage'] as String
..storageDir = json['storageDir'] as String
..refreshInterval = json['refreshInterval'] as int
..apiToken = json['apiToken'] as String;
Map<String, dynamic> _$StartConfigToJson(StartConfig instance) =>
<String, dynamic>{
@@ -21,4 +21,5 @@ Map<String, dynamic> _$StartConfigToJson(StartConfig instance) =>
'storage': instance.storage,
'storageDir': instance.storageDir,
'refreshInterval': instance.refreshInterval,
'apiToken': instance.apiToken,
};
@@ -1,22 +1,18 @@
import 'dart:async';
import 'package:gopeed/core/common/start_config.dart';
import '../libgopeed_boot.dart';
LibgopeedBoot create() => LibgopeedBootBrowser();
class LibgopeedBootBrowser implements LibgopeedBoot {
late LibgopeedConfig _config;
LibgopeedBootBrowser() {
_config = LibgopeedConfig();
// do nothing
@override
Future<int> start(StartConfig cfg) async {
return 0;
}
@override
LibgopeedConfig get config => _config;
@override
Future<void> start() async {}
@override
Future<void> stop() async {}
}
@@ -16,48 +16,30 @@ import '../libgopeed_boot.dart';
LibgopeedBoot create() => LibgopeedBootNative();
class LibgopeedBootNative implements LibgopeedBoot {
late LibgopeedConfig _config;
late LibgopeedInterface _libgopeed;
late SendPort _childSendPort;
LibgopeedBootNative() {
_config = LibgopeedConfig();
if (!Util.isDesktop()) {
_libgopeed = LibgopeedChannel();
}
}
@override
LibgopeedConfig get config => _config;
@override
Future<void> start() async {
Future<int> start(StartConfig cfg) async {
var storageDir = "./";
if (!Util.isUnix()) {
// not support unix socket, use tcp
_config.network = "tcp";
_config.address = "127.0.0.1:0";
} else {
_config.network = "unix";
if (Util.isDesktop()) {
_config.address = LibgopeedBoot.unixSocketPath;
} else if (Platform.isAndroid) {
_config.address =
"${(await getTemporaryDirectory()).path}/${LibgopeedBoot.unixSocketPath}";
storageDir = (await getExternalStorageDirectory())?.path ?? "";
}
if (Platform.isAndroid) {
storageDir = (await getExternalStorageDirectory())?.path ?? storageDir;
}
final cfg = StartConfig(
network: _config.network,
address: _config.address,
storage: 'bolt',
storageDir: storageDir,
refreshInterval: _config.refreshInterval);
if (Platform.isIOS) {
storageDir = (await getLibraryDirectory()).path;
}
cfg.storage = 'bolt';
cfg.storageDir = storageDir;
cfg.refreshInterval = 0;
var port =
Util.isDesktop() ? await _ffiStart(cfg) : await _libgopeed.start(cfg);
if (_config.network == "tcp") {
_config.address = "${_config.address.split(":")[0]}:$port";
}
return port;
}
@override
+2 -15
View File
@@ -1,19 +1,8 @@
import 'common/start_config.dart';
import "libgopeed_boot_stub.dart"
if (dart.library.html) 'entry/libgopeed_boot_browser.dart'
if (dart.library.io) 'entry/libgopeed_boot_native.dart';
class LibgopeedConfig {
late String network;
late String address;
late int refreshInterval;
LibgopeedConfig({
this.network = "tcp",
this.address = "127.0.0.1:0",
this.refreshInterval = 500,
});
}
abstract class LibgopeedBoot {
static const unixSocketPath = 'gopeed.sock';
@@ -26,9 +15,7 @@ abstract class LibgopeedBoot {
factory LibgopeedBoot() => create();
Future<void> start();
Future<int> start(StartConfig cfg);
Future<void> stop();
LibgopeedConfig get config;
}