0a3f2c5cc6
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json - 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档 - 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸 - 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名 - 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
142 lines
5.1 KiB
Dart
142 lines
5.1 KiB
Dart
/// 模块注册表:**唯一**需要修改的模块清单文件。
|
||
///
|
||
/// 新增模块步骤:
|
||
/// 1. 在 `lib/modules/<id>/` 下实现 `EdcModule`(或先用 `PlannedModule` 占位);
|
||
/// 2. 在本文件顶部 import 模块单例;
|
||
/// 3. 加入下方 [kModules] 列表。
|
||
///
|
||
/// 首页卡片、品牌菜单、窗口标题、文档打开 / 保存后缀、最近列表与工作区
|
||
/// 都会自动跟随注册表,不需要修改 `AppShell` / `HomeView`。
|
||
///
|
||
/// 发布级注册:`assets/modules/registry.json`(构建时复制到发布包 `modules/`)
|
||
/// 可覆盖模块顺序 / 显示名 / 颜色 / 启用状态;应用启动时优先读取发布清单,
|
||
/// 失败回退本文件。Flutter AOT 不能动态加载新的 Dart UI 代码,新增实现仍需
|
||
/// 重新构建;清单只负责发布装配与可见结构。
|
||
library;
|
||
|
||
import 'dart:io' show File, Platform;
|
||
|
||
import 'package:flutter/services.dart' show rootBundle;
|
||
|
||
import 'package:sequence_diagram/modules/architecture/architecture_module.dart';
|
||
import 'package:sequence_diagram/modules/elec/elec_module.dart';
|
||
import 'package:sequence_diagram/modules/io/io_module.dart';
|
||
import 'package:sequence_diagram/modules/manifest.dart';
|
||
import 'package:sequence_diagram/modules/module.dart';
|
||
import 'package:sequence_diagram/modules/pid/pid_module.dart';
|
||
import 'package:sequence_diagram/modules/sequence/sequence_module.dart';
|
||
import 'package:sequence_diagram/modules/topo/topo_module.dart';
|
||
|
||
export 'package:sequence_diagram/modules/module.dart';
|
||
|
||
/// 编译进应用的模块(顺序 = 默认首页 / 菜单展示顺序)。
|
||
///
|
||
/// 发布包可通过 `modules/registry.json` 覆盖顺序 / 显示名 / 启用状态;
|
||
/// 未在清单中出现的编译期模块会被隐藏。
|
||
const List<EdcModule> kCompiledModules = <EdcModule>[
|
||
architectureModule,
|
||
sequenceModule,
|
||
elecModule,
|
||
ioModule,
|
||
topoModule,
|
||
pidModule,
|
||
];
|
||
|
||
List<EdcModule> _modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||
String _moduleRegistrySource = 'compiled';
|
||
|
||
/// 当前生效的模块列表(发布清单已合并)。
|
||
List<EdcModule> get kModules => _modules;
|
||
|
||
/// 当前模块清单来源(排查发布包问题用)。
|
||
String get moduleRegistrySource => _moduleRegistrySource;
|
||
|
||
/// 初始化发布级模块清单。
|
||
///
|
||
/// 桌面优先读取 exe 同级 `modules/registry.json`;安卓 / 开发环境回退到
|
||
/// `assets/modules/registry.json`;失败时回退 [kCompiledModules]。
|
||
/// 必须在 `runApp` 前调用;运行中修改清单需要重启应用。
|
||
Future<void> initModuleRegistry({
|
||
String? manifestText,
|
||
String? manifestPath,
|
||
}) async {
|
||
String? text = manifestText;
|
||
String source = manifestText != null ? 'override' : '';
|
||
if (text == null && manifestPath != null) {
|
||
try {
|
||
final File f = File(manifestPath);
|
||
if (await f.exists()) {
|
||
text = await f.readAsString();
|
||
source = manifestPath;
|
||
}
|
||
} catch (_) {}
|
||
}
|
||
if (text == null &&
|
||
(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
||
try {
|
||
final String exeDir = File(Platform.resolvedExecutable).parent.path;
|
||
final File external = File(
|
||
'$exeDir${Platform.pathSeparator}modules${Platform.pathSeparator}registry.json',
|
||
);
|
||
if (await external.exists()) {
|
||
text = await external.readAsString();
|
||
source = external.path;
|
||
}
|
||
} catch (_) {}
|
||
}
|
||
if (text == null) {
|
||
try {
|
||
text = await rootBundle.loadString('assets/modules/registry.json');
|
||
source = 'assets/modules/registry.json';
|
||
} catch (_) {}
|
||
}
|
||
if (text == null) {
|
||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||
_moduleRegistrySource = 'compiled';
|
||
return;
|
||
}
|
||
try {
|
||
final ModuleManifest manifest = ModuleManifest.parse(text);
|
||
final List<EdcModule> resolved =
|
||
resolveModulesFromManifest(manifest, kCompiledModules);
|
||
if (resolved.isEmpty) {
|
||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||
_moduleRegistrySource = 'compiled (empty manifest)';
|
||
} else {
|
||
_modules = List<EdcModule>.unmodifiable(resolved);
|
||
_moduleRegistrySource = source;
|
||
}
|
||
} catch (_) {
|
||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||
_moduleRegistrySource = 'compiled (invalid manifest)';
|
||
}
|
||
}
|
||
|
||
/// 恢复编译期注册表(测试 / 重置用)。
|
||
void resetModuleRegistry() {
|
||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||
_moduleRegistrySource = 'compiled';
|
||
}
|
||
|
||
/// 按 id 查找模块;id 为 null / 未注册时返回 null(首页)。
|
||
EdcModule? moduleById(String? id) {
|
||
if (id == null || id.isEmpty) return null;
|
||
for (final EdcModule m in kModules) {
|
||
if (m.id == id) return m;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// 已开放模块(首页可进入)。
|
||
Iterable<EdcModule> get availableModules =>
|
||
kModules.where((EdcModule m) => m.available);
|
||
|
||
/// 品牌名(首页 / 窗口标题)。
|
||
const String kBrandName = 'PDS流程设计套件';
|
||
|
||
/// 窗口标题:首页显示品牌,模块显示「品牌 · 模块设计」。
|
||
String moduleTitle(String? moduleId) {
|
||
final EdcModule? m = moduleById(moduleId);
|
||
return m == null ? kBrandName : '$kBrandName · ${m.name}设计';
|
||
}
|