From 08149334b8e6f419f46e56e9c0e595b14f13f7cc Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 24 Feb 2024 22:12:17 +0100 Subject: [PATCH] add config page --- README.md | 2 +- module.prop | 4 +- .../code_server/components/SelectDialog.jsx | 40 +++++ .../share/mmrl/config/code_server/index.jsx | 150 ++++++++++++++++++ .../mmrl/config/code_server/util/AuthTypes.js | 1 + 5 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 system/usr/share/mmrl/config/code_server/components/SelectDialog.jsx create mode 100644 system/usr/share/mmrl/config/code_server/index.jsx create mode 100644 system/usr/share/mmrl/config/code_server/util/AuthTypes.js diff --git a/README.md b/README.md index 31c9fdc..493e676 100644 --- a/README.md +++ b/README.md @@ -18,5 +18,5 @@ Magisk or [Fox's Magisk Module Manager][foxm] ## Config location ``` -/data/chuser//home/.config +/data/mkuser//home/.config ``` \ No newline at end of file diff --git a/module.prop b/module.prop index 48284d1..231cc12 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=code_server name=Code Server -version=1.2.5 -versionCode=125 +version=2.0.0 +versionCode=200 author=coder, vhqtvn & Der_Googler description=VS Code in the browser diff --git a/system/usr/share/mmrl/config/code_server/components/SelectDialog.jsx b/system/usr/share/mmrl/config/code_server/components/SelectDialog.jsx new file mode 100644 index 0000000..043193f --- /dev/null +++ b/system/usr/share/mmrl/config/code_server/components/SelectDialog.jsx @@ -0,0 +1,40 @@ +import React from "react" +import { + List, + ListItem, + ListItemButton, + ListItemText, + DialogTitle, + Dialog, + } from "@mui/material"; + +import AuthTypes from "/util/authTypes.js" + +function SelectDialog(props) { + const { onClose, selectedValue, open } = props; + + const handleClose = () => { + onClose(selectedValue); + }; + + const handleListItemClick = (value) => { + onClose(value); + }; + + return ( + + Select auth type + + {AuthTypes.map((type) => ( + + handleListItemClick(type)}> + + + + ))} + + + ); +} + +export default SelectDialog; diff --git a/system/usr/share/mmrl/config/code_server/index.jsx b/system/usr/share/mmrl/config/code_server/index.jsx new file mode 100644 index 0000000..174cbda --- /dev/null +++ b/system/usr/share/mmrl/config/code_server/index.jsx @@ -0,0 +1,150 @@ +import React from "react"; +import { Save } from "@mui/icons-material"; +import { + Box, + Alert, + ListItemButton, + ListItemText +} from "@mui/material"; +import { Page, Toolbar } from "@mmrl/ui"; +import { useActivity, useTheme } from "@mmrl/hooks"; +import { write, exist } from "@mmrl/sufile"; + +const cfgPath = "/data/mkuser/root/.config/code-server/config.yaml"; +const cfg = require(cfgPath); +const hasCfg = exist(cfgPath); + +import AuthTypes from "/util/AuthTypes.js" +import SelectDialog from "/components/SelectDialog.jsx" + +function App() { + const { context } = useActivity(); + + const [bindAddr, setBindAddr] = React.useState(cfg["bind-addr"]); + const [auth, setAuth] = React.useState(cfg["auth"]); + const [password, setPassword] = React.useState(cfg["password"]); + const [cert, setCert] = React.useState(cfg["cert"]); + + const saveConfig = React.useCallback(() => { + write( + cfgPath, + YAML.stringify( + { + "bind-addr": bindAddr, + auth: auth, + password: password, + cert: cert, + }, + null, + 4 + ) + ); + }, [bindAddr, auth, password, cert]); + + const renderToolbar = () => { + return ( + + + + + Code Server + + + + + ); + }; + + const [open, setOpen] = React.useState(false); + + const handleClickOpen = () => { + setOpen(true); + }; + + const handleClose = (value) => { + setOpen(false); + setAuth(value); + }; + + return ( + + + Do not forget to save your config! + + + Settings}> + { + if (val) setBindAddr(val); + }} + inputLabel="Address" + type="text" + title="Change address" + initialValue={bindAddr} + > + + + + + + + + + + { + if (val) setPassword(val); + }} + inputLabel="Password" + type="text" + title="Change password" + initialValue={password} + > + + + + + setCert(e.target.checked)} /> + + + + ); +} + + + +export default () => { + const { context } = useActivity(); + const { theme } = useTheme(); + + if (hasCfg) { + return ; + } else { + return ( + ( + + + + + Code Server + + )} + > + + Config file was not found. + + + ); + } +}; diff --git a/system/usr/share/mmrl/config/code_server/util/AuthTypes.js b/system/usr/share/mmrl/config/code_server/util/AuthTypes.js new file mode 100644 index 0000000..5683652 --- /dev/null +++ b/system/usr/share/mmrl/config/code_server/util/AuthTypes.js @@ -0,0 +1 @@ +export default ["password", "none"]; \ No newline at end of file