diff --git a/matrixgw_backend/src/matrix_connection/matrix_client.rs b/matrixgw_backend/src/matrix_connection/matrix_client.rs index dc59884..eb7702e 100644 --- a/matrixgw_backend/src/matrix_connection/matrix_client.rs +++ b/matrixgw_backend/src/matrix_connection/matrix_client.rs @@ -121,7 +121,7 @@ impl MatrixClient { .map_err(MatrixClientError::ReadDbPassphrase)?; let client = Client::builder() - .server_name_or_homeserver_url(&AppConfig::get().matrix_homeserver) + .homeserver_url(&AppConfig::get().matrix_homeserver) // Automatically refresh tokens if needed .handle_refresh_tokens() .sqlite_store(&db_path, Some(&passphrase)) diff --git a/matrixgw_frontend/src/api/MatrixSyncApi.ts b/matrixgw_frontend/src/api/MatrixSyncApi.ts index 600a4e6..8e8999c 100644 --- a/matrixgw_frontend/src/api/MatrixSyncApi.ts +++ b/matrixgw_frontend/src/api/MatrixSyncApi.ts @@ -2,7 +2,7 @@ import { APIClient } from "./ApiClient"; export class MatrixSyncApi { /** - * Force sync thread startup + * Start sync thread */ static async Start(): Promise { await APIClient.exec({ @@ -10,4 +10,25 @@ export class MatrixSyncApi { uri: "/matrix_sync/start", }); } + + /** + * Stop sync thread + */ + static async Stop(): Promise { + await APIClient.exec({ + method: "POST", + uri: "/matrix_sync/stop", + }); + } + + /** + * Get sync thread status + */ + static async Status(): Promise { + const res = await APIClient.exec({ + method: "GET", + uri: "/matrix_sync/status", + }); + return res.data.started; + } } diff --git a/matrixgw_frontend/src/routes/HomeRoute.tsx b/matrixgw_frontend/src/routes/HomeRoute.tsx index f21be44..e404074 100644 --- a/matrixgw_frontend/src/routes/HomeRoute.tsx +++ b/matrixgw_frontend/src/routes/HomeRoute.tsx @@ -1,4 +1,3 @@ -import { APIClient } from "../api/ApiClient"; import { MatrixSyncApi } from "../api/MatrixSyncApi"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { useUserInfo } from "../widgets/dashboard/BaseAuthenticatedPage"; diff --git a/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx b/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx index 1bb675d..82173bf 100644 --- a/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx +++ b/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx @@ -3,15 +3,21 @@ import CloseIcon from "@mui/icons-material/Close"; import KeyIcon from "@mui/icons-material/Key"; import LinkIcon from "@mui/icons-material/Link"; import LinkOffIcon from "@mui/icons-material/LinkOff"; +import PlayArrowIcon from "@mui/icons-material/PlayArrow"; +import PowerSettingsNewIcon from "@mui/icons-material/PowerSettingsNew"; +import StopIcon from "@mui/icons-material/Stop"; import { Button, Card, CardActions, CardContent, + CircularProgress, + Grid, Typography, } from "@mui/material"; import React from "react"; import { MatrixLinkApi } from "../api/MatrixLinkApi"; +import { MatrixSyncApi } from "../api/MatrixSyncApi"; import { SetRecoveryKeyDialog } from "../dialogs/SetRecoveryKeyDialog"; import { useAlert } from "../hooks/contexts_provider/AlertDialogProvider"; import { useConfirm } from "../hooks/contexts_provider/ConfirmDialogProvider"; @@ -27,10 +33,17 @@ export function MatrixLinkRoute(): React.ReactElement { {user.info.matrix_user_id === null ? ( ) : ( - <> - - - + + + + + + + + + + + )} ); @@ -202,3 +215,115 @@ function EncryptionKeyStatus(): React.ReactElement { ); } + +function SyncThreadStatus(): React.ReactElement { + const alert = useAlert(); + const snackbar = useSnackbar(); + + const [started, setStarted] = React.useState(); + + const loadStatus = async () => { + try { + setStarted(await MatrixSyncApi.Status()); + } catch (e) { + console.error(`Failed to refresh sync thread status! ${e}`); + snackbar(`Failed to refresh sync thread status! ${e}`); + } + }; + + const handleStartThread = async () => { + try { + setStarted(undefined); + await MatrixSyncApi.Start(); + snackbar("Sync thread started"); + } catch (e) { + console.error(`Failed to start sync thread! ${e}`); + alert(`Failed to start sync thread! ${e}`); + } + }; + + const handleStopThread = async () => { + try { + setStarted(undefined); + await MatrixSyncApi.Stop(); + snackbar("Sync thread stopped"); + } catch (e) { + console.error(`Failed to stop sync thread! ${e}`); + alert(`Failed to stop sync thread! ${e}`); + } + }; + + React.useEffect(() => { + const interval = setInterval(loadStatus, 1000); + + () => clearInterval(interval); + }, []); + + return ( + <> + + + + Sync thread status + + +

+ A thread is spawned on the server to watch for events on the + Matrix server. You can restart this thread from here in case of + issue. +

+ +

+ Current thread status:{" "} + {started === undefined ? ( + <> + + + ) : started === true ? ( + <> + {" "} + Started + + ) : ( + <> + + Stopped + + )} +

+
+
+ + {started === false && ( + + )} + + {started === true && ( + + )} + +
+ + ); +}