Skip to content

feat: Java有关重构#11

Open
futurw4v wants to merge 16 commits into
lxdklp:mainfrom
futurw4v:feature/java_manager
Open

feat: Java有关重构#11
futurw4v wants to merge 16 commits into
lxdklp:mainfrom
futurw4v:feature/java_manager

Conversation

@futurw4v
Copy link
Copy Markdown
Contributor

@futurw4v futurw4v commented May 3, 2026

重构内容:

  • 将Java初始化有关任务与UI分离,抽出至java_service.dart,将java_manager.dart重命名为java_utils.dart
  • 移除搜索Java(searchPotentialJavaExecutables)内的遍历,在Windows下采用搜索注册表的方法(参考PCL2),对于Mac与Linux没有地方测试(
  • 将SharedPreference中的java更改为javaSelectedPath,添加javaRuntimes缓存Java的信息
  • 重构java.dart,添加了刷新Java与手动添加Java
  • 更改了MainStartPageState内检测Java是否存在的逻辑
  • 优化代码与部分逻辑
  • 添加了插件open_filex,win32_registry

实在是铲不动了太多东西要改的了
没有ChangeNotifier真的很难改,这算前面挖的坑了
所以Java部分先改到这 (•_•),我打算开始改UI了

对了最好在contribution.md里面提一嘴统一PUB_HOSTED_URL和FLUTTER_STORAGE_BASE_URL,在我这里很容易因为pub get一下pubspec.lock就会迎来大变

实际上还是有点问题的 在初始化java的时候会阻塞UI,但是改这个要动很多东西所以没打算在现在弄

希望能早点合并喵

@lxdklp
Copy link
Copy Markdown
Owner

lxdklp commented May 3, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +67 to +69
await Isolate.run(() {
JavaService.refreshJavaRuntimes();
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Isolate.run 中调用 JavaService.refreshJavaRuntimes() 存在以下问题:

  1. 内存隔离Isolate 之间不共享内存。在子 Isolate 中更新 JavaService 的静态变量 _javaRuntimes 不会影响主 Isolate 中的数据,导致 UI 无法看到刷新结果。
  2. 插件限制SharedPreferences 插件通常依赖于主 Isolate 的平台通道,在后台 Isolate 中直接调用 getInstance() 可能会抛出 MissingPluginException

建议在 Isolate 中仅执行纯 CPU 或阻塞式的搜索逻辑(如 JavaUtils.searchPotentialJavaExecutables),并将结果返回给主 Isolate 进行状态更新和持久化。

),
Row(
// 使按钮组紧贴
mainAxisSize: MainAxisSize.min,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Row 中设置 mainAxisSize: MainAxisSize.min 的同时使用 Spacer()(第 57 行)会导致布局冲突。Spacer 会尝试占据所有可用空间,而 min 要求 Row 尽可能缩小,这通常会导致渲染错误或 Spacer 失效。建议将 RowmainAxisSize 改为默认的 max

References
  1. Avoid using Spacer or Expanded inside a Row/Column with MainAxisSize.min as it leads to layout constraints issues.

vendor: parsedVersion['vendor'],
path: executablePath,
os: Platform.operatingSystem,
arch: Platform.version,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Platform.version 返回的是 Dart SDK 的版本信息字符串(例如 "3.0.0 ..."),而非系统架构。建议使用 Platform.executableArchitecture 来获取正确的架构信息(如 'x64' 或 'arm64')。

Comment thread lib/function/java/java_utils.dart
Comment on lines +147 to +157
static set javaSelectedPath(String newPath) {
if (newPath == _javaSelectedPath) return;

final newFile = File(newPath);

if (!newFile.existsSync()) {
throw ArgumentError('路径不存在: $newPath');
}

_javaSelectedPath = newPath;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

静态 setter javaSelectedPath 仅更新了内存中的变量,未同步更新 SharedPreferences。这会导致用户在 UI 中看到的更改在应用重启后丢失。建议在该 setter 中同步更新缓存,或者统一使用 setSelectedJavaPathToPrefs 方法。

@lxdklp
Copy link
Copy Markdown
Owner

lxdklp commented May 3, 2026

镜像源这个倒是没必要规定,自己觉得哪个镜像源快或者是用官方源也没啥所谓,反正应该也没人看pubspec.lock的变更

@futurw4v
Copy link
Copy Markdown
Contributor Author

futurw4v commented May 3, 2026

镜像源这个倒是没必要规定,自己觉得哪个镜像源快或者是用官方源也没啥所谓,反正应该也没人看pubspec.lock的变更

主要是会一直在提交列表里

Comment thread CONTRIBUTING.md
| Game_$name | 版本列表 | list(string) |
| java | Java路径 | string |
| javaSelectedPath | 所选Java路径 | string |
| javaRuntimes | Java运行时列表(以JSON格式存储) | string |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image 在dart拿string存json看着有点奇怪,而且也完全没必要吧,对于启动来说只需要知道javaSelectedPath就足够了,启动时也只需要确保javaSelectedPath是存在的就行,Java运行时列表在管理Java时能看到就只够了,缓存这个意义不大感觉🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为只存javaSelectedPath会很卡

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

存Json可以更方便的反实例化 如果不存每次打开都要全量搜索

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants