Skip to content
Merged
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
11 changes: 6 additions & 5 deletions apps/app-frontend/src/composables/useJavaTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ref } from 'vue'

import { trackEvent } from '@/helpers/analytics'
import { test_jre } from '@/helpers/jre.js'
import { get_jre, test_jre } from '@/helpers/jre.js'

export default function useJavaTest() {
const testingJava = ref(false)
const javaTestResult = ref<boolean | null>(null)
let testDebounceTimer: ReturnType<typeof setTimeout> | null = null

async function runJavaTest(path: string, version: number, track = true) {
async function runJavaTest(path: string, version: number | null, track = true) {
if (testDebounceTimer) {
clearTimeout(testDebounceTimer)
testDebounceTimer = null
Expand All @@ -19,7 +19,8 @@ export default function useJavaTest() {
}
testingJava.value = true
try {
javaTestResult.value = await test_jre(path, version)
javaTestResult.value =
version === null ? !!(await get_jre(path)) : await test_jre(path, version)
} catch {
javaTestResult.value = false
}
Expand All @@ -30,7 +31,7 @@ export default function useJavaTest() {
}
}

function testJavaInstallationDebounced(path: string, version: number, delay = 600) {
function testJavaInstallationDebounced(path: string, version: number | null, delay = 600) {
if (testDebounceTimer) clearTimeout(testDebounceTimer)
if (!path) {
javaTestResult.value = null
Expand All @@ -39,7 +40,7 @@ export default function useJavaTest() {
testDebounceTimer = setTimeout(() => runJavaTest(path, version, false), delay)
}

async function testJavaInstallation(path: string, version: number, track = false) {
async function testJavaInstallation(path: string, version: number | null, track = false) {
await runJavaTest(path, version, track)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ let hasInitialized = false
watch(
javaTestPath,
(newPath) => {
if (newPath && optimalJava?.parsed_version) {
if (newPath) {
if (!hasInitialized) {
testJavaInstallation(newPath, optimalJava?.parsed_version, false)
testJavaInstallation(newPath, null, false)
hasInitialized = true
} else {
testJavaInstallationDebounced(newPath, optimalJava?.parsed_version)
testJavaInstallationDebounced(newPath, null)
}
}
},
{ immediate: true },
)

const javaDetectionModal = ref<{ show: (version: number, current: object) => void } | null>(null)
const javaDetectionModal = ref<{ show: (version: number | null, current: object) => void } | null>(
null,
)

async function handleBrowseJava() {
const result = await open({ multiple: false })
Expand All @@ -84,7 +86,7 @@ async function handleBrowseJava() {
}

function handleDetectJava() {
javaDetectionModal.value?.show(optimalJava?.parsed_version, { path: javaPath.value })
javaDetectionModal.value?.show(null, { path: javaPath.value })
}

const overrideJavaArgs = ref((instance.value.extra_launch_args?.length ?? 0) > 0)
Expand Down Expand Up @@ -262,9 +264,6 @@ const messages = defineMessages({
<CoffeeIcon />
</div>
<div class="flex flex-col gap-2 flex-1 min-w-0">
<span class="font-semibold leading-none mt-2"
>Java {{ optimalJava?.parsed_version }}</span
>
<div class="flex gap-2 items-center">
<Input
:model-value="activePath"
Expand Down Expand Up @@ -306,7 +305,7 @@ const messages = defineMessages({
: undefined,
}"
class="!text-[var(--legacy-button-color,var(--color-base))] [&>svg]:!text-[var(--legacy-button-color,var(--color-primary))]"
@click="testJavaInstallation(activePath, optimalJava?.parsed_version, true)"
@click="testJavaInstallation(activePath, null, true)"
@mouseenter="hoveringTest = true"
@mouseleave="hoveringTest = false"
>
Expand Down
Loading