2026-10-05 18:10:18 -04:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { useCurrentServerUuid } from '@/api/server/queries';
|
|
|
|
|
import { useServerStatus, useSocketInstance } from '@/state/server';
|
|
|
|
|
import { Dialog, useDialogState } from '@/components/elements/dialog';
|
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
2021-08-02 23:32:10 -04:00
|
|
|
import Button from '@/components/elements/Button';
|
|
|
|
|
import { SocketEvent, SocketRequest } from '@/components/server/events';
|
2026-10-05 18:10:18 -04:00
|
|
|
import Select from '@/components/ui/Select';
|
2022-05-07 18:18:14 -04:00
|
|
|
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
|
|
|
|
|
import Can from '@/components/elements/Can';
|
|
|
|
|
import InputSpinner from '@/components/elements/InputSpinner';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { useServerStartup, useSetSelectedDockerImage } from '@/api/server/startup/queries';
|
2021-08-02 23:32:10 -04:00
|
|
|
|
2022-05-07 18:18:14 -04:00
|
|
|
const MATCH_ERRORS = [
|
|
|
|
|
'minecraft 1.17 requires running the server with java 16 or above',
|
|
|
|
|
'minecraft 1.18 requires running the server with java 17 or above',
|
|
|
|
|
'java.lang.unsupportedclassversionerror',
|
|
|
|
|
'unsupported major.minor version',
|
|
|
|
|
'has been compiled by a more recent version of the java runtime',
|
2021-08-02 23:32:10 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const JavaVersionModalFeature = () => {
|
2026-10-05 18:10:18 -04:00
|
|
|
const dialog = useDialogState();
|
|
|
|
|
const [selectedVersionOverride, setSelectedVersionOverride] = useState('');
|
2021-08-02 23:32:10 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const uuid = useCurrentServerUuid()!;
|
|
|
|
|
const status = useServerStatus();
|
|
|
|
|
const instance = useSocketInstance();
|
|
|
|
|
const updateDockerImage = useSetSelectedDockerImage(uuid);
|
|
|
|
|
const loading = updateDockerImage.isPending;
|
2021-08-02 23:32:10 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const { data, isFetching } = useServerStartup(uuid, { enabled: dialog.open });
|
|
|
|
|
const selectedVersion = selectedVersionOverride || Object.values(data?.meta?.docker_images || {})[0] || '';
|
2021-08-02 23:32:10 -04:00
|
|
|
|
2022-05-07 18:18:14 -04:00
|
|
|
useWebsocketEvent(SocketEvent.CONSOLE_OUTPUT, (data) => {
|
|
|
|
|
if (status === 'running') return;
|
2021-08-02 23:32:10 -04:00
|
|
|
|
2022-06-26 15:13:52 -04:00
|
|
|
if (MATCH_ERRORS.some((p) => data.toLowerCase().includes(p.toLowerCase()))) {
|
2026-10-05 18:10:18 -04:00
|
|
|
setSelectedVersionOverride('');
|
|
|
|
|
dialog.show();
|
2022-05-07 18:18:14 -04:00
|
|
|
}
|
|
|
|
|
});
|
2021-08-02 23:32:10 -04:00
|
|
|
|
|
|
|
|
const updateJava = () => {
|
2026-10-05 18:10:18 -04:00
|
|
|
updateDockerImage
|
|
|
|
|
.mutateAsync({ path: { server_uuid: uuid }, body: { docker_image: selectedVersion } })
|
2021-08-02 23:32:10 -04:00
|
|
|
.then(() => {
|
|
|
|
|
if (status === 'offline' && instance) {
|
|
|
|
|
instance.send(SocketRequest.SET_STATE, 'restart');
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
dialog.hide();
|
2021-08-02 23:32:10 -04:00
|
|
|
})
|
2026-10-05 18:10:18 -04:00
|
|
|
.catch(() => {});
|
2021-08-02 23:32:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-10-05 18:10:18 -04:00
|
|
|
<Dialog
|
|
|
|
|
open={dialog.open}
|
|
|
|
|
title={'Unsupported Java version'}
|
|
|
|
|
onClose={dialog.hide}
|
|
|
|
|
preventExternalClose={loading}
|
|
|
|
|
hideCloseIcon={loading}
|
2022-05-07 18:18:14 -04:00
|
|
|
>
|
2026-10-05 18:10:18 -04:00
|
|
|
<SpinnerOverlay visible={loading} />
|
|
|
|
|
<p className={'mt-4'}>
|
2022-05-07 18:18:14 -04:00
|
|
|
This server is currently running an unsupported version of Java and cannot be started.
|
|
|
|
|
<Can action={'startup.docker-image'}>
|
|
|
|
|
Please select a supported version from the list below to continue starting the server.
|
|
|
|
|
</Can>
|
|
|
|
|
</p>
|
|
|
|
|
<Can action={'startup.docker-image'}>
|
2026-10-05 18:10:18 -04:00
|
|
|
<div className={'mt-4'}>
|
|
|
|
|
<InputSpinner visible={!data || isFetching}>
|
|
|
|
|
<Select
|
|
|
|
|
disabled={!data}
|
|
|
|
|
value={selectedVersion}
|
|
|
|
|
onChange={(value) => setSelectedVersionOverride(String(value))}
|
|
|
|
|
options={
|
|
|
|
|
data
|
|
|
|
|
? Object.keys(data.meta?.docker_images ?? {}).map((key) => ({
|
|
|
|
|
value: (data.meta?.docker_images ?? {})[key],
|
|
|
|
|
label: key,
|
|
|
|
|
}))
|
|
|
|
|
: []
|
|
|
|
|
}
|
|
|
|
|
/>
|
2022-05-07 18:18:14 -04:00
|
|
|
</InputSpinner>
|
|
|
|
|
</div>
|
|
|
|
|
</Can>
|
2026-10-05 18:10:18 -04:00
|
|
|
<div className={'mt-8 flex flex-col sm:flex-row justify-end sm:space-x-4 space-y-4 sm:space-y-0'}>
|
|
|
|
|
<Button isSecondary onClick={dialog.hide} className={'w-full sm:w-auto'}>
|
2022-05-07 18:18:14 -04:00
|
|
|
Cancel
|
2021-08-02 23:32:10 -04:00
|
|
|
</Button>
|
2022-05-07 18:18:14 -04:00
|
|
|
<Can action={'startup.docker-image'}>
|
2026-10-05 18:10:18 -04:00
|
|
|
<Button onClick={updateJava} className={'w-full sm:w-auto'}>
|
2021-08-02 23:32:10 -04:00
|
|
|
Update Docker Image
|
2022-05-07 18:18:14 -04:00
|
|
|
</Button>
|
|
|
|
|
</Can>
|
2021-08-02 23:32:10 -04:00
|
|
|
</div>
|
2026-10-05 18:10:18 -04:00
|
|
|
</Dialog>
|
2021-08-02 23:32:10 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default JavaVersionModalFeature;
|