config-viewer.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { forwardRef, useImperativeHandle, useState } from "react";
  2. import { useTranslation } from "react-i18next";
  3. import { Box, Chip } from "@mui/material";
  4. import { getRuntimeYaml } from "@/services/cmds";
  5. import { DialogRef } from "@/components/base";
  6. import { EditorViewer } from "@/components/profile/editor-viewer";
  7. export const ConfigViewer = forwardRef<DialogRef>((_, ref) => {
  8. const { t } = useTranslation();
  9. const [open, setOpen] = useState(false);
  10. const [runtimeConfig, setRuntimeConfig] = useState("");
  11. useImperativeHandle(ref, () => ({
  12. open: () => {
  13. getRuntimeYaml().then((data) => {
  14. setRuntimeConfig(data ?? "# Error getting runtime yaml\n");
  15. setOpen(true);
  16. });
  17. },
  18. close: () => setOpen(false),
  19. }));
  20. return (
  21. <EditorViewer
  22. title={
  23. <Box>
  24. {t("Runtime Config")}
  25. <Chip label={t("ReadOnly")} size="small" />
  26. </Box>
  27. }
  28. mode="text"
  29. property={runtimeConfig}
  30. open={open}
  31. readOnly
  32. language="yaml"
  33. schema="clash"
  34. onClose={() => setOpen(false)}
  35. />
  36. );
  37. });