Skip to content

Commit 362969d

Browse files
Glavo3gf8jv4dv
andauthored
使用 Java 8 启动启动器时弹出弃用警告 (#3938)
* 使用 Java 8 启动启动器时弹出弃用警告 * Update HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com> * Update HMCL/src/main/resources/assets/lang/I18N.properties Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com> * Update HMCL/src/main/resources/assets/lang/I18N_zh.properties Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com> --------- Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
1 parent fb37e3b commit 362969d

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.jackhuang.hmcl.Metadata;
4343
import org.jackhuang.hmcl.game.ModpackHelper;
4444
import org.jackhuang.hmcl.java.JavaManager;
45+
import org.jackhuang.hmcl.java.JavaRuntime;
4546
import org.jackhuang.hmcl.setting.*;
4647
import org.jackhuang.hmcl.task.Task;
4748
import org.jackhuang.hmcl.task.TaskExecutor;
@@ -62,6 +63,7 @@
6263
import org.jackhuang.hmcl.util.platform.OperatingSystem;
6364

6465
import java.io.File;
66+
import java.util.EnumSet;
6567
import java.util.List;
6668
import java.util.concurrent.CompletableFuture;
6769

@@ -70,6 +72,8 @@
7072
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
7173

7274
public final class Controllers {
75+
public static final String JAVA_VERSION_TIP = "javaVersion";
76+
7377
public static final int MIN_WIDTH = 800 + 2 + 16; // bg width + border width*2 + shadow width*2
7478
public static final int MIN_HEIGHT = 450 + 2 + 40 + 16; // bg height + border width*2 + toolbar height + shadow width*2
7579
public static final Screen SCREEN = Screen.getPrimary();
@@ -307,6 +311,51 @@ public static void initialize(Stage stage) {
307311
}
308312
}
309313

314+
if (JavaRuntime.CURRENT_VERSION < 10) {
315+
Integer shownTipVersion = null;
316+
317+
try {
318+
shownTipVersion = (Integer) config().getShownTips().get(JAVA_VERSION_TIP);
319+
} catch (ClassCastException e) {
320+
LOG.warning("Invalid type for shown tips key: " + JAVA_VERSION_TIP, e);
321+
}
322+
323+
if (shownTipVersion == null || shownTipVersion < 11) {
324+
String downloadLink = null;
325+
326+
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX && Architecture.SYSTEM_ARCH == Architecture.LOONGARCH64_OW)
327+
downloadLink = "https://www.loongnix.cn/zh/api/java/downloads-jdk21/index.html";
328+
else {
329+
330+
EnumSet<Architecture> supportedArchitectures;
331+
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS)
332+
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.X86, Architecture.ARM64);
333+
else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX)
334+
supportedArchitectures = EnumSet.of(
335+
Architecture.X86_64, Architecture.X86,
336+
Architecture.ARM64, Architecture.ARM32,
337+
Architecture.RISCV64, Architecture.LOONGARCH64
338+
);
339+
else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS)
340+
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.ARM64);
341+
else
342+
supportedArchitectures = EnumSet.noneOf(Architecture.class);
343+
344+
if (supportedArchitectures.contains(Architecture.SYSTEM_ARCH))
345+
downloadLink = String.format("https://docs.hmcl.net/downloads/%s/%s.html",
346+
OperatingSystem.CURRENT_OS.getCheckedName(),
347+
Architecture.SYSTEM_ARCH.getCheckedName()
348+
);
349+
}
350+
351+
MessageDialogPane.Builder builder = new MessageDialogPane.Builder(i18n("fatal.deprecated_java_version"), null, MessageType.WARNING);
352+
if (downloadLink != null)
353+
builder.addHyperLink(i18n("fatal.deprecated_java_version.download_link", 21), downloadLink);
354+
Controllers.dialog(builder
355+
.ok(() -> config().getShownTips().put(JAVA_VERSION_TIP, 11))
356+
.build());
357+
}
358+
}
310359

