Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/components/modals/download-java-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@chakra-ui/react";
import { openUrl } from "@tauri-apps/plugin-opener";
import { useRouter } from "next/router";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { LuExternalLink } from "react-icons/lu";
import { MenuSelector } from "@/components/common/menu-selector";
Expand All @@ -23,6 +23,9 @@ import { useToast } from "@/contexts/toast";
import { ConfigService } from "@/services/config";

type VendorKey = "mojang" | "zulu" | "bellsoft" | "oracle";
const DEFAULT_VENDOR: VendorKey = "mojang";
const DEFAULT_VERSION = "25" as const;
const DEFAULT_TYPE = "jre" as const;

interface JavaVendor {
label: string;
Expand Down Expand Up @@ -56,9 +59,11 @@ export const DownloadJavaModal: React.FC<Omit<ModalProps, "children">> = ({
const os = config.basicInfo.osType;
const arch = config.basicInfo.arch;

const [vendor, setVendor] = useState<VendorKey | "">("");
const [version, setVersion] = useState<"" | "8" | "11" | "17" | "21">("");
const [type, setType] = useState<"" | "jdk" | "jre">("");
const [vendor, setVendor] = useState<VendorKey | "">(DEFAULT_VENDOR);
const [version, setVersion] = useState<"" | "8" | "11" | "17" | "21" | "25">(
DEFAULT_VERSION
);
const [type, setType] = useState<"" | "jdk" | "jre">(DEFAULT_TYPE);

const VENDORS: Record<VendorKey, JavaVendor> = {
mojang: {
Expand Down Expand Up @@ -114,6 +119,13 @@ export const DownloadJavaModal: React.FC<Omit<ModalProps, "children">> = ({
},
};

useEffect(() => {
if (!props.isOpen) return;
setVendor(DEFAULT_VENDOR);
setVersion(DEFAULT_VERSION);
setType(DEFAULT_TYPE);
}, [props.isOpen]);
Comment on lines +122 to +127
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The useEffect hook references props.isOpen in its body but does not include it in the dependency array. According to React best practices and the pattern used consistently throughout the codebase (e.g., manual-add-java-path-modal.tsx:39-43, manage-skin-modal.tsx:88-93), props.isOpen should be included in the dependency array to ensure the effect runs when the modal opens. Please add props.isOpen to the dependency array.

Copilot uses AI. Check for mistakes.

const handleConfirm = async () => {
if (!vendor || !version || !type) return;

Expand Down
20 changes: 18 additions & 2 deletions src/components/modals/launch-process-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { useLauncherConfig } from "@/contexts/config";
import { useGlobalData } from "@/contexts/global-data";
import { useSharedModals } from "@/contexts/shared-modal";
import { useToast } from "@/contexts/toast";
import { LaunchServiceError } from "@/enums/service-error";
import { InstanceSummary } from "@/models/instance/misc";
import { ResponseError } from "@/models/response";
import { AccountService } from "@/services/account";
Expand All @@ -55,7 +56,8 @@ const LaunchProcessModal: React.FC<LaunchProcessModal> = ({
const { config } = useLauncherConfig();
const primaryColor = config.appearance.theme.primaryColor;
const { selectedPlayer, getInstanceList } = useGlobalData();
const { openSharedModal } = useSharedModals();
const { openSharedModal, openGenericConfirmDialog, closeSharedModal } =
useSharedModals();

const [launchingInstance, setLaunchingInstance] = useState<InstanceSummary>();
const [errorPaused, setErrorPaused] = useState<boolean>(false);
Expand Down Expand Up @@ -88,7 +90,18 @@ const LaunchProcessModal: React.FC<LaunchProcessModal> = ({
function: () => LaunchService.selectSuitableJRE(instanceId),
isOK: (data: any) => true,
onResCallback: (data: any) => {},
onErrCallback: (error: ResponseError) => {}, // TODO
onErrCallback: (error: ResponseError) => {
if (error.raw_error === LaunchServiceError.NoSuitableJava) {
openGenericConfirmDialog({
title: t("NoSuitableJavaDialog.title"),
body: t("NoSuitableJavaDialog.body"),
onOKCallback: () => {
router.push("/settings/java");
closeSharedModal("launch");
},
});
}
},
},
{
label: "validateGameFiles",
Expand Down Expand Up @@ -152,13 +165,16 @@ const LaunchProcessModal: React.FC<LaunchProcessModal> = ({
],
[
activeStep,
closeSharedModal,
handleCloseModalWithCancel,
instanceId,
openGenericConfirmDialog,
openSharedModal,
quickPlaySingleplayer,
quickPlayMultiplayer,
router,
selectedPlayer,
t,
toast,
]
);
Expand Down
4 changes: 4 additions & 0 deletions src/enums/service-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ export enum ResourceServiceError {
ParseError = "PARSE_ERROR",
NoDownloadApi = "NO_DOWNLOAD_API",
}

export enum LaunchServiceError {
NoSuitableJava = "NO_SUITABLE_JAVA",
}
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,10 @@
"MenuSelector": {
"selectedCount": "{{count}} selected"
},
"NoSuitableJavaDialog": {
"title": "No suitable Java runtime found for this instance",
"body": "No suitable Java runtime is available for this instance. Click \"Confirm\" to open Java Management page and add or download Java manually."
},
Comment on lines +1422 to +1425
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The new translation keys for "NoSuitableJavaDialog" are only added to en.json and zh-Hans.json, but are missing from the other locale files (fr.json, ja.json, zh-Hant.json). This will cause missing translations when users switch to French, Japanese, or Traditional Chinese languages. Please add these translation keys to all locale files to maintain consistency across all supported languages.

Copilot uses AI. Check for mistakes.
"NotFoundPage": {
"text": "Page not found, redirecting to launch page in {{seconds}} seconds..."
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,10 @@
"MenuSelector": {
"selectedCount": "已选 {{count}} 项"
},
"NoSuitableJavaDialog": {
"title": "未找到合适的 Java 运行时",
"body": "对于当前实例,没有合适的 Java 运行时可供选择。点击 “确定” 以前往 Java 管理页面手动添加或下载 Java。"
},
"NotFoundPage": {
"text": "页面不存在,即将在 {{seconds}} 秒后跳转"
},
Expand Down
Loading