Files
GC-XH/GC-UI/frontend/lib/shell.dart
T
Morris a361c889f8 修复审计发现的问题,默认构建即带 Flutter 前端
P0
- GC-SAVEDOG:更新改为整目录替换(旧文件备份到 .GC/update/backup,
  失败可完整回滚),不再只搬一个 exe;回滚会删掉新包独有文件
- GC-SAVEDOG:包名校验放宽为单文件名模式,Linux 启动器(无扩展名)可更新
- GC-DOWNLOAD:测速全失败时不再回退 GitCode,改为返回「不可用」并保留上次可用源
- GC-DOWNLOAD:识别并赋予 Linux 无扩展名启动器可执行位;兼容脚本清理旧版时
  也覆盖无扩展名产物
- CI:删除 nightly-prerelease(绕开 build.sh,产出无前端空壳);alpha 工作流
  去掉非法 cron,只保留手动触发

P1
- 前端:主题设置真正生效(深色/浅色/跟随系统 + 持久化),去掉死字段
- 前端:下载页轮询改为自适应单次链,页面不可见或任务结束后降频/停止
- 前端:下载完成 / 删除模型后首页列表自动刷新
- 前端:复用 http.Client,不再每次轮询新建连接
- 后端:/api/models 走缓存,不再每次全盘递归统计体积
- 设置页:外部改动能同步进表单,不再只同步一次

P2
- 错误响应统一为 ErrorDto,不再复用 LaunchResultDto
- 限流桶定期清理,避免无限增长
- 播放器窗口去重,避免同一模型重复开窗
- 封面按实际格式返回,去掉错误的 image/png 与 no-store
- 端口集中到 GcUiContract,前端可用 GC_UI_PORT 或 ui-backend.json 发现后端
- 构建:Windows 包改为散开发布,与后端共用运行时(体积约 109MB -> 72MB)
- 文档:更新仓库地址与更新流程说明

测试:dotnet build 全绿;GC.Tests 更新链路全通过;flutter analyze 无问题;
flutter test 11 项全通过。
2026-11-18 20:10:03 +08:00

356 lines
10 KiB
Dart