311360
if (globalConfig().getAgreementVersion() < 1) {
312361
JFXDialogLayout agreementPane = new JFXDialogLayout();

HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ public Builder(String text, String title, MessageType type) {
160160
this.dialog = new MessageDialogPane(text, title, type);
161161
}
162162

163+
public Builder addHyperLink(String text, String externalLink) {
164+
JFXHyperlink link = new JFXHyperlink(text);
165+
link.setExternalLink(externalLink);
166+
dialog.actions.getChildren().add(link);
167+
return this;
168+
}
169+
163170
public Builder addAction(Node actionNode) {
164171
dialog.addButton(actionNode);
165172
actionNode.getStyleClass().add("dialog-accept");

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ fatal.apply_update_failure=We are sorry, but Hello Minecraft! Launcher is unable
395395
fatal.apply_update_need_win7=Hello Minecraft! Launcher cannot automatically update on Windows XP/Vista.\n\
396396
\n\
397397
You can update manually by downloading a newer launcher version from %s.
398+
fatal.deprecated_java_version=HMCL will require Java 11 or later to run in the future, but will still support launching games with Java 8.\n\
399+
\n\
400+
It is recommended to install the latest version of Java to ensure that HMCL works properly.\n\
401+
\n\
402+
You can continue to keep the old version of Java. HMCL can recognize and manage multiple Java versions and will automatically select the appropriate Java for you based on the game version.
403+
fatal.deprecated_java_version.download_link=Download Java %d
398404
fatal.samba=If you opened Hello Minecraft! Launcher from a Samba network drive, some features might not be working. Please try updating your Java or moving the launcher to another directory.
399405
fatal.illegal_char=Your user path contains an illegal character "=". You will not be able to use authlib-injector or change the skin of your offline account.
400406
fatal.unsupported_platform=Minecraft is not fully supported on your platform yet, so you may experience missing features or even be unable to launch the game.\n\

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ fatal.mac_app_translocation=由於 macOS 的安全機制,Hello Minecraft! Laun
377377
fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即將升級完成,請重新開啟 HMCL。
378378
fatal.apply_update_failure=我們很抱歉 Hello Minecraft! Launcher 無法自動完成升級程式,因為出現了一些問題。\n但你依然可以從 %s 處手動下載 HMCL 來完成升級。
379379
fatal.apply_update_need_win7=Hello Minecraft! Launcher 無法在 Windows XP/Vista 上進行自動更新,請從 %s 處手動下載 HMCL 來完成升級。
380+
fatal.deprecated_java_version=HMCL 未來需要 Java 11 或更高版本才能執行,但依然支援使用 Java 8 啟動遊戲。建議安裝最新版本的 Java 以確保 HMCL 正常執行。\n你可以繼續保留舊版本 Java。HMCL 能夠識別與管理多個 Java,並會自動根據遊戲版本為你選取合適的 Java。
381+
fatal.deprecated_java_version.download_link=下載 Java %d
380382
fatal.samba=如果您正在透過 Samba 共亯的目錄中開啟 Hello Minecraft! Launcher,啟動器可能無法正常工作,請嘗試更新您的 Java 或在本機目錄內開啟 HMCL。
381383
fatal.illegal_char=由於您的使用者目錄路徑中存在無效字元『=』,您將無法使用外部登入帳戶以及離線登入更換外觀功能。
382384
fatal.unsupported_platform=Minecraft 尚未你您的平臺提供完善支援,所以可能影響遊戲體驗或無法啟動遊戲。\n若無法啟動 Minecraft 1.17 及更高版本,可以嘗試在「(全域/實例特定) 遊戲設定 → 進階設定 → 除錯選項」中將「繪製器」切換為「軟繪製器」,以獲得更好的相容性。

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ fatal.mac_app_translocation=由于 macOS 的安全机制,Hello Minecraft! Laun
386386
fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即将完成升级,请重新打开 HMCL。\n如遇到问题,你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
387387
fatal.apply_update_failure=我们很抱歉 Hello Minecraft! Launcher 无法自动完成升级,因为出现了一些问题。\n但你依可以从 %s 手动下载 HMCL 来完成升级。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
388388
fatal.apply_update_need_win7=Hello Minecraft! Launcher 无法在 Windows XP/Vista 上进行自动更新,请从 %s 手动下载 HMCL 来完成升级。
389+
fatal.deprecated_java_version=HMCL 未来需要 Java 11 或更高版本才能运行,但依然支持使用 Java 8 启动游戏。建议安装最新版本的 Java 以确保 HMCL 能正常工作。\n你可以继续保留旧版本 Java。HMCL 能够识别与管理多个 Java,并会自动根据游戏版本为你选择合适的 Java。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
390+
fatal.deprecated_java_version.download_link=下载 Java %d
389391
fatal.samba=如果你正在通过 Samba 共享的文件夹中运行 Hello Minecraft! Launcher,启动器可能无法正常工作。请尝试更新你的 Java 或在本地文件夹内运行 HMCL。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
390392
fatal.illegal_char=由于你的用户文件夹路径中存在非法字符“=”,你将无法使用外置登录账户以及离线登录更换皮肤功能。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
391393
fatal.unsupported_platform=Minecraft 尚未对你的平台提供完善支持,所以可能影响游戏体验或无法启动游戏。\n若无法启动 Minecraft 1.17 及更高版本,可以尝试在“(全局/版本特定) 游戏设置 → 高级设置 → 调试选项”中将“渲染器”切换为“软渲染器”,以获得更好的兼容性。\n如遇到问题,你可以点击右上角帮助按钮进行求助。

0 commit comments

Comments
 (0)