mirror of
https://github.com/modrinth/code.git
synced 2026-08-03 06:35:53 +00:00
* Clean impl of java installation ui improvements * Migrate composable to ts * Migrate to ButtonStyled, fix coloring * Fix lint * Fix clearing java path not refreshing state * fix: use Table component + install btn disabled state tooltip --------- Signed-off-by: Arthur <creeperkatze.dev@gmail.com> Signed-off-by: Arthur <contact@creeperkatze.dev> Co-authored-by: Creeperkatze <178587183+Creeperkatze@users.noreply.github.com> Co-authored-by: Calum H. <calum@modrinth.com> Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { ref } from 'vue'
|
|
|
|
import { trackEvent } from '@/helpers/analytics'
|
|
import { 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) {
|
|
if (testDebounceTimer) {
|
|
clearTimeout(testDebounceTimer)
|
|
testDebounceTimer = null
|
|
}
|
|
if (!path) {
|
|
javaTestResult.value = null
|
|
return
|
|
}
|
|
testingJava.value = true
|
|
try {
|
|
javaTestResult.value = await test_jre(path, version)
|
|
} catch {
|
|
javaTestResult.value = false
|
|
}
|
|
testingJava.value = false
|
|
|
|
if (track) {
|
|
trackEvent('JavaTest', { path, success: javaTestResult.value })
|
|
}
|
|
}
|
|
|
|
function testJavaInstallationDebounced(path: string, version: number, delay = 600) {
|
|
if (testDebounceTimer) clearTimeout(testDebounceTimer)
|
|
if (!path) {
|
|
javaTestResult.value = null
|
|
return
|
|
}
|
|
testDebounceTimer = setTimeout(() => runJavaTest(path, version, false), delay)
|
|
}
|
|
|
|
async function testJavaInstallation(path: string, version: number, track = false) {
|
|
await runJavaTest(path, version, track)
|
|
}
|
|
|
|
return {
|
|
testingJava,
|
|
javaTestResult,
|
|
testJavaInstallationDebounced,
|
|
testJavaInstallation,
|
|
}
|
|
}
|