- 启动:健康检查与设置并行请求,页面按需构建并 Offstage 保活,封面按展示尺寸解码 - UI:模型卡片增加悬停动效、封面渐变遮罩、版本/作者/标签胶囊,空简介占位 - 主题:设置页新增主色调选择(预设 + 自定义 #RRGGBB),前后端持久化并实时生效 - CI:新增 PR 审核流水线(后端编译/自检、Flutter 分析测试、漏洞与密钥扫描、汇总门禁) - CI:新增每晚 21:00(UTC 13:00)预发布流水线,prerelease 且不设为 Latest,先删旧再建新 - 安全:后端新增安全响应头、Host/Origin 校验、写入限流、请求体上限、ID 与设置白名单、错误信息脱敏 - 源:暂时只启用 Xhmcl;GitCode 实现保留但不再调用,旧配置自动迁移
124 lines
3.1 KiB
Dart
124 lines
3.1 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import 'api_client.dart';
|
|
import 'i18n.dart';
|
|
import 'theme.dart';
|
|
|
|
/// 外壳状态:后端客户端 + 设置 + 健康状态 + 更新状态条。
|
|
///
|
|
/// 各页面只读这里的数据、通过这里的方法改后端,避免每页各持一份状态。
|
|
class ShellController extends ChangeNotifier {
|
|
ShellController({GcApi? api}) : api = api ?? GcApi();
|
|
|
|
final GcApi api;
|
|
|
|
int index = 0;
|
|
SettingsInfo? settings;
|
|
HealthInfo? health;
|
|
String? loadError;
|
|
|
|
bool updateBarVisible = false;
|
|
bool updateBusy = false;
|
|
double updateProgress = 0;
|
|
String updateStatus = '';
|
|
String updateDetail = '';
|
|
String launcherNotice = '';
|
|
|
|
bool get backendReady => settings != null;
|
|
|
|
Future<void> bootstrap() async {
|
|
try {
|
|
// 健康检查与设置并行请求:两者互不依赖,串行会白白多等一次网络往返。
|
|
final healthFuture = api.health();
|
|
final settingsFuture = api.settings();
|
|
health = await healthFuture;
|
|
settings = await settingsFuture;
|
|
loadError = null;
|
|
_applySettings(settings!);
|
|
} catch (error) {
|
|
loadError = error.toString();
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
void _applySettings(SettingsInfo value) {
|
|
I18n.setLanguage(value.language);
|
|
GcPalette.apply(value.accentColor);
|
|
}
|
|
|
|
void goTo(int value) {
|
|
if (index == value) return;
|
|
index = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> reloadSettings() async {
|
|
try {
|
|
settings = await api.settings();
|
|
loadError = null;
|
|
_applySettings(settings!);
|
|
} catch (error) {
|
|
loadError = error.toString();
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> saveSettings(SettingsPatch patch) async {
|
|
try {
|
|
settings = await api.saveSettings(patch);
|
|
loadError = null;
|
|
_applySettings(settings!);
|
|
} catch (error) {
|
|
loadError = error.toString();
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
void setUpdateStatus({
|
|
bool? visible,
|
|
bool? busy,
|
|
double? progress,
|
|
String? status,
|
|
String? detail,
|
|
String? notice,
|
|
}) {
|
|
if (visible != null) updateBarVisible = visible;
|
|
if (busy != null) updateBusy = busy;
|
|
if (progress != null) updateProgress = progress;
|
|
if (status != null) updateStatus = status;
|
|
if (detail != null) updateDetail = detail;
|
|
if (notice != null) launcherNotice = notice;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// 检查模型 / 启动器更新(设置页与状态条共用)。
|
|
Future<void> checkUpdate({bool force = true}) async {
|
|
if (updateBusy) return;
|
|
setUpdateStatus(
|
|
visible: true,
|
|
busy: true,
|
|
progress: 0,
|
|
status: T('update.checking'),
|
|
detail: '',
|
|
notice: '',
|
|
);
|
|
|
|
try {
|
|
final result = await api.checkUpdate(force: force);
|
|
setUpdateStatus(
|
|
busy: false,
|
|
progress: 1,
|
|
status: result.message.isEmpty ? T('update.done') : result.message,
|
|
detail: result.error ?? '',
|
|
notice: result.launcherMessage ?? '',
|
|
);
|
|
} catch (error) {
|
|
setUpdateStatus(
|
|
busy: false,
|
|
status: T('update.offline'),
|
|
detail: error.toString(),
|
|
);
|
|
}
|
|
}
|
|
}
|