feat: Java有关重构#11
Conversation
…初始化、设置等逻辑移动到JavaService内
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust Java management system, featuring a new JavaService for runtime state management and enhanced discovery logic in JavaUtils that includes Windows registry scanning. The UI has been updated to support manual Java path selection, runtime refreshing, and macOS-specific menu integrations. My feedback highlights several critical issues: the use of Isolate.run for refreshing runtimes will fail due to memory isolation and plugin limitations, a layout conflict exists between MainAxisSize.min and Spacer in the settings page, Platform.version is incorrectly used for architecture detection, registry handles lack proper resource cleanup, and the javaSelectedPath setter fails to persist changes to storage.
| await Isolate.run(() { | ||
| JavaService.refreshJavaRuntimes(); | ||
| }); |
There was a problem hiding this comment.
在 Isolate.run 中调用 JavaService.refreshJavaRuntimes() 存在以下问题:
- 内存隔离:
Isolate之间不共享内存。在子Isolate中更新JavaService的静态变量_javaRuntimes不会影响主Isolate中的数据,导致 UI 无法看到刷新结果。 - 插件限制:
SharedPreferences插件通常依赖于主Isolate的平台通道,在后台Isolate中直接调用getInstance()可能会抛出MissingPluginException。
建议在 Isolate 中仅执行纯 CPU 或阻塞式的搜索逻辑(如 JavaUtils.searchPotentialJavaExecutables),并将结果返回给主 Isolate 进行状态更新和持久化。
| ), | ||
| Row( | ||
| // 使按钮组紧贴 | ||
| mainAxisSize: MainAxisSize.min, |
There was a problem hiding this comment.
| vendor: parsedVersion['vendor'], | ||
| path: executablePath, | ||
| os: Platform.operatingSystem, | ||
| arch: Platform.version, |
| static set javaSelectedPath(String newPath) { | ||
| if (newPath == _javaSelectedPath) return; | ||
|
|
||
| final newFile = File(newPath); | ||
|
|
||
| if (!newFile.existsSync()) { | ||
| throw ArgumentError('路径不存在: $newPath'); | ||
| } | ||
|
|
||
| _javaSelectedPath = newPath; | ||
| } |
|
镜像源这个倒是没必要规定,自己觉得哪个镜像源快或者是用官方源也没啥所谓,反正应该也没人看pubspec.lock的变更 |
主要是会一直在提交列表里 |
| | Game_$name | 版本列表 | list(string) | | ||
| | java | Java路径 | string | | ||
| | javaSelectedPath | 所选Java路径 | string | | ||
| | javaRuntimes | Java运行时列表(以JSON格式存储) | string | |
There was a problem hiding this comment.
因为只存javaSelectedPath会很卡
There was a problem hiding this comment.
存Json可以更方便的反实例化 如果不存每次打开都要全量搜索

重构内容:
searchPotentialJavaExecutables)内的遍历,在Windows下采用搜索注册表的方法(参考PCL2),对于Mac与Linux没有地方测试(java更改为javaSelectedPath,添加javaRuntimes缓存Java的信息实在是铲不动了太多东西要改的了
没有ChangeNotifier真的很难改,这算前面挖的坑了
所以Java部分先改到这 (•_•),我打算开始改UI了
对了最好在contribution.md里面提一嘴统一PUB_HOSTED_URL和FLUTTER_STORAGE_BASE_URL,在我这里很容易因为
pub get一下pubspec.lock就会迎来大变实际上还是有点问题的 在初始化java的时候会阻塞UI,但是改这个要动很多东西所以没打算在现在弄
希望能早点合并喵