0.1.1
This commit is contained in:
@@ -11,23 +11,50 @@
|
||||
<header class="app-header">
|
||||
<nav class="navbar navbar-expand-lg h-100 py-0 bg-light text-dark">
|
||||
<div class="container my-0">
|
||||
<a class="navbar-brand d-flex align-items-center" href="/"> <img alt="Logo" src="imgs/logo.png" class="app-logo" /> <span class="ps-2 fs-4 fw-bold text-primary font-logo">Khadhroony-BoBot</span>
|
||||
<a class="navbar-brand d-flex align-items-center" href="/">
|
||||
<img alt="Logo" src="imgs/logo.png" class="app-logo" />
|
||||
<span class="ps-2 fs-4 fw-bold text-primary font-logo">Khadhroony-BoBoBot</span>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="app-main">
|
||||
<div class="osb-scrollable pt-1 pb-4" data-simplebar>
|
||||
<div class="container vcentered sketchy-translucid">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<h1>Khadhroony-BoBoBot</h1>
|
||||
|
||||
<div class="container py-4">
|
||||
<div class="row g-4">
|
||||
<div class="col-12 col-xl-4">
|
||||
<div class="row g-4 justify-content-center">
|
||||
<div class="col-12 col-xl-8">
|
||||
<div class="card shadow-sm border-0 h-100">
|
||||
<div class="card-body text-start">
|
||||
<h3 class="h5 card-title mb-3">Content</h3>
|
||||
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3 mb-3">
|
||||
<div>
|
||||
<h3 class="h5 card-title mb-1">WebSocket transport</h3>
|
||||
<p class="text-body-secondary mb-0">
|
||||
Démarre ou arrête tous les endpoints WebSocket activés dans <code>config.json</code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span id="wsStatusBadge" class="badge text-bg-secondary">Disconnected</span>
|
||||
<button id="wsConnectButton" class="btn btn-success" type="button">Start</button>
|
||||
<button id="wsDisconnectButton" class="btn btn-danger" type="button" disabled>Stop</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label for="wsLogTextarea" class="form-label fw-semibold">Transport log</label>
|
||||
<textarea
|
||||
id="wsLogTextarea"
|
||||
class="form-control font-monospace"
|
||||
rows="18"
|
||||
readonly
|
||||
spellcheck="false"
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,6 +65,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="app-footer bg-dark text-light">
|
||||
<div class="container h-100 d-flex align-items-center">
|
||||
<div class="row flex-grow-1 align-items-center">
|
||||
@@ -45,7 +73,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script type="module" src="ts/main.ts" defer></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -3,8 +3,8 @@
|
||||
import * as bootstrap from "bootstrap";
|
||||
import "simplebar";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
//import { invoke } from "@tauri-apps/api/core";
|
||||
//import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
//import { error } from "@fltsci/tauri-plugin-tracing";
|
||||
//import { info } from "@fltsci/tauri-plugin-tracing";
|
||||
import { trace, takeoverConsole } from "@fltsci/tauri-plugin-tracing";
|
||||
@@ -12,7 +12,45 @@ import { trace, takeoverConsole } from "@fltsci/tauri-plugin-tracing";
|
||||
(window as Window & typeof globalThis & { bootstrap?: typeof bootstrap }).bootstrap = bootstrap;
|
||||
(window as Window & typeof globalThis & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver = ResizeObserver;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
function appendLogLine(textarea: HTMLTextAreaElement, line: string): void {
|
||||
const now = new Date();
|
||||
const timestamp = now.toLocaleTimeString("fr-CH", { hour12: false });
|
||||
textarea.value += `[${timestamp}] ${line}\n`;
|
||||
textarea.scrollTop = textarea.scrollHeight;
|
||||
}
|
||||
|
||||
function setRunningState(
|
||||
isRunning: boolean,
|
||||
statusBadge: HTMLSpanElement,
|
||||
connectButton: HTMLButtonElement,
|
||||
disconnectButton: HTMLButtonElement,
|
||||
): void {
|
||||
if (isRunning) {
|
||||
statusBadge.textContent = "Connected";
|
||||
statusBadge.className = "badge text-bg-success";
|
||||
connectButton.disabled = true;
|
||||
disconnectButton.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
statusBadge.textContent = "Disconnected";
|
||||
statusBadge.className = "badge text-bg-secondary";
|
||||
connectButton.disabled = false;
|
||||
disconnectButton.disabled = true;
|
||||
}
|
||||
|
||||
function setBusyState(
|
||||
label: string,
|
||||
statusBadge: HTMLSpanElement,
|
||||
connectButton: HTMLButtonElement,
|
||||
disconnectButton: HTMLButtonElement,
|
||||
): void {
|
||||
statusBadge.textContent = label;
|
||||
statusBadge.className = "badge text-bg-warning";
|
||||
connectButton.disabled = true;
|
||||
disconnectButton.disabled = true;
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
void takeoverConsole();
|
||||
const sidebarToggle = document.querySelector<HTMLButtonElement>('#sidebarToggle');
|
||||
if (sidebarToggle) {
|
||||
@@ -48,6 +86,61 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
a.setAttribute("href", url.pathname + "?" + url.searchParams.toString());
|
||||
});
|
||||
|
||||
const connectButton = document.querySelector<HTMLButtonElement>("#wsConnectButton");
|
||||
const disconnectButton = document.querySelector<HTMLButtonElement>("#wsDisconnectButton");
|
||||
const statusBadge = document.querySelector<HTMLSpanElement>("#wsStatusBadge");
|
||||
const logTextarea = document.querySelector<HTMLTextAreaElement>("#wsLogTextarea");
|
||||
|
||||
if (!connectButton || !disconnectButton || !statusBadge || !logTextarea) {
|
||||
trace("main UI controls not found");
|
||||
return;
|
||||
}
|
||||
|
||||
let unlistenLogEvent: UnlistenFn | null = null;
|
||||
|
||||
try {
|
||||
unlistenLogEvent = await listen<string>("kb-log", (event) => {
|
||||
appendLogLine(logTextarea, event.payload);
|
||||
});
|
||||
} catch (error) {
|
||||
appendLogLine(logTextarea, `[ui] event listen error: ${String(error)}`);
|
||||
}
|
||||
|
||||
setRunningState(false, statusBadge, connectButton, disconnectButton);
|
||||
appendLogLine(logTextarea, "[ui] main window loaded");
|
||||
|
||||
connectButton.addEventListener("click", async () => {
|
||||
setBusyState("Starting", statusBadge, connectButton, disconnectButton);
|
||||
|
||||
try {
|
||||
const startedCount = await invoke<number>("start_ws_clients");
|
||||
appendLogLine(logTextarea, `[ui] started ${startedCount} websocket client(s)`);
|
||||
setRunningState(true, statusBadge, connectButton, disconnectButton);
|
||||
} catch (error) {
|
||||
appendLogLine(logTextarea, `[ui] start error: ${String(error)}`);
|
||||
setRunningState(false, statusBadge, connectButton, disconnectButton);
|
||||
}
|
||||
});
|
||||
|
||||
disconnectButton.addEventListener("click", async () => {
|
||||
setBusyState("Stopping", statusBadge, connectButton, disconnectButton);
|
||||
|
||||
try {
|
||||
const stoppedCount = await invoke<number>("stop_ws_clients");
|
||||
appendLogLine(logTextarea, `[ui] stopped ${stoppedCount} websocket client(s)`);
|
||||
setRunningState(false, statusBadge, connectButton, disconnectButton);
|
||||
} catch (error) {
|
||||
appendLogLine(logTextarea, `[ui] stop error: ${String(error)}`);
|
||||
setRunningState(true, statusBadge, connectButton, disconnectButton);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("beforeunload", () => {
|
||||
if (unlistenLogEvent) {
|
||||
unlistenLogEvent();
|
||||
}
|
||||
});
|
||||
|
||||
trace("window loaded");
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user