更新扩展连接协议字段并且新增邀请码展示
This commit is contained in:
@@ -101,4 +101,7 @@ abstract class Api {
|
||||
|
||||
/// 获取可用支付方式(公开接口)
|
||||
static const String kr_getPublicPaymentMethods = "/v1/public/payment/methods";
|
||||
|
||||
/// 获取用户信息(用于获取邀请码等)
|
||||
static const String kr_getUserInfo = "/v1/public/user/info";
|
||||
}
|
||||
|
||||
@@ -83,22 +83,22 @@ class KRUserApi {
|
||||
return right(baseResponse.model);
|
||||
}
|
||||
|
||||
// ⚠️ 已废弃:新版本后端不再提供此接口
|
||||
// Future<Either<HttpError, KRUserInfo>> kr_getUserInfo() async {
|
||||
// final Map<String, dynamic> data = <String, dynamic>{};
|
||||
// BaseResponse<KRUserInfo> baseResponse =
|
||||
// await HttpUtil.getInstance().request<KRUserInfo>(
|
||||
// Api.kr_getUserInfo,
|
||||
// data,
|
||||
// method: HttpMethod.GET,
|
||||
// isShowLoading: false,
|
||||
// );
|
||||
// if (!baseResponse.isSuccess) {
|
||||
// return left(
|
||||
// HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
// }
|
||||
// return right(baseResponse.model);
|
||||
// }
|
||||
/// 获取用户信息(包含邀请码、余额、佣金等)
|
||||
static Future<Either<HttpError, KRUserInfo>> kr_getUserInfo() async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
BaseResponse<KRUserInfo> baseResponse =
|
||||
await HttpUtil.getInstance().request<KRUserInfo>(
|
||||
Api.kr_getUserInfo,
|
||||
data,
|
||||
method: HttpMethod.GET,
|
||||
isShowLoading: false,
|
||||
);
|
||||
if (!baseResponse.isSuccess) {
|
||||
return left(
|
||||
HttpError(msg: baseResponse.retMsg, code: baseResponse.retCode));
|
||||
}
|
||||
return right(baseResponse.model);
|
||||
}
|
||||
|
||||
Future<Either<HttpError, KRAffiliateCount>> kr_getAffiliateCount() async {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
@@ -404,7 +404,27 @@ class KRSingBoxImp {
|
||||
void kr_saveOutbounds(List<Map<String, dynamic>> outbounds) async {
|
||||
KRLogUtil.kr_i('💾 开始保存配置文件...', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📊 出站节点数量: ${outbounds.length}', tag: 'SingBox');
|
||||
|
||||
|
||||
// 打印每个节点的详细配置
|
||||
for (int i = 0; i < outbounds.length; i++) {
|
||||
final outbound = outbounds[i];
|
||||
KRLogUtil.kr_i('📋 节点[$i] 配置:', tag: 'SingBox');
|
||||
KRLogUtil.kr_i(' - type: ${outbound['type']}', tag: 'SingBox');
|
||||
KRLogUtil.kr_i(' - tag: ${outbound['tag']}', tag: 'SingBox');
|
||||
KRLogUtil.kr_i(' - server: ${outbound['server']}', tag: 'SingBox');
|
||||
KRLogUtil.kr_i(' - server_port: ${outbound['server_port']}', tag: 'SingBox');
|
||||
if (outbound['method'] != null) {
|
||||
KRLogUtil.kr_i(' - method: ${outbound['method']}', tag: 'SingBox');
|
||||
}
|
||||
if (outbound['password'] != null) {
|
||||
KRLogUtil.kr_i(' - password: ${outbound['password']?.toString().substring(0, 8)}...', tag: 'SingBox');
|
||||
}
|
||||
if (outbound['uuid'] != null) {
|
||||
KRLogUtil.kr_i(' - uuid: ${outbound['uuid']?.toString().substring(0, 8)}...', tag: 'SingBox');
|
||||
}
|
||||
KRLogUtil.kr_i(' - 完整配置: ${jsonEncode(outbound)}', tag: 'SingBox');
|
||||
}
|
||||
|
||||
kr_outbounds = outbounds;
|
||||
|
||||
final map = {};
|
||||
@@ -413,10 +433,10 @@ class KRSingBoxImp {
|
||||
final file = _file(kr_configName);
|
||||
final temp = _tempFile(kr_configName);
|
||||
final mapStr = jsonEncode(map);
|
||||
|
||||
|
||||
KRLogUtil.kr_i('📄 配置文件内容长度: ${mapStr.length}', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📄 配置文件前500字符: ${mapStr.substring(0, mapStr.length > 500 ? 500 : mapStr.length)}', tag: 'SingBox');
|
||||
|
||||
KRLogUtil.kr_i('📄 完整配置文件内容: $mapStr', tag: 'SingBox');
|
||||
|
||||
await file.writeAsString(mapStr);
|
||||
await temp.writeAsString(mapStr);
|
||||
|
||||
@@ -428,7 +448,7 @@ class KRSingBoxImp {
|
||||
.mapLeft((err) {
|
||||
KRLogUtil.kr_e('❌ 保存配置文件失败: $err', tag: 'SingBox');
|
||||
}).run();
|
||||
|
||||
|
||||
KRLogUtil.kr_i('✅ 配置文件保存完成', tag: 'SingBox');
|
||||
}
|
||||
|
||||
@@ -438,7 +458,7 @@ class KRSingBoxImp {
|
||||
KRLogUtil.kr_i('🚀 开始启动 SingBox...', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📁 配置文件路径: $_cutPath', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📝 配置名称: $kr_configName', tag: 'SingBox');
|
||||
|
||||
|
||||
// 检查配置文件是否存在
|
||||
final configFile = File(_cutPath);
|
||||
if (await configFile.exists()) {
|
||||
@@ -448,7 +468,7 @@ class KRSingBoxImp {
|
||||
} else {
|
||||
KRLogUtil.kr_w('⚠️ 配置文件不存在: $_cutPath', tag: 'SingBox');
|
||||
}
|
||||
|
||||
|
||||
await kr_singBox.start(_cutPath, kr_configName, false).map(
|
||||
(r) {
|
||||
KRLogUtil.kr_i('✅ SingBox 启动成功', tag: 'SingBox');
|
||||
@@ -525,35 +545,59 @@ class KRSingBoxImp {
|
||||
|
||||
//// 设置出站模式
|
||||
Future<void> kr_updateConnectionType(KRConnectionType newType) async {
|
||||
if (kr_connectionType.value == newType) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
KRLogUtil.kr_i('🔄 开始更新连接类型...', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📊 当前类型: ${kr_connectionType.value}', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📊 新类型: $newType', tag: 'SingBox');
|
||||
|
||||
kr_connectionType.value = newType;
|
||||
if (kr_connectionType.value == newType) {
|
||||
KRLogUtil.kr_i('⚠️ 连接类型相同,无需更新', tag: 'SingBox');
|
||||
return;
|
||||
}
|
||||
|
||||
final oOption = _getConfigOption();
|
||||
kr_connectionType.value = newType;
|
||||
|
||||
var mode = "";
|
||||
switch (newType) {
|
||||
case KRConnectionType.global:
|
||||
mode = "other";
|
||||
break;
|
||||
case KRConnectionType.rule:
|
||||
mode = KRCountryUtil.kr_getCurrentCountryCode();
|
||||
break;
|
||||
// case KRConnectionType.direct:
|
||||
// mode = "direct";
|
||||
// break;
|
||||
}
|
||||
oOption["region"] = mode;
|
||||
final op = SingboxConfigOption.fromJson(oOption);
|
||||
final oOption = _getConfigOption();
|
||||
|
||||
await kr_singBox.changeOptions(op)
|
||||
..map((r) {}).mapLeft((err) {
|
||||
KRLogUtil.kr_e('更新连接类型失败: $err');
|
||||
}).run();
|
||||
if (kr_status.value == SingboxStarted()) {
|
||||
await kr_restart();
|
||||
var mode = "";
|
||||
switch (newType) {
|
||||
case KRConnectionType.global:
|
||||
mode = "other";
|
||||
KRLogUtil.kr_i('🌍 切换到全局代理模式', tag: 'SingBox');
|
||||
break;
|
||||
case KRConnectionType.rule:
|
||||
mode = KRCountryUtil.kr_getCurrentCountryCode();
|
||||
KRLogUtil.kr_i('🎯 切换到规则代理模式: $mode', tag: 'SingBox');
|
||||
break;
|
||||
// case KRConnectionType.direct:
|
||||
// mode = "direct";
|
||||
// break;
|
||||
}
|
||||
oOption["region"] = mode;
|
||||
KRLogUtil.kr_i('📝 更新 region 配置: $mode', tag: 'SingBox');
|
||||
|
||||
final op = SingboxConfigOption.fromJson(oOption);
|
||||
KRLogUtil.kr_i('📄 配置选项: ${oOption.toString()}', tag: 'SingBox');
|
||||
|
||||
await kr_singBox.changeOptions(op)
|
||||
..map((r) {
|
||||
KRLogUtil.kr_i('✅ 连接类型更新成功', tag: 'SingBox');
|
||||
}).mapLeft((err) {
|
||||
KRLogUtil.kr_e('❌ 更新连接类型失败: $err', tag: 'SingBox');
|
||||
throw err;
|
||||
}).run();
|
||||
|
||||
if (kr_status.value == SingboxStarted()) {
|
||||
KRLogUtil.kr_i('🔄 VPN已启动,准备重启以应用新配置...', tag: 'SingBox');
|
||||
await kr_restart();
|
||||
KRLogUtil.kr_i('✅ VPN重启完成', tag: 'SingBox');
|
||||
} else {
|
||||
KRLogUtil.kr_i('ℹ️ VPN未启动,配置已更新', tag: 'SingBox');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
KRLogUtil.kr_e('💥 更新连接类型异常: $e', tag: 'SingBox');
|
||||
KRLogUtil.kr_e('📚 错误堆栈: $stackTrace', tag: 'SingBox');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,7 +642,7 @@ class KRSingBoxImp {
|
||||
void kr_selectOutbound(String tag) {
|
||||
KRLogUtil.kr_i('🎯 开始选择出站节点: $tag', tag: 'SingBox');
|
||||
KRLogUtil.kr_i('📊 当前活动组数量: ${kr_activeGroups.length}', tag: 'SingBox');
|
||||
|
||||
|
||||
// 打印所有活动组信息
|
||||
for (int i = 0; i < kr_activeGroups.length; i++) {
|
||||
final group = kr_activeGroups[i];
|
||||
|
||||
Reference in New Issue
Block a user