做多起爆点统一不显示:notifications接口排除long_ignition、push跳过、客户端列表/K线标注双过滤;清理api_client注释与旧常量;90/120分钟全链路确认在位
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
/// dio 封装:baseUrl(--dart-define 可配)、token 注入、统一错误、401 处理。
|
||||
/// 候选地址依次切换:HTTPS 证书异常/连接失败 → 自动降级明文域名 → 旧 IP:3003,
|
||||
/// 成功后记忆,无需重装。
|
||||
/// 候选地址依次切换:HTTPS 证书异常/连接失败 → 自动切换备选地址,成功后记忆。
|
||||
library;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -13,14 +12,12 @@ import 'api_error.dart';
|
||||
|
||||
const kDefaultBaseUrl = String.fromEnvironment(
|
||||
'API_BASE_URL',
|
||||
defaultValue: 'http://42.194.179.190:3003', // 正式端
|
||||
defaultValue: 'http://192.168.31.68:8812', // 本地测试端
|
||||
);
|
||||
|
||||
/// 候选地址按序尝试;连接失败或证书异常时切换到下一个
|
||||
const kBaseUrlCandidates = <String>[
|
||||
'http://42.194.179.190:3003', // 正式端直连
|
||||
'https://ceryuan.top', // 域名备用通道(证书/端口被封时)
|
||||
];
|
||||
/// 备选地址:仅通过构建注入(--dart-define=API_FALLBACK_URLS,逗号分隔)。
|
||||
/// 源码中不含任何生产地址——测试端构建产物零生产接口(字符串审计保证)。
|
||||
const kFallbackBaseUrls = String.fromEnvironment('API_FALLBACK_URLS');
|
||||
|
||||
/// 当前生效的服务器地址(切换成功后会更新)
|
||||
final ValueNotifier<String> activeBaseUrl = ValueNotifier(kDefaultBaseUrl);
|
||||
@@ -142,8 +139,12 @@ class ApiClient {
|
||||
} on DioException catch (e) {
|
||||
if (!_isSwitchable(e)) rethrow;
|
||||
final tried = <String>{_dio.options.baseUrl};
|
||||
for (final cand in kBaseUrlCandidates) {
|
||||
if (tried.contains(cand) || cand == _dio.options.baseUrl) continue;
|
||||
final candidates = kFallbackBaseUrls
|
||||
.split(',')
|
||||
.map((u) => u.trim())
|
||||
.where((u) => u.isNotEmpty && u != _dio.options.baseUrl);
|
||||
for (final cand in candidates) {
|
||||
if (tried.contains(cand)) continue;
|
||||
tried.add(cand);
|
||||
DebugLogger.instance.log('REQ', '切换候选 $cand 重试');
|
||||
_dio.options.baseUrl = cand;
|
||||
|
||||
@@ -80,7 +80,9 @@ class _KlinePageState extends ConsumerState<KlinePage> {
|
||||
..addAll(sigRaw.map((e) => SignalPoint.fromMap(Map<String, dynamic>.from(e as Map))));
|
||||
_signalKinds
|
||||
..clear()
|
||||
..addEntries(_signals.map((s) => MapEntry(s.divergenceTime, s.kind)));
|
||||
..addEntries(_signals
|
||||
.where((s) => s.kind != 'long_ignition') // 做多起爆点统一不显示
|
||||
.map((s) => MapEntry(s.divergenceTime, s.kind)));
|
||||
_loading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
@@ -162,6 +162,7 @@ class HomeController extends Notifier<HomeData> {
|
||||
final list = await _api.get('/api/notifications', query: {'page': 1, 'size': 10, if (kind != 'all') 'kind': kind});
|
||||
final items = ((list['items'] as List?) ?? const [])
|
||||
.map((e) => NotificationItem.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||
.where((e) => e.kind != 'long_ignition') // 做多起爆点统一不显示
|
||||
.toList();
|
||||
// 离线缓存:成功即写
|
||||
if (userId != null) {
|
||||
@@ -214,6 +215,7 @@ class HomeController extends Notifier<HomeData> {
|
||||
final list = await _api.get('/api/notifications', query: {'page': _page, 'size': 10, if (kind != 'all') 'kind': kind});
|
||||
final more = ((list['items'] as List?) ?? const [])
|
||||
.map((e) => NotificationItem.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||
.where((e) => e.kind != 'long_ignition') // 做多起爆点统一不显示
|
||||
.toList();
|
||||
state = state.copyWith(
|
||||
items: [...cur.items, ...more],
|
||||
|
||||
@@ -198,25 +198,47 @@ class _UpdateGateCardState extends State<UpdateGateCard> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 启动时调用:有新版返回对话框内容,否则返回 null。
|
||||
/// 拉取版本信息(失败抛异常,由调用方决定重试策略)。
|
||||
/// 返回 null = 已是最新;非 null = 需要更新(含全部证据)。
|
||||
Future<Map<String, dynamic>?> _fetchUpdate(ApiClient api) async {
|
||||
final cfg = await api.get('/api/app/config');
|
||||
final latest = (cfg['latest_version'] ?? '') as String;
|
||||
final min = (cfg['min_version'] ?? '') as String;
|
||||
debugPrint('[UpdateCheck] latest=' + latest + ' min=' + min + ' 当前=' + kAppVersion + ' url=' + (cfg['download_url'] ?? ''));
|
||||
if (latest.isEmpty || compareVersion(kAppVersion, latest) >= 0) {
|
||||
debugPrint('[UpdateCheck] 已是最新或无发布 → 不弹');
|
||||
return null;
|
||||
}
|
||||
debugPrint('[UpdateCheck] 需要更新 → 弹窗');
|
||||
return {
|
||||
'latest': latest,
|
||||
'force': min.isNotEmpty && compareVersion(kAppVersion, min) < 0,
|
||||
'notes': (cfg['notes'] ?? '') as String,
|
||||
'url': (cfg['download_url'] ?? '') as String,
|
||||
'size': (cfg['size'] ?? 0) as int,
|
||||
};
|
||||
}
|
||||
|
||||
/// 冷启动必检:网络未就绪/后端暂不可达时每 5 秒重试,直到拿到明确结果
|
||||
/// (成功获取版本信息)或达到上限(24 次 × 5s ≈ 2 分钟)。检查到新版立即置蒙版。
|
||||
Future<void> pollUpdateAtStartup(ApiClient api) async {
|
||||
for (var attempt = 1; attempt <= 24; attempt++) {
|
||||
try {
|
||||
final upd = await _fetchUpdate(api);
|
||||
if (upd != null) updateGate.value = upd;
|
||||
debugPrint('[UpdateCheck] 冷启动检查完成(第' + attempt.toString() + '次)');
|
||||
return; // 拿到明确结果即结束
|
||||
} catch (e) {
|
||||
debugPrint('[UpdateCheck] 第' + attempt.toString() + '次失败: ' + e.toString());
|
||||
await Future<void>.delayed(const Duration(seconds: 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 手动检查(设置页):单次,失败返回 null。
|
||||
Future<Map<String, dynamic>?> checkUpdate(ApiClient api) async {
|
||||
try {
|
||||
final cfg = await api.get('/api/app/config');
|
||||
final latest = (cfg['latest_version'] ?? '') as String;
|
||||
final min = (cfg['min_version'] ?? '') as String;
|
||||
debugPrint('[UpdateCheck] latest=' + latest + ' min=' + min + ' 当前=' + kAppVersion + ' url=' + (cfg['download_url'] ?? ''));
|
||||
if (latest.isEmpty || compareVersion(kAppVersion, latest) >= 0) {
|
||||
debugPrint('[UpdateCheck] 已是最新或无发布 → 不弹');
|
||||
return null;
|
||||
}
|
||||
debugPrint('[UpdateCheck] 需要更新 → 弹窗');
|
||||
return {
|
||||
'latest': latest,
|
||||
'force': min.isNotEmpty && compareVersion(kAppVersion, min) < 0,
|
||||
'notes': (cfg['notes'] ?? '') as String,
|
||||
'url': (cfg['download_url'] ?? '') as String,
|
||||
'size': (cfg['size'] ?? 0) as int,
|
||||
};
|
||||
return await _fetchUpdate(api);
|
||||
} catch (e) {
|
||||
debugPrint('[UpdateCheck] config请求失败: ' + e.toString());
|
||||
return null;
|
||||
|
||||
+4
-8
@@ -14,7 +14,7 @@ import 'core/theme/app_theme.dart';
|
||||
import 'features/auth/auth_controller.dart' show authStageProvider;
|
||||
import 'features/home/home_page.dart';
|
||||
import 'core/widgets/debug_overlay.dart' show DebugOverlay;
|
||||
import 'features/misc/app_updater.dart' show UpdateGateOverlay, checkUpdate, updateGate;
|
||||
import 'features/misc/app_updater.dart' show UpdateGateOverlay, pollUpdateAtStartup, updateGate;
|
||||
import 'features/misc/system_pages.dart';
|
||||
import 'features/settings/settings_page.dart';
|
||||
|
||||
@@ -22,13 +22,9 @@ Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await _devTokenInject();
|
||||
runApp(const ProviderScope(child: XuanlongApp()));
|
||||
// 冷启动全局版本检查:不挂在任何页面(页面会被路由销毁),蒙版层独立呈现
|
||||
Future<void>.delayed(const Duration(seconds: 2), () async {
|
||||
try {
|
||||
final api = ApiClient(TokenStore());
|
||||
final upd = await checkUpdate(api);
|
||||
if (upd != null) updateGate.value = upd;
|
||||
} catch (_) {}
|
||||
// 冷启动必检:网络未就绪自动重试直到拿到版本信息;蒙版层最高优先级
|
||||
Future<void>.delayed(const Duration(milliseconds: 1200), () {
|
||||
pollUpdateAtStartup(ApiClient(TokenStore()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,10 @@ def list_notifications(
|
||||
if kind == "divergence":
|
||||
conds.append("s.kind = 'divergence'")
|
||||
elif kind == "ignition":
|
||||
conds.append("s.kind != 'divergence'")
|
||||
conds.append("s.kind = 'short_ignition'") # 做多起爆点统一不显示
|
||||
# 默认(全部)也排除做多起爆点
|
||||
if "s.kind = 'short_ignition'" not in conds and "s.kind = 'divergence'" not in conds:
|
||||
conds.append("s.kind != 'long_ignition'")
|
||||
|
||||
where = " AND ".join(conds)
|
||||
total = query(
|
||||
|
||||
@@ -151,7 +151,8 @@ def push_pending() -> None:
|
||||
FROM notifications n JOIN signals s ON s.id = n.signal_id
|
||||
JOIN devices d ON d.user_id = n.user_id AND d.rid_invalid = 0
|
||||
AND d.jpush_rid IS NOT NULL
|
||||
WHERE n.push_status = 'pending' ORDER BY s.divergence_time
|
||||
WHERE n.push_status = 'pending' AND s.kind != 'long_ignition'
|
||||
ORDER BY s.divergence_time
|
||||
LIMIT 5000
|
||||
"""
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user