This commit is contained in:
LZX committed 2026-09-16 20:43:39 +08:00
1 parent 5efc778165
commit 59125d185c
64 files changed
+7912 -1393

No files matched your search

+156
View File
@@ -0,0 +1,156 @@
import 'package:flutter/foundation.dart';
/// 通知条目类型(决定默认配色与图标)
enum NoticeKind {
/// 进行中(带进度圈)
progress,
/// 已完成
success,
/// 失败(默认保留到手动关闭)
failure,
/// 纯信息
info,
}
/// 探测阶段(对应 l10n 文案 key)
///
/// 队列线性执行:每个模块依次经历
/// [queued] 排队 → [checkingDependency] 依赖检测 → [installingDependency] 自动补全
/// → [detecting] 执行探测 → [finalizing] 结果整理。
enum ProbeNoticePhase { queued, checkingDependency, installingDependency, detecting, finalizing }
/// 探测失败分类(对应 l10n 文案 key)
enum NoticeFailure {
toolchainMissing,
dependencyInstallFailed,
executionFailed,
unparsable,
timeout,
}
/// 结构化通知文案:**模型层不含任何用户可见字符串**,
/// 实际文字由 UI 层 `resolveNoticeDisplay()` 通过 l10n 解析(禁止硬编码)。
sealed class NoticeText {
const NoticeText();
}
/// 模块探测阶段文案:排队 / 依赖检测 / 自动补全 / 执行探测 / 整理
class ModulePhaseText extends NoticeText {
/// 模块展示名(如 'Gradle',来自 ProjectModule.displayName,不是文案)
final String moduleDisplayName;
final ProbeNoticePhase phase;
/// 可选技术细节(例如安装过程中的最后一行输出),展示为副标题
final String? detail;
const ModulePhaseText({
required this.moduleDisplayName,
required this.phase,
this.detail,
});
}
/// 模块探测完成(带发现的任务数)
class ModuleDoneText extends NoticeText {
final String moduleDisplayName;
final int taskCount;
const ModuleDoneText(this.moduleDisplayName, {this.taskCount = 0});
}
/// 整轮探测因超出时间预算而中止(已完成 [completed]/[total] 个模块)
class ProbeBudgetExceededText extends NoticeText {
final int completed;
final int total;
const ProbeBudgetExceededText({required this.completed, required this.total});
}
/// 模块探测失败(带失败分类与可选技术细节,如缺失的工具名 / stderr 末尾)
class ModuleFailureText extends NoticeText {
final String moduleDisplayName;
final NoticeFailure failure;
final String? detail;
const ModuleFailureText({
required this.moduleDisplayName,
required this.failure,
this.detail,
});
}
/// 一条通知(业务无关:任务探测、以后的下载/编译进度都可复用)
@immutable
class NoticeItem {
/// 稳定标识(如 'probe:gradle'),用于插入/移除动画定位与就地更新
final String id;
final NoticeKind kind;
final NoticeText text;
/// 0..1 进度;null 表示不定进度
final double? progress;
/// 完成后是否必须由用户手动关闭(失败场景用)
final bool sticky;
/// 完成后延时自动关闭(成功场景用)
final Duration? autoCloseAfter;
/// 用户点击 × 时的附加动作(例如"正在探测"的通知被关闭 => 取消探测)
final VoidCallback? onUserDismiss;
/// 关闭前是否需要二次确认(破坏性操作,例如取消正在进行的探测)
final bool confirmBeforeDismiss;
const NoticeItem({
required this.id,
required this.kind,
required this.text,
this.progress,
this.sticky = false,
this.autoCloseAfter,
this.onUserDismiss,
this.confirmBeforeDismiss = false,
});
NoticeItem copyWith({
NoticeKind? kind,
NoticeText? text,
double? progress,
bool? sticky,
Duration? autoCloseAfter,
bool? confirmBeforeDismiss,
bool clearProgress = false,
bool clearAutoClose = false,
}) {
return NoticeItem(
id: id,
kind: kind ?? this.kind,
text: text ?? this.text,
progress: clearProgress ? null : (progress ?? this.progress),
sticky: sticky ?? this.sticky,
autoCloseAfter:
clearAutoClose ? null : (autoCloseAfter ?? this.autoCloseAfter),
onUserDismiss: onUserDismiss,
confirmBeforeDismiss: confirmBeforeDismiss ?? this.confirmBeforeDismiss,
);
}
@override
bool operator ==(Object other) =>
other is NoticeItem &&
other.id == id &&
other.kind == kind &&
other.text == text &&
other.progress == progress &&
other.sticky == sticky &&
other.autoCloseAfter == autoCloseAfter;
@override
int get hashCode =>
Object.hash(id, kind, text, progress, sticky, autoCloseAfter);
}
+48
View File
@@ -0,0 +1,48 @@
import 'run_task.dart';
import 'run_task_type.dart';
/// 当前工程的系统任务内存表:**类型 → 任务数组**(哈希表)。
///
/// * 进入项目时逐类型加载;
/// * 某个模块探测完成,就只写入自己类型那一格([replaceType]);
/// * UI 按类型逐段渲染([nonEmptyTypes] 给出非空类型,顺序即枚举顺序)。
class ProjectTaskTable {
final Map<RunTaskType, List<RunTask>> _byType = {
for (final type in RunTaskType.values) type: <RunTask>[],
};
List<RunTask> tasksOf(RunTaskType type) => List.unmodifiable(_byType[type] ?? const []);
/// 非空类型(按枚举顺序,即 UI 展示顺序)
List<RunTaskType> get nonEmptyTypes =>
[for (final type in RunTaskType.values) if ((_byType[type] ?? const []).isNotEmpty) type];
bool get isEmpty => _byType.values.every((tasks) => tasks.isEmpty);
int get totalCount => _byType.values.fold(0, (sum, tasks) => sum + tasks.length);
/// 模块探测完成 -> 覆盖写入自己类型那一格
void replaceType(RunTaskType type, List<RunTask> tasks) {
_byType[type] = List<RunTask>.from(tasks);
}
/// 用户自定义任务写入 user 类型
void setUserTasks(List<RunTask> tasks) => replaceType(RunTaskType.user, tasks);
void clear() {
for (final type in RunTaskType.values) {
_byType[type] = <RunTask>[];
}
}
/// 按类型顺序展开的全部任务(用户任务在最后)
List<RunTask> get allOrdered => [
for (final type in RunTaskType.values) ...?_byType[type],
];
/// 全部探测任务(不含用户自定义任务)
List<RunTask> get detectedTasks => [
for (final type in RunTaskType.values)
if (type != RunTaskType.user) ...?_byType[type],
];
}
+62
View File
@@ -0,0 +1,62 @@
import 'run_task.dart';
/// 内置任务类型(完全可枚举):UI 按"类型 → 具体任务"分组呈现。
///
/// 顺序即 UI 展示顺序;[user] 永远在最后。
/// 每个探测模块对应一个类型,模块探测出的任务只写入自己类型那一格。
enum RunTaskType {
gradle,
cmake,
cargo,
npm,
make,
dart,
/// 未映射到内置类型模块的探测任务(例如运行时注册的自定义模块)
other,
singleFile,
user;
/// 该类型对应的模块 id(非模块类型返回 null)
String? get moduleId => switch (this) {
RunTaskType.gradle => 'gradle',
RunTaskType.cmake => 'cmake',
RunTaskType.cargo => 'cargo',
RunTaskType.npm => 'npm',
RunTaskType.make => 'make',
RunTaskType.dart => 'dart',
RunTaskType.other => null,
RunTaskType.singleFile => null,
RunTaskType.user => null,
};
/// 是否为"可执行真实自省/可重新同步"的模块类型
bool get isModuleType => moduleId != null;
/// 类型展示名(模块类型为专有名词,不做本地化;用户任务/单文件走 l10n)
static const Map<String, RunTaskType> _byModuleId = {
'gradle': RunTaskType.gradle,
'cmake': RunTaskType.cmake,
'cargo': RunTaskType.cargo,
'npm': RunTaskType.npm,
'make': RunTaskType.make,
'dart': RunTaskType.dart,
};
/// 模块 id -> 类型
static RunTaskType? fromModuleId(String? moduleId) {
if (moduleId == null || moduleId.isEmpty) return null;
return _byModuleId[moduleId];
}
/// 单条任务归属的类型
static RunTaskType ofTask(RunTask task) {
if (task.source == TaskSource.custom) return RunTaskType.user;
final byModule = fromModuleId(task.moduleId);
if (byModule != null) return byModule;
if (task.group == 'single_file') return RunTaskType.singleFile;
// 有模块归属但未映射到内置类型(自定义模块)-> other;其它无模块任务才算用户可见兜底
if (task.moduleId != null && task.moduleId!.isNotEmpty) return RunTaskType.other;
return RunTaskType.user;
}
}