Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Display shutdown progress in webinterface #108

Merged
merged 2 commits into from
Aug 8, 2024
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
46 changes: 39 additions & 7 deletions src/tribler/ui/src/components/layouts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../ui/dialog";
import { useEffect, useState } from "react";
import Cookies from "js-cookie";
import { DialogDescription } from "@radix-ui/react-dialog";
import { Ban } from "lucide-react";
import { Ban } from "lucide-react";

export function Header() {
const [online, setOnline] = useState<boolean>(true);
const [shutdownLogs, setShutdownLogs] = useState<string[]>([]);
const [searchParams, setSearchParams] = useSearchParams();

useEffect(() => {
Expand All @@ -32,23 +33,54 @@ export function Header() {
}, [searchParams]);

useInterval(() => {
if (online !== triblerService.isOnline())
setOnline(triblerService.isOnline());
const onlineNow = triblerService.isOnline();
if (online !== onlineNow) {
if (!online)
setShutdownLogs([]);
setOnline(onlineNow);

}
}, 1000);

useEffect(() => {
(async () => { triblerService.addEventListener("tribler_shutdown_state", OnShutdownEvent) })();
return () => {
(async () => { triblerService.removeEventListener("tribler_shutdown_state", OnShutdownEvent) })();
}
}, []);

const OnShutdownEvent = (event: MessageEvent) => {
const data = JSON.parse(event.data);
setShutdownLogs(prevLogs => [...prevLogs, data.state]);
}

return (
<>
<Dialog open={!online}>
<Dialog open={!online || shutdownLogs.length > 0}>
<DialogContent
closable={false}
onInteractOutside={(e) => {
e.preventDefault();
}}
>
<DialogHeader>
<DialogTitle className="flex items-center justify-center"><Ban className="inline mr-3"/>Failed to connect to Tribler</DialogTitle>
<DialogDescription className="text-center text-xs">Tribler may not be running or your browser is missing a cookie.<br />
In latter case please re-open Tribler from the system tray</DialogDescription>
<DialogTitle className="flex items-center justify-center mb-3"><Ban className="inline mr-3" />
{online
? "Tribler is shutting down"
: (shutdownLogs.length > 0
? "Tribler has shutdown"
: "Failed to connect to Tribler")}
</DialogTitle>

{!online && shutdownLogs.length === 0
? <DialogDescription className="text-center text-xs">
Tribler may not be running or your browser is missing a cookie.
<br />In latter case please re-open Tribler from the system tray
</DialogDescription>
: <DialogDescription className="text-xs font-mono">
{shutdownLogs.map(log => <p>{log}<br /></p>)}
</DialogDescription>
}
</DialogHeader>
</DialogContent>
</Dialog>
Expand Down
1 change: 1 addition & 0 deletions src/tribler/ui/src/components/ui/simple-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function SimpleTable<T extends object>({
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
className={`${allowSelect || allowMultiSelect ? "cursor-pointer" : ""}`}
onClick={(event) => {
if (!allowSelect && !allowMultiSelect)
return
Expand Down