This commit is contained in:
LZX committed 2026-09-15 16:59:50 +08:00
1 parent b49e096355
commit 63e1fe3861
48 files changed
+5817 -556

No files matched your search

@@ -97,4 +97,78 @@ class RunTaskStorageService {
Future<void> saveTasks(String projectRoot, List<RunTask> tasks) async {
await saveConfig(projectRoot: projectRoot, tasks: tasks);
}
/// 获取特定模块的独立任务缓存配置文件(例如 `.code_editor/gradle_tasks.json`)
File getModuleConfigFile(String projectRoot, String moduleName) {
return File(p.join(projectRoot, configDirName, '${moduleName}_tasks.json'));
}
/// 从工程的 `.code_editor/<module>_tasks.json` 中读取模块探测出的任务与缓存元信息
Future<({List<RunTask> tasks, String? hash, DateTime? updatedAt})> loadModuleTasks(
String projectRoot,
String moduleName,
) async {
try {
final file = getModuleConfigFile(projectRoot, moduleName);
if (!await file.exists()) {
return (tasks: <RunTask>[], hash: null, updatedAt: null);
}
final content = await file.readAsString();
if (content.trim().isEmpty) {
return (tasks: <RunTask>[], hash: null, updatedAt: null);
}
final dynamic decoded = jsonDecode(content);
if (decoded is Map) {
final hash = decoded['buildScriptHash']?.toString();
final rawUpdated = decoded['updatedAt']?.toString();
final updatedAt = rawUpdated != null ? DateTime.tryParse(rawUpdated) : null;
final tasksRaw = decoded['tasks'];
final List<RunTask> list = [];
if (tasksRaw is List) {
for (final item in tasksRaw) {
if (item is Map) {
list.add(RunTask.fromJson(Map<String, dynamic>.from(item)));
}
}
}
return (tasks: list, hash: hash, updatedAt: updatedAt);
}
return (tasks: <RunTask>[], hash: null, updatedAt: null);
} catch (e) {
debugPrint('[RunTaskStorageService] 读取 ${moduleName}_tasks.json 失败: $e');
return (tasks: <RunTask>[], hash: null, updatedAt: null);
}
}
/// 将特定模块探测所得任务与缓存哈希持久化保存到 `.code_editor/<module>_tasks.json`
Future<void> saveModuleTasks({
required String projectRoot,
required String moduleName,
required List<RunTask> tasks,
String? hash,
}) async {
try {
final file = getModuleConfigFile(projectRoot, moduleName);
final dir = file.parent;
if (!await dir.exists()) {
await dir.create(recursive: true);
}
final data = {
'version': '1.0',
'module': moduleName,
'updatedAt': DateTime.now().toIso8601String(),
if (hash != null && hash.isNotEmpty) 'buildScriptHash': hash,
'tasks': tasks.map((t) => t.toJson()).toList(),
};
const encoder = JsonEncoder.withIndent(' ');
final jsonStr = encoder.convert(data);
await file.writeAsString(jsonStr, flush: true);
} catch (e) {
debugPrint('[RunTaskStorageService] 保存 ${moduleName}_tasks.json 失败: $e');
}
}
}