|
|
@@ -7,6 +7,7 @@ import 'package:get/get.dart';
|
|
|
import 'package:nomo/app/controllers/windows/window_service.dart';
|
|
|
import 'package:path/path.dart' as path;
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
+import 'package:uuid/uuid.dart';
|
|
|
|
|
|
import '../../config/translations/strings_enum.dart';
|
|
|
import '../../utils/log/logger.dart';
|
|
|
@@ -16,6 +17,7 @@ import '../constants/errors.dart';
|
|
|
import 'base_core_api.dart';
|
|
|
import 'windows/menu_base/src/menu.dart';
|
|
|
import 'windows/menu_base/src/menu_item.dart';
|
|
|
+import 'windows/stat_log_entry.dart';
|
|
|
import 'windows/vpn_service.dart';
|
|
|
|
|
|
/// Windows 实现
|
|
|
@@ -46,6 +48,11 @@ class WindowsCoreApi implements BaseCoreApi {
|
|
|
int _sessionCountUp = 0; // session计时
|
|
|
bool _isCountdown = false; // 汇报计时类型 倒计时还是正计时
|
|
|
|
|
|
+ int _locationId = 0;
|
|
|
+ String _locationCode = '';
|
|
|
+ String _boostSessionId = '';
|
|
|
+ int _peekTimeInterval = 0;
|
|
|
+
|
|
|
/// 内部构造方法,供 BaseCoreApi 工厂使用
|
|
|
factory WindowsCoreApi.create() => WindowsCoreApi._();
|
|
|
|
|
|
@@ -150,16 +157,82 @@ class WindowsCoreApi implements BaseCoreApi {
|
|
|
'{"type":"vpn_status","status":2,"code":0,"message":""}',
|
|
|
);
|
|
|
|
|
|
- // TODO: 汇报日志
|
|
|
- // _eventController.add(
|
|
|
- // '{"type":"boost_result","locationCode":"US","nodeId":"xxx","success":true}',
|
|
|
- // );
|
|
|
+ // 获取统计
|
|
|
+ _vpn.queryStat().then((stat) {
|
|
|
+ log(_tag, 'stat: $stat');
|
|
|
+ try {
|
|
|
+ final ts = DateTime.now().millisecondsSinceEpoch;
|
|
|
+ final connectionHistory = (stat?['connectionHistory'] as List?)?.last;
|
|
|
+
|
|
|
+ final param = statLogEntryToJson(
|
|
|
+ StatLogEntry(
|
|
|
+ id: Uuid().v4(),
|
|
|
+ time: ts,
|
|
|
+ level: 'info',
|
|
|
+ module: 'NM_BoostResult',
|
|
|
+ category: 'nomo',
|
|
|
+ fields: Fields(
|
|
|
+ code: 0,
|
|
|
+ boostSessionId: _boostSessionId,
|
|
|
+ success: true,
|
|
|
+ locationId: _locationId,
|
|
|
+ locationCode: _locationCode,
|
|
|
+ generatedTime: ts,
|
|
|
+ connectionHistory: connectionHistory,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ final nodeId = connectionHistory['nodeId'] ?? 0;
|
|
|
+ final msg =
|
|
|
+ '{"type":"boost_result","locationCode":"$_locationCode","nodeId":"$nodeId","success":true, "param": "$param"}';
|
|
|
+
|
|
|
+ _eventController.add(msg);
|
|
|
+ } catch (e) {
|
|
|
+ log(_tag, 'parse stat json error: $e');
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void _handleStateError(int code) {
|
|
|
_eventController.add(
|
|
|
'{"type":"vpn_status","status":3,"code":$code,"message":""}',
|
|
|
);
|
|
|
+ // 获取统计
|
|
|
+ _vpn.queryStat().then((stat) {
|
|
|
+ log(_tag, 'stat: $stat');
|
|
|
+ try {
|
|
|
+ final ts = DateTime.now().millisecondsSinceEpoch;
|
|
|
+ final connectionHistory = (stat?['connectionHistory'] as List?)?.last;
|
|
|
+
|
|
|
+ final param = statLogEntryToJson(
|
|
|
+ StatLogEntry(
|
|
|
+ id: Uuid().v4(),
|
|
|
+ time: ts,
|
|
|
+ level: 'info',
|
|
|
+ module: 'NM_BoostResult',
|
|
|
+ category: 'nomo',
|
|
|
+ fields: Fields(
|
|
|
+ code: code,
|
|
|
+ boostSessionId: _boostSessionId,
|
|
|
+ success: false,
|
|
|
+ locationId: _locationId,
|
|
|
+ locationCode: _locationCode,
|
|
|
+ generatedTime: ts,
|
|
|
+ connectionHistory: connectionHistory,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ final nodeId = connectionHistory['nodeId'] ?? 0;
|
|
|
+ final msg =
|
|
|
+ '{"type":"boost_result","locationCode":"$_locationCode","nodeId":"$nodeId","success":false, "param": "$param"}';
|
|
|
+
|
|
|
+ _eventController.add(msg);
|
|
|
+ } catch (e) {
|
|
|
+ log(_tag, 'parse stat json error: $e');
|
|
|
+ }
|
|
|
+ });
|
|
|
_vpn.stop();
|
|
|
}
|
|
|
|
|
|
@@ -176,11 +249,6 @@ class WindowsCoreApi implements BaseCoreApi {
|
|
|
'{"type":"vpn_status","status":0,"code":0,"message":""}',
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
- // TODO: 汇报日志
|
|
|
- // _eventController.add(
|
|
|
- // '{"type":"boost_result","locationCode":"US","nodeId":"xxx","success":true}',
|
|
|
- // );
|
|
|
}
|
|
|
|
|
|
void _checkMembershipRemaining() {
|
|
|
@@ -265,6 +333,10 @@ class WindowsCoreApi implements BaseCoreApi {
|
|
|
// 记录会员剩余时间
|
|
|
_remainTime = remainTime;
|
|
|
_isCountdown = isCountdown;
|
|
|
+ _locationId = locationId;
|
|
|
+ _locationCode = locationCode;
|
|
|
+ _boostSessionId = sessionId;
|
|
|
+ _peekTimeInterval = peekTimeInterval;
|
|
|
|
|
|
String geoPath = await _getGeoDirectory();
|
|
|
|