Skip to content

Commit

Permalink
toniebox-reverse-engineeringgh-164 show disabled BoxineCloud (orange …
Browse files Browse the repository at this point in the history
…instead red), toniebox-reverse-engineeringgh-167 fetch cloud status on some changes (cloud enabled changed, certificates uploaded, certificates extracted esp32 flashing)
  • Loading branch information
henryk86 committed Nov 4, 2024
1 parent 9cb09fa commit 2b1592e
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 73 deletions.
1 change: 1 addition & 0 deletions public/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"incident_detected": "Ein Sicherheitsvorfall wurde entdeckt! Bitte überprüfe deine Logs!"
},
"server": {
"boxineDisabled": "Boxine/Toniecloud ist derzeit deaktiviert. Aktiviere die Einstellung 'Cloud enabled', um die Verbindung zu Boxine/Toniecloud wiederherzustellen.",
"boxineStatusOffline": "Nicht mit Boxine/Toniecloud verbunden",
"boxineStatusOnline": "Mit Boxine/Toniecloud verbunden",
"teddycloudStatusOffline": "TeddyCloud Server offline",
Expand Down
1 change: 1 addition & 0 deletions public/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"incident_detected": "Security Incident Detected! Please check your logs!"
},
"server": {
"boxineDisabled": "Boxine/Toniecloud is currently disabled. Enable setting 'Cloud enabled' to reconnect to Boxine/Toniecloud.",
"boxineStatusOffline": "Not connected to Boxine/Toniecloud",
"boxineStatusOnline": "Connected to Boxine/Toniecloud",
"teddycloudStatusOffline": "Teddycloud server offline",
Expand Down
1 change: 1 addition & 0 deletions public/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"incident_detected": "¡Incidente de seguridad detectado! ¡Por favor, revisa tus registros!"
},
"server": {
"boxineDisabled": "Boxine/Toniecloud está actualmente desactivado. Activa la opción 'Cloud enabled' para volver a conectarte a Boxine/Toniecloud.",
"boxineStatusOffline": "No conectado a Boxine/Toniecloud",
"boxineStatusOnline": "Conectado a Boxine/Toniecloud",
"teddycloudStatusOffline": "Servidor de Teddycloud desconectado",
Expand Down
1 change: 1 addition & 0 deletions public/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"incident_detected": "Incident de sécurité détecté ! Veuillez vérifier vos journaux !"
},
"server": {
"boxineDisabled": "Boxine/Toniecloud est actuellement désactivé. Active le paramètre 'Cloud enabled' pour te reconnecter à Boxine/Toniecloud.",
"boxineStatusOffline": "Non connecté à Boxine/Toniecloud",
"boxineStatusOnline": "Connecté à Boxine/Toniecloud",
"teddycloudStatusOffline": "Serveur TeddyCloud hors ligne",
Expand Down
133 changes: 71 additions & 62 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { SystemSoundsPage } from "./pages/tonies/SystemSoundsPage";
import { TonieAudioPlaylistsPage } from "./pages/tonies/TonieAudioPlaylistsPage";
import { ToniesPage } from "./pages/tonies/ToniesPage";
import { detectColorScheme } from "./utils/browserUtils";
import { TeddyCloudProvider } from "./utils/TeddyCloudContext";

function App() {
const { defaultAlgorithm, darkAlgorithm } = theme;
Expand Down Expand Up @@ -101,68 +102,76 @@ function App() {
},
}}
>
<div className="App">
<Layout style={{ minHeight: "100vh" }}>
<Router basename={import.meta.env.VITE_APP_TEDDYCLOUD_WEB_BASE}>
<AudioProvider>
<StyledHeader themeSwitch={themeSwitchIcon} />
<Layout>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/home/stats" element={<StatsPage />} />
<Route path="/home/features" element={<FeaturesPage />} />
<Route path="/home/toniemeeting" element={<TonieMeetingPage />} />
<Route path="/tonies" element={<ToniesPage />} />
<Route path="/tonies/system-sounds" element={<SystemSoundsPage />} />
<Route path="/tonies/content" element={<ContentPage />} />
<Route path="/tonies/library" element={<LibraryPage />} />
<Route path="/tonies/encoder" element={<EncoderPage />} />
<Route path="/tonies/tap" element={<TonieAudioPlaylistsPage />} />
<Route path="/tonieboxes" element={<TonieboxesPage />} />
<Route path="/tonieboxes/boxsetup" element={<BoxSetupPage />} />
<Route
path="/tonieboxes/boxsetup/identifyboxversion"
element={<IdentifyBoxVersionPage />}
/>
<Route path="/tonieboxes/boxsetup/openboxguide" element={<OpenBoxGuidePage />} />
<Route
path="/tonieboxes/boxsetup/boxversioninfo"
element={<BoxVersionInformationPage />}
/>
<Route
path="/tonieboxes/boxsetup/esp32/flashing"
element={<ESP32BoxFlashingPage />}
/>
<Route path="/tonieboxes/boxsetup/esp32/legacy" element={<ESP32LegacyPage />} />
<Route
path="/tonieboxes/boxsetup/cc3200/flashing"
element={<CC3200BoxFlashingPage />}
/>
<Route
path="/tonieboxes/boxsetup/cc3235/flashing"
element={<CC3235BoxFlashingPage />}
/>
<Route path="/settings" element={<SettingsPage />} />
<Route path="/settings/certificates" element={<CertificatesPage />} />
<Route path="/settings/rtnl" element={<RtnlPage />} />
<Route path="/community" element={<CommunityPage />} />
<Route path="/community/faq" element={<FAQPage />} />
<Route path="/community/contribution" element={<ContributionPage />} />
<Route
path="/community/contribution/tonies-json"
element={<ContributionToniesJsonPage />}
/>
<Route path="/community/contribution/translations" element={<TranslationsPage />} />
<Route path="/community/contributors" element={<ContributorsPage />} />
<Route path="/community/changelog" element={<ChangelogPage />} />
<Route path="/*" element={<Error404Page />} />
</Routes>
</Layout>
<StyledFooter />
</AudioProvider>
</Router>
</Layout>
</div>
<TeddyCloudProvider>
<div className="App">
<Layout style={{ minHeight: "100vh" }}>
<Router basename={import.meta.env.VITE_APP_TEDDYCLOUD_WEB_BASE}>
<AudioProvider>
<StyledHeader themeSwitch={themeSwitchIcon} />
<Layout>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/home/stats" element={<StatsPage />} />
<Route path="/home/features" element={<FeaturesPage />} />
<Route path="/home/toniemeeting" element={<TonieMeetingPage />} />
<Route path="/tonies" element={<ToniesPage />} />
<Route path="/tonies/system-sounds" element={<SystemSoundsPage />} />
<Route path="/tonies/content" element={<ContentPage />} />
<Route path="/tonies/library" element={<LibraryPage />} />
<Route path="/tonies/encoder" element={<EncoderPage />} />
<Route path="/tonies/tap" element={<TonieAudioPlaylistsPage />} />
<Route path="/tonieboxes" element={<TonieboxesPage />} />
<Route path="/tonieboxes/boxsetup" element={<BoxSetupPage />} />
<Route
path="/tonieboxes/boxsetup/identifyboxversion"
element={<IdentifyBoxVersionPage />}
/>
<Route
path="/tonieboxes/boxsetup/openboxguide"
element={<OpenBoxGuidePage />}
/>
<Route
path="/tonieboxes/boxsetup/boxversioninfo"
element={<BoxVersionInformationPage />}
/>
<Route
path="/tonieboxes/boxsetup/esp32/flashing"
element={<ESP32BoxFlashingPage />}
/>
<Route path="/tonieboxes/boxsetup/esp32/legacy" element={<ESP32LegacyPage />} />
<Route
path="/tonieboxes/boxsetup/cc3200/flashing"
element={<CC3200BoxFlashingPage />}
/>
<Route
path="/tonieboxes/boxsetup/cc3235/flashing"
element={<CC3235BoxFlashingPage />}
/>
<Route path="/settings" element={<SettingsPage />} />
<Route path="/settings/certificates" element={<CertificatesPage />} />
<Route path="/settings/rtnl" element={<RtnlPage />} />
<Route path="/community" element={<CommunityPage />} />
<Route path="/community/faq" element={<FAQPage />} />
<Route path="/community/contribution" element={<ContributionPage />} />
<Route
path="/community/contribution/tonies-json"
element={<ContributionToniesJsonPage />}
/>
<Route
path="/community/contribution/translations"
element={<TranslationsPage />}
/>
<Route path="/community/contributors" element={<ContributorsPage />} />
<Route path="/community/changelog" element={<ChangelogPage />} />
<Route path="/*" element={<Error404Page />} />
</Routes>
</Layout>
<StyledFooter />
</AudioProvider>
</Router>
</Layout>
</div>
</TeddyCloudProvider>
</ConfigProvider>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/form/CertificatesDragAndDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { InboxOutlined } from "@ant-design/icons";

