J.A.R.V.I.S-rust/frontend/src/routes/index.svelte

106 lines
2.7 KiB
Svelte
Raw Normal View History

<script lang="ts">
2026-01-04 22:50:34 +05:00
import { onMount, onDestroy } from "svelte"
import { invoke } from "@tauri-apps/api/core"
import { Notification, Space, Button } from "@svelteuidev/core"
2026-01-04 22:50:34 +05:00
import { InfoCircled } from "radix-icons-svelte"
import ArcReactor from "@/components/elements/ArcReactor.svelte"
import HDivider from "@/components/elements/HDivider.svelte"
import Stats from "@/components/elements/Stats.svelte"
import Footer from "@/components/Footer.svelte"
import {
isJarvisRunning,
updateJarvisStats,
jarvisState,
ipcConnected,
enableIpc,
disableIpc
} from "@/stores"
let processRunning = false
let launching = false
// when process state changes, enable/disable IPC
isJarvisRunning.subscribe((value) => {
processRunning = value
if (value) {
// process is running, enable IPC connection
enableIpc()
} else {
// process stopped, disable IPC (stops reconnect attempts)
disableIpc()
}
2026-01-04 22:50:34 +05:00
})
2026-01-04 22:50:34 +05:00
onMount(() => {
document.body.classList.add("assist-page")
updateJarvisStats()
2026-01-04 22:50:34 +05:00
})
2026-01-04 22:50:34 +05:00
onDestroy(() => {
document.body.classList.remove("assist-page")
disableIpc()
2026-01-04 22:50:34 +05:00
})
async function runAssistant() {
launching = true
try {
await invoke("run_jarvis_app")
// wait for startup
setTimeout(async () => {
await updateJarvisStats()
launching = false
}, 2500)
} catch (err) {
console.error("Failed to run jarvis-app:", err)
launching = false
}
}
</script>
<HDivider />
2026-01-04 22:50:34 +05:00
{#if !processRunning}
2026-01-04 22:50:34 +05:00
<Notification
title="Внимание!"
icon={InfoCircled}
color="cyan"
withCloseButton={false}
>
В данный момент ассистент не запущен.<br />
Но вы всё еще можете изменять его настройки.<br />
<br />
<Button
color="lime"
radius="md"
size="sm"
uppercase
ripple
fullSize
on:click={runAssistant}
disabled={launching}
>
{launching ? "Запуск..." : "Запустить"}
</Button>
2026-01-04 22:50:34 +05:00
</Notification>
{:else}
2026-01-04 22:50:34 +05:00
<ArcReactor />
{#if !$ipcConnected}
<Notification
title="Подключение..."
color="yellow"
withCloseButton={false}
>
Устанавливается связь с ассистентом...
</Notification>
{/if}
{/if}
2026-01-04 22:50:34 +05:00
<HDivider noMargin />
<Stats />
<Footer />