import 'package:flutter/material.dart';
import 'controller.dart';
import 'i18n.dart';
import 'pages.dart';
import 'theme.dart';
/// 侧边栏导航项。
class _NavItem {
const _NavItem(this.icon, this.labelKey);
final IconData icon;
final String labelKey;
}
const List<_NavItem> _navItems = <_NavItem>[
_NavItem(Icons.grid_view_rounded, 'nav.home'),
_NavItem(Icons.download_rounded, 'nav.download'),
_NavItem(Icons.tune_rounded, 'nav.settings'),
_NavItem(Icons.info_outline_rounded, 'nav.about'),
];
/// 应用外壳:左侧导航 + 右侧内容 + 底部更新状态条。
class ShellPage extends StatefulWidget {
const ShellPage({super.key, required this.controller});
final ShellController controller;
@override
State<ShellPage> createState() => _ShellPageState();
}
class _ShellPageState extends State<ShellPage> {
/// 页面缓存:键为「索引:语言」。同一个页面只构建一次,切走时用
/// [Offstage] 保活(不参与布局/绘制),切回来无需重建、状态也不丢。
final Map<String, Widget> _pages = <String, Widget>{};
@override
void initState() {
super.initState();
widget.controller.bootstrap();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: widget.controller,
builder: (context, _) {
final controller = widget.controller;
return Scaffold(
backgroundColor: GcColors.appBg,
body: Row(
children: <Widget>[
_Sidebar(controller: controller),
Expanded(
child: Column(
children: <Widget>[
Expanded(child: _content(controller)),
if (controller.updateBarVisible)
_UpdateBar(controller: controller),
],
),
),
],
),
);
},
);
}
Widget _content(ShellController controller) {
if (!controller.backendReady) {
if (controller.loadError != null) {
return _BackendDown(controller: controller);
}
return const Center(
child: SizedBox(
width: 26,
height: 26,
child: CircularProgressIndicator(strokeWidth: 2.4),
),
);
}
// 只构建当前页;其余已访问页面保留在树上但处于 Offstage。
final key = '${controller.index}:${I18n.language.value}';
_pages.putIfAbsent(key, () => _buildPage(controller, controller.index));
final visibleKey = key;
return Stack(
children: <Widget>[
for (final entry in _pages.entries)
Offstage(
offstage: entry.key != visibleKey,
child: TickerMode(
enabled: entry.key == visibleKey,
child: entry.value,
),
),
],
);
}
Widget _buildPage(ShellController controller, int index) {
switch (index) {
case 1:
return DownloadPageView(controller: controller);
case 2:
return SettingsPageView(controller: controller);
case 3:
return AboutPageView(controller: controller);
default:
return HomePageView(controller: controller);
}
}
}
class _Sidebar extends StatelessWidget {
const _Sidebar({required this.controller});
final ShellController controller;
@override
Widget build(BuildContext context) {
final settings = controller.settings;
return Container(
width: 236,
color: GcColors.sideBg,
padding: const EdgeInsets.fromLTRB(16, 20, 16, 18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 26,
height: 26,
decoration: BoxDecoration(
color: GcColors.surfaceAlt,
borderRadius: BorderRadius.circular(8),
),
alignment: Alignment.center,
child: Text(
'◎',
style: TextStyle(fontSize: 14, color: GcColors.accent),
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
'Morris GC',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
),
],
),
const SizedBox(height: 6),
GcHint(T('app.tagline')),
const SizedBox(height: 26),
const Padding(
padding: EdgeInsets.only(left: 14, bottom: 6),
child: Text(
'MENU',
style: TextStyle(
fontSize: 9.5,
letterSpacing: 1.2,
fontWeight: FontWeight.w600,
color: Color(0xFF4C5F80),
),
),
),
for (var i = 0; i < _navItems.length; i++)
_NavButton(
item: _navItems[i],
active: controller.index == i,
onTap: () => controller.goTo(i),
),
const Spacer(),
Container(height: 1, color: GcColors.line),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.only(left: 14),
child: Text(
'v${settings?.version ?? '—'}',
style: TextStyle(fontSize: 10.5, color: GcColors.faint),
),
),
Padding(
padding: const EdgeInsets.only(left: 14, top: 2),
child: Text(
settings?.platform ?? '—',
style: const TextStyle(fontSize: 10, color: Color(0xFF4F6080)),
),
),
],
),
);
}
}
class _NavButton extends StatelessWidget {
const _NavButton({
required this.item,
required this.active,
required this.onTap,
});
final _NavItem item;
final bool active;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Material(
color: active ? GcColors.surfaceAlt : Colors.transparent,
borderRadius: BorderRadius.circular(9),
child: InkWell(
borderRadius: BorderRadius.circular(9),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
child: Row(
children: <Widget>[
Icon(
item.icon,
size: 16,
color: active ? GcColors.accent : GcColors.faint,
),
const SizedBox(width: 10),
Text(
T(item.labelKey),
style: TextStyle(
fontSize: 12.5,
fontWeight: active ? FontWeight.w600 : FontWeight.w400,
color: active ? GcColors.ink : GcColors.muted,
),
),
],
),
),
),
),
);
}
}
class _UpdateBar extends StatelessWidget {
const _UpdateBar({required this.controller});
final ShellController controller;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: GcColors.surface,
border: Border(top: BorderSide(color: GcColors.line)),
),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 9),
child: Row(
children: <Widget>[
Text('⟳',
style: TextStyle(fontSize: 16, color: GcColors.accent)),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
controller.updateStatus,
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
overflow: TextOverflow.ellipsis,
),
if (controller.updateDetail.isNotEmpty)
Text(
controller.updateDetail,
style: TextStyle(fontSize: 11, color: GcColors.faint),
overflow: TextOverflow.ellipsis,
),
if (controller.launcherNotice.isNotEmpty)
Text(
controller.launcherNotice,
style: TextStyle(fontSize: 11, color: GcColors.warn),
),
],
),
),
if (controller.updateBusy)
const SizedBox(
width: 130,
child: LinearProgressIndicator(minHeight: 4),
),
const SizedBox(width: 14),
TextButton(
onPressed: controller.updateBusy
? null
: () => controller.checkUpdate(force: true),
child: Text(T('update.checkNow')),
),
],
),
);
}
}
class _BackendDown extends StatelessWidget {
const _BackendDown({required this.controller});
final ShellController controller;
@override
Widget build(BuildContext context) {
return Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 520),
child: GcCard(
padding: const EdgeInsets.all(28),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
T('common.error'),
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
const SizedBox(height: 10),
GcHint(controller.loadError ?? ''),
const SizedBox(height: 6),
GcHint('后端地址:${controller.api.baseUrl}'),
const SizedBox(height: 16),
FilledButton(
onPressed: controller.bootstrap,
child: Text(T('common.retry')),
),
],
),
),
),
);
}
}