905086
2026-11-07 7fd2270570811c0d29f0d5d87d11bfc4612e0743
fluttergamebox/lib/pages/main_shell.dart
@@ -12,6 +12,7 @@
import 'package:fluttergamebox/widgets/activate_dialog.dart';
import 'package:fluttergamebox/widgets/download_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';
import 'package:fluttergamebox/widgets/info_dialogs.dart';
import 'package:fluttergamebox/widgets/window_controls.dart';
@@ -42,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
@@ -91,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,
                ),
@@ -133,7 +151,15 @@
  Widget _buildTopBar() {
    return GestureDetector(
      onDoubleTap: () {},
      // 拖动顶栏移动窗口;双击最大化/还原
      onPanStart: (_) => windowManager.startDragging(),
      onDoubleTap: () async {
        if (await windowManager.isMaximized()) {
          windowManager.unmaximize();
        } else {
          windowManager.maximize();
        }
      },
      child: Container(
        height: 52,
        color: const Color(0xFF191C2B),
@@ -151,12 +177,12 @@
                      height: 28,
                      color: AppColors.pink,
                      child: const Center(
                          child: Text('99',
                          child: Text('游',
                              style: TextStyle(
                                  color: Colors.white, fontSize: 11))))),
            ),
            const SizedBox(width: 8),
            const Text('99游戏盒子',
            const Text('游趣电玩',
                style: TextStyle(
                    color: Colors.white,
                    fontSize: 14,
@@ -594,7 +620,7 @@
      case '游戏恢复':
        _showToast('游戏恢复功能:重新下载可恢复游戏文件');
      case '重启应用':
        _showToast('应用重启中...');
        _restartApp();
      case '检查更新':
        _showToast('当前已是最新版本!');
      case '退出应用':
@@ -602,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 显示
@@ -676,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();
@@ -714,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) {