From 6697e53613d5ce562a19795ab41b19803c2bb93d Mon Sep 17 00:00:00 2001
From: 905086 <k2049@qq.com>
Date: Sat, 07 Nov 2026 19:26:30 +0800
Subject: [PATCH] feat(tools): 新增工具卸载功能及相关实现

---
 fluttergamebox/lib/pages/main_shell.dart |  123 +++++++++++++++++++++++++++++++++-------
 1 files changed, 101 insertions(+), 22 deletions(-)

diff --git a/fluttergamebox/lib/pages/main_shell.dart b/fluttergamebox/lib/pages/main_shell.dart
index 3b0088f..cbbac32 100644
--- a/fluttergamebox/lib/pages/main_shell.dart
+++ b/fluttergamebox/lib/pages/main_shell.dart
@@ -43,6 +43,22 @@
     ShellNav.instance.openDetail =
         (id) => setState(() => _detailGameId = id);
     ShellNav.instance.goBack = _closeDetail;
+    // 打开首页时自动弹出系统公告(内容在管理后台设置)
+    WidgetsBinding.instance.addPostFrameCallback((_) {
+      if (mounted) _showHomeAnnouncement();
+    });
+  }
+
+  /// 打开首页自动弹出公告(无公告内容则不弹出)
+  void _showHomeAnnouncement() async {
+    final res = await ApiClient.get('/api/announcements');
+    if (!mounted || res['code'] != 0) return;
+    final data = res['data'] as List;
+    if (data.isEmpty) return;
+    final content = (data[0]['content'] ?? '').toString().trim();
+    if (content.isEmpty) return;
+    if (!mounted) return;
+    _showAnnouncementDialog(context, content);
   }
 
   @override
@@ -92,7 +108,8 @@
                 height: 3,
                 color: AppColors.bgLight,
                 child: LinearProgressIndicator(
-                  value: task.progress,
+                  // 下载阶段显示下载进度,安装(解压)阶段显示解压进度
+                  value: task.extracting ? task.extractProgress : task.progress,
                   backgroundColor: Colors.transparent,
                   color: AppColors.accent,
                 ),
@@ -603,7 +620,7 @@
       case '游戏恢复':
         _showToast('游戏恢复功能:重新下载可恢复游戏文件');
       case '重启应用':
-        _showToast('应用重启中...');
+        _restartApp();
       case '检查更新':
         _showToast('当前已是最新版本!');
       case '退出应用':
@@ -611,6 +628,21 @@
     }
   }
 
+  /// 重启应用:启动新的应用进程后退出当前进程
+  Future<void> _restartApp() async {
+    try {
+      // 以分离模式启动当前应用的 exe(带原有启动参数)
+      await Process.start(
+        Platform.resolvedExecutable,
+        Platform.executableArguments,
+        mode: ProcessStartMode.detached,
+      );
+    } catch (_) {
+      // 启动失败时仍尝试退出(下次手动打开)
+    }
+    exit(0);
+  }
+
   void _showToast(String msg) {
     final ctx = context;
     // 使用全局 overlay 显示
@@ -685,6 +717,72 @@
   }
 }
 
+/// 公告弹窗(标题+内容+关闭),首页打开与左侧栏共用
+void _showAnnouncementDialog(BuildContext context, String content) {
+  showDialog(
+    context: context,
+    builder: (context) => Dialog(
+      backgroundColor: Colors.white,
+      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
+      child: Container(
+        width: 420,
+        padding: const EdgeInsets.all(24),
+        child: Column(
+          mainAxisSize: MainAxisSize.min,
+          crossAxisAlignment: CrossAxisAlignment.start,
+          children: [
+            Row(
+              children: [
+                const Icon(Icons.campaign,
+                    color: Color(0xFF2B7FFF), size: 22),
+                const SizedBox(width: 8),
+                const Text('系统公告',
+                    style: TextStyle(
+                        color: Colors.black,
+                        fontSize: 16,
+                        fontWeight: FontWeight.bold)),
+                const Spacer(),
+                GestureDetector(
+                  onTap: () => Navigator.pop(context),
+                  child: const Icon(Icons.close,
+                      color: Colors.grey, size: 20),
+                ),
+              ],
+            ),
+            const SizedBox(height: 16),
+            ConstrainedBox(
+              constraints: const BoxConstraints(maxHeight: 320),
+              child: SingleChildScrollView(
+                child: Text(
+                  content,
+                  style: const TextStyle(
+                      color: Color(0xFFE74C3C),
+                      fontSize: 13,
+                      height: 1.9),
+                ),
+              ),
+            ),
+            const SizedBox(height: 16),
+            Align(
+              alignment: Alignment.centerRight,
+              child: ElevatedButton(
+                onPressed: () => Navigator.pop(context),
+                style: ElevatedButton.styleFrom(
+                  backgroundColor: const Color(0xFF2B7FFF),
+                  foregroundColor: Colors.white,
+                  shape: RoundedRectangleBorder(
+                      borderRadius: BorderRadius.circular(4)),
+                ),
+                child: const Text('知道了'),
+              ),
+            ),
+          ],
+        ),
+      ),
+    ),
+  );
+}
+
 /// 左侧浮动栏:系统公告/联系客服/常见问题
 class _LeftSidebar extends StatelessWidget {
   const _LeftSidebar();
@@ -723,26 +821,7 @@
             (res['data'] as List).isNotEmpty
         ? res['data'][0]['content']
         : '暂无公告';
-    showDialog(
-      context: context,
-      builder: (context) => AlertDialog(
-        backgroundColor: Colors.white,
-        title: const Text('系统公告',
-            style: TextStyle(color: Colors.black, fontSize: 16)),
-        content: SizedBox(
-          width: 380,
-          child: Text('$content',
-              style:
-                  const TextStyle(color: Color(0xFFE74C3C), fontSize: 13, height: 1.9)),
-        ),
-        actions: [
-          TextButton(
-            onPressed: () => Navigator.pop(context),
-            child: const Text('知道了', style: TextStyle(color: Color(0xFF2B7FFF))),
-          ),
-        ],
-      ),
-    );
+    _showAnnouncementDialog(context, '$content');
   }
 
   void _showToast2(BuildContext context, String msg) {

--
Gitblit v1.10.0