feat: 服务器断线提醒; fix: 强制子项目 Java 17 消除源值8警告
This commit is contained in:
1 parent
e868493bb6
commit
3404ffe83a
2 files changed
+69
-1
No files matched your search
@@ -63,3 +63,21 @@ subprojects {
|
|||||||
tasks.register<Delete>("clean") {
|
tasks.register<Delete>("clean") {
|
||||||
delete(rootProject.layout.buildDirectory)
|
delete(rootProject.layout.buildDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 强制所有子项目(含插件模块)使用 Java 17,消除 "源值 8/目标值 8 已过时" 警告
|
||||||
|
gradle.beforeProject {
|
||||||
|
if (project != rootProject) {
|
||||||
|
tasks.withType(JavaCompile::class.java).configureEach {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17.toString()
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17.toString()
|
||||||
|
}
|
||||||
|
plugins.withId("com.android.library") {
|
||||||
|
extensions.findByType(com.android.build.api.dsl.LibraryExtension::class.java)?.apply {
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import '../../app.dart' show navigatorKey;
|
||||||
import '../../providers/rcon_provider.dart';
|
import '../../providers/rcon_provider.dart';
|
||||||
import '../../providers/server_provider.dart';
|
import '../../providers/server_provider.dart';
|
||||||
import '../download/download_page.dart';
|
import '../download/download_page.dart';
|
||||||
@@ -18,24 +20,72 @@ class DashboardPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _DashboardPageState extends State<DashboardPage> {
|
class _DashboardPageState extends State<DashboardPage> {
|
||||||
Map<String, ServerStatus> _status = {};
|
Map<String, ServerStatus> _status = {};
|
||||||
|
Timer? _pollTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_refreshAll();
|
_refreshAll();
|
||||||
|
// 每 5 秒轮询一次,用于断线提醒
|
||||||
|
_pollTimer = Timer.periodic(const Duration(seconds: 5), (_) => _refreshAll(alertOnDrop: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _refreshAll() async {
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_pollTimer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _refreshAll({bool alertOnDrop = false}) async {
|
||||||
final rcon = context.read<RconProvider>();
|
final rcon = context.read<RconProvider>();
|
||||||
final servers = context.read<ServerProvider>().servers;
|
final servers = context.read<ServerProvider>().servers;
|
||||||
final map = <String, ServerStatus>{};
|
final map = <String, ServerStatus>{};
|
||||||
for (final s in servers) {
|
for (final s in servers) {
|
||||||
map[s.id] = await rcon.checkStatus(s);
|
map[s.id] = await rcon.checkStatus(s);
|
||||||
|
if (!mounted) return;
|
||||||
|
}
|
||||||
|
// 断线检测:上一轮在线、这一轮离线 → 弹出提醒
|
||||||
|
if (alertOnDrop) {
|
||||||
|
for (final s in servers) {
|
||||||
|
final prev = _status[s.id];
|
||||||
|
final now = map[s.id];
|
||||||
|
if ((prev?.online ?? false) && !(now?.online ?? false)) {
|
||||||
|
_showDisconnectAlert(s.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _status = map);
|
setState(() => _status = map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 断线提醒:页面内 SnackBar + 顶部全局提示。
|
||||||
|
void _showDisconnectAlert(String serverName) {
|
||||||
|
final nav = navigatorKey.currentContext;
|
||||||
|
if (nav == null) return;
|
||||||
|
final messenger = ScaffoldMessenger.maybeOf(nav);
|
||||||
|
if (messenger == null) return;
|
||||||
|
messenger.clearSnackBars();
|
||||||
|
messenger.showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
duration: const Duration(seconds: 5),
|
||||||
|
backgroundColor: Colors.red.shade700,
|
||||||
|
content: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.warning_amber_rounded, color: Colors.white),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(child: Text('⚠️ 服务器「$serverName」已断开连接!')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: '知道了',
|
||||||
|
textColor: Colors.white,
|
||||||
|
onPressed: messenger.hideCurrentSnackBar,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final servers = context.watch<ServerProvider>().servers;
|
final servers = context.watch<ServerProvider>().servers;
|
||||||
|
|||||||
Reference in new issue
Block a user