import { ApiUploadCertPostRequest, TeddyCloudApi } from "../../api";
import { defaultAPIConfig } from "../../config/defaultApiConfig";
import { useTeddyCloud } from "../../utils/TeddyCloudContext";

const api = new TeddyCloudApi(defaultAPIConfig());

export const CertificateDragNDrop: React.FC<{ overlay?: string }> = ({ overlay }) => {
const { t } = useTranslation();
const { setFetchCloudStatus } = useTeddyCloud();

const handleUpload = async (file: UploadFile<any>) => {
const formData = new FormData();
Expand All @@ -35,6 +37,7 @@ export const CertificateDragNDrop: React.FC<{ overlay?: string }> = ({ overlay }
filename: file.name,
})
);
setFetchCloudStatus((prev) => !prev);
} catch (err) {
message.error(
t("settings.certificates.uploadFailed", {
Expand Down
7 changes: 7 additions & 0 deletions src/components/form/SwitchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useField } from "formik";

import { TeddyCloudApi } from "../../api";
import { defaultAPIConfig } from "../../config/defaultApiConfig";
import { useTeddyCloud } from "../../utils/TeddyCloudContext";

type SwitchFieldProps = {
name: string;
Expand All @@ -21,6 +22,7 @@ type SwitchFieldProps = {

const SwitchField = (props: SwitchFieldProps & SwitchProps) => {
const { t } = useTranslation();
const { setFetchCloudStatus } = useTeddyCloud();
const { name, label, valueConverter, description, overlayed: initialOverlayed, overlayId, ...switchProps } = props;
const [field, meta, { setValue }] = useField(name!);
const [overlayed, setOverlayed] = useState(initialOverlayed);
Expand Down Expand Up @@ -97,6 +99,11 @@ const SwitchField = (props: SwitchFieldProps & SwitchProps) => {
triggerWriteConfig();
message.success(t("settings.saved"));
})
.then(() => {
if (name === "cloud.enabled") {
setFetchCloudStatus((prev) => !prev);
}
})
.catch((e) => {
message.error("Error while saving config to file.");
});
Expand Down
67 changes: 56 additions & 11 deletions src/components/header/ServerStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Space, Tag, Tooltip } from "antd";
import { CheckCircleOutlined, CloseCircleOutlined } from "@ant-design/icons";
import { CheckCircleOutlined, CloseCircleOutlined, LockOutlined } from "@ant-design/icons";

import { defaultAPIConfig } from "../../config/defaultApiConfig";
import { BoxineApi, BoxineForcedApi } from "../../api";
import { BoxineApi, BoxineForcedApi, TeddyCloudApi } from "../../api";

import { HiddenDesktop, HiddenMobile } from "../StyledComponents";
import { useTeddyCloud } from "../../utils/TeddyCloudContext";

const api = new BoxineApi(defaultAPIConfig());
const api2 = new BoxineForcedApi(defaultAPIConfig());
const apiTC = new TeddyCloudApi(defaultAPIConfig());

export const ServerStatus = () => {
const { t } = useTranslation();
const { fetchCloudStatus } = useTeddyCloud();
const [boxineStatus, setBoxineStatus] = useState<boolean>(false);
const [boxineEnabledStatus, setBoxineEnabledStatus] = useState<boolean>(true);
const [teddyStatus, setTeddyStatus] = useState<boolean>(false);

const fetchBoxineEnabledStatus = async () => {
try {
const cloudEnabled = await apiTC.apiGetTeddyCloudSettingRaw("cloud.enabled");
setBoxineEnabledStatus((await cloudEnabled.text()) === "true");
} catch (err) {
console.log("Something went wrong getting cloud.enabled.");
setBoxineEnabledStatus(false);
}
};

const fetchTime = async () => {
try {
const timeRequest = (await api.v1TimeGet()) as String;
Expand All @@ -25,27 +39,58 @@ export const ServerStatus = () => {
} catch (e) {
setTeddyStatus(false);
}
try {
const timeRequest2 = (await api2.reverseV1TimeGet()) as String;

if (timeRequest2.length === 10) {
setBoxineStatus(true);
if (boxineEnabledStatus) {
try {
const timeRequest2 = (await api2.reverseV1TimeGet()) as String;

if (timeRequest2.length === 10) {
setBoxineStatus(true);
}
} catch (e) {
setBoxineStatus(false);
}
} catch (e) {
setBoxineStatus(false);
}
};

useEffect(() => {
fetchBoxineEnabledStatus();
fetchTime();
}, []);

useEffect(() => {
fetchBoxineEnabledStatus();
fetchTime();
}, [fetchCloudStatus]);

useEffect(() => {
fetchTime();
}, [boxineEnabledStatus]);

return (
<Space>
<Tooltip title={boxineStatus ? t("server.boxineStatusOnline") : t("server.boxineStatusOffline")}>
<Tooltip
title={
boxineEnabledStatus
? boxineStatus
? t("server.boxineStatusOnline")
: t("server.boxineStatusOffline")
: t("server.boxineDisabled")
}
>
<Tag
icon={boxineStatus ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
color={boxineStatus ? "#87d068" : "#f50"}
icon={
boxineEnabledStatus ? (
boxineStatus ? (
<CheckCircleOutlined />
) : (
<CloseCircleOutlined />
)
) : (
<LockOutlined />
)
}
color={boxineEnabledStatus ? (boxineStatus ? "#87d068" : "#f50") : "#faad14"}
bordered={false}
style={{ cursor: "help", color: "#001529" }}
>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/tonieboxes/boxsetup/esp32/ESP32BoxFlashingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import ConfirmationDialog from "../../../../components/utils/ConfirmationDialog"
import AvailableBoxesModal, { connectESP32Explanation } from "../../../../components/tonieboxes/boxSetup/CommonContent";
import DotAnimation from "../../../../components/utils/DotAnimation";
import { isWebSerialSupported } from "../../../../utils/checkWebSerialSupport";
import { useTeddyCloud } from "../../../../utils/TeddyCloudContext";

const api = new TeddyCloudApi(defaultAPIConfig());

Expand Down Expand Up @@ -72,6 +73,7 @@ const { Step } = Steps;

export const ESP32BoxFlashingPage = () => {
const { t } = useTranslation();
const { setFetchCloudStatus } = useTeddyCloud();
const navigate = useNavigate();
const currentLanguage = i18n.language;

Expand Down Expand Up @@ -863,6 +865,7 @@ export const ESP32BoxFlashingPage = () => {
file: state.filename,
})
);
setFetchCloudStatus((prev) => !prev);
} else if (!response.ok && response.status === 409) {
hideLoading();
const errorMessage = await response.text();
Expand Down
Loading

0 comments on commit 2b1592e

Please sign in to comment.