Skip to content

Commit

Permalink
terminal improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Mar 28, 2024
1 parent a40515f commit bba0857
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 14 deletions.
128 changes: 128 additions & 0 deletions Website/src/activitys/LogcatActivity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from "react";
import { Add, Remove } from "@mui/icons-material";
import { Stack, Box, Slider } from "@mui/material";
import FlatList from "flatlist-react";
import { Toolbar } from "@Components/onsenui/Toolbar";
import { BottomToolbar } from "@Components/onsenui/BottomToolbar";
import { Page } from "@Components/onsenui/Page";
import { BuildConfig } from "@Native/BuildConfig";
import { useActivity } from "@Hooks/useActivity";
import { useTheme } from "@Hooks/useTheme";
import { useNativeStorage } from "@Hooks/useNativeStorage";
import { useSettings } from "@Hooks/useSettings";
import { Ansi } from "@Components/Ansi";

const LogcatActivity = () => {
const [fontSize, setFontSize] = useNativeStorage("mmrlini_log_terminal", 100);
const { context } = useActivity();
const { theme } = useTheme();
const [lines, setLines] = React.useState<string[]>([]);
const { settings } = useSettings();

const termEndRef = React.useRef<HTMLDivElement>(null);

if (settings.term_scroll_bottom) {
const termBehavior = React.useMemo(() => settings.term_scroll_behavior, [settings]);

React.useEffect(() => {
termEndRef.current?.scrollIntoView({ behavior: termBehavior.value, block: "end", inline: "nearest" });
}, [lines]);
}

const addLine = (line: string) => {
setLines((lines) => [...lines, line]);
};

const startLog = () => {
const envp = {
PACKAGENAME: BuildConfig.APPLICATION_ID,
};

Terminal.exec({
command: "logcat --pid=`pidof -s $PACKAGENAME` -v color",
env: envp,
printError: false,
onLine: (line) => {
addLine(line);
},
onExit: (code) => {},
});
};

return (
<Page
onShow={startLog}
renderToolbar={() => (
<Toolbar modifier="noshadow">
<Toolbar.Left>
<Toolbar.BackButton onClick={context.popPage} />
</Toolbar.Left>
<Toolbar.Center>Logcat</Toolbar.Center>
</Toolbar>
)}
modifier="noshadow"
renderBottomToolbar={() => {
return (
<BottomToolbar sx={{ background: "none", backgroundColor: theme.palette.background.default }}>
<Stack spacing={2} direction="row" sx={{ height: "100%", ml: 1, mr: 1 }} alignItems="center">
<Add color="secondary" />
<Slider
value={fontSize}
onChange={(event, newValue) => {
setFontSize(Number(newValue));
}}
step={10}
marks
min={20}
max={200}
/>
<Remove color="secondary" />
</Stack>
</BottomToolbar>
);
}}
>
<div
style={{
display: "flex",
flexWrap: "wrap",
}}
>
<Stack
style={{
whiteSpace: "pre",
flex: "0 0 100%",
color: "white",
height: "100%",
}}
direction="column"
justifyContent="flex-start"
alignItems="stretch"
spacing={0}
>
<FlatList
list={lines}
renderItem={(line, key) => (
<Box
key={key}
component={Ansi}
sx={{
fontSize: fontSize ? `${fontSize}%` : "none",
ml: 1,
mr: 1,
}}
>
{line}
</Box>
)}
renderOnScroll
renderWhenEmpty={() => <></>}
/>
</Stack>
</div>
<div ref={termEndRef} />
</Page>
);
};

export { LogcatActivity };
17 changes: 15 additions & 2 deletions Website/src/activitys/MainActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import pkg from "@Package";
import UnverifiedHostActivity from "./UnverifiedHostActivity";
import { useModFS } from "@Hooks/useModFS";
import { SuFile } from "@Native/SuFile";
import { LogcatActivity } from "./LogcatActivity";

const CheckRoot = () => {
if (pkg.config.verified_hosts.includes(location.hostname)) {
Expand Down Expand Up @@ -213,7 +214,14 @@ const MainActivity = (): JSX.Element => {
const handleOpenSettings = () => {
pushPage({
component: SettingsActivity,
key: "settings",
key: "SettingsActivity",
});
};

const handleOpenLogcat = () => {
pushPage({
component: LogcatActivity,
key: "LogcatActivity",
});
};

Expand All @@ -236,9 +244,14 @@ const MainActivity = (): JSX.Element => {
<Button fullWidth variant="contained" disableElevation onClick={resetErrorBoundary}>
Try again
</Button>
<Button style={{ marginTop: 16 }} fullWidth variant="contained" disableElevation onClick={handleOpenSettings}>
<Button sx={{ mt: 2 }} fullWidth variant="contained" disableElevation onClick={handleOpenSettings}>
Open settings
</Button>
{os.isAndroid && (
<Button sx={{ mt: 2 }} fullWidth variant="contained" disableElevation onClick={handleOpenLogcat}>
Open Logcat
</Button>
)}

<Pre sx={style}>
<Code>{errorInfo.componentStack}</Code>
Expand Down
20 changes: 17 additions & 3 deletions Website/src/activitys/SettingsActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ function SettingsActivity() {

<Divider />

<List
subheader={<ListSubheader sx={(theme) => ({ bgcolor: theme.palette.background.default })}>{strings("storage")}</ListSubheader>}
>
<List subheader={<ListSubheader>{strings("storage")}</ListSubheader>}>
<ListItemButton
onClick={() => {
setRepos([]);
Expand All @@ -240,6 +238,22 @@ function SettingsActivity() {

<Divider />

{BuildConfig.DEBUG && (
<>
<List subheader={<ListSubheader>Debug</ListSubheader>}>
<ListItemButton
onClick={() => {
throw new Error("Test error thrown!");
}}
>
<ListItemText primary="Throw error" />
</ListItemButton>
</List>

<Divider />
</>
)}

<ListItem>
<ListItemText
primary={
Expand Down
7 changes: 6 additions & 1 deletion Website/src/activitys/TerminalActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Toolbar } from "@Components/onsenui/Toolbar";
import { useActivity } from "@Hooks/useActivity";
import { Button, styled } from "@mui/material";
import Stack from "@mui/material/Stack";
import Box from "@mui/material/Box";
import { Ansi } from "@Components/Ansi";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
import React from "react";
Expand Down Expand Up @@ -307,6 +308,10 @@ const TerminalActivity = () => {
e.callParentHandler();
}
}}
sx={{
// removing bottom window insets
pb: "0px !important",
}}
onShow={install}
modifier="noshadow"
renderToolbar={renderToolbar}
Expand Down Expand Up @@ -335,7 +340,7 @@ const TerminalActivity = () => {
))}
</Stack>
</div>
<div ref={termEndRef} />
<Box sx={{ height: view.getWindowBottomInsets() }} ref={termEndRef} />
</Page>
);
};
Expand Down
23 changes: 19 additions & 4 deletions Website/src/components/module/DeviceModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from "@mui/material/Button";

import { ModConfActivity } from "@Activitys/ModConfActivity";

import { Delete, Settings, RefreshRounded } from "@mui/icons-material";
import { Delete, Settings, RefreshRounded, Loop } from "@mui/icons-material";

import { useTheme } from "@Hooks/useTheme";
import { useSettings } from "@Hooks/useSettings";
Expand Down Expand Up @@ -44,6 +44,7 @@ const DeviceModule = React.memo<Props>((props) => {

const remove = new SuFile(format("REMOVE"));
const disable = new SuFile(format("DISABLE"));
const has_update = SuFile.exist(format("UPDATE"));

const [isEnabled, setIsEnabled] = React.useState(!disable.exist());
const [isSwitchDisabled, setIsSwitchDisabled] = React.useState(remove.exist());
Expand All @@ -59,8 +60,8 @@ const DeviceModule = React.memo<Props>((props) => {
const module_config_file = SuFile.exist(format("CONFINDEX"));

return (
<Card sx={{ p: 2, width: "100%" }}>
<Stack direction="column" justifyContent="center" spacing={1}>
<Card sx={{ position: "relative", p: 2, width: "100%" }}>
<Stack sx={{ position: "relative", zIndex: 1 }} direction="column" justifyContent="center" spacing={1}>
{cover && (
<Image
sx={(theme) => ({
Expand Down Expand Up @@ -113,7 +114,7 @@ const DeviceModule = React.memo<Props>((props) => {
<Typography variant="caption" display="block">
<Switch
checked={isEnabled}
disabled={isSwitchDisabled}
disabled={isSwitchDisabled || has_update}
onChange={(e) => {
const checked = e.target.checked;

Expand Down Expand Up @@ -228,6 +229,20 @@ const DeviceModule = React.memo<Props>((props) => {
</Stack>
</Stack>
</Stack>
{has_update && (
<Loop
sx={{
position: "absolute",
left: "50%",
top: "50%",
fill: theme.palette.background.default,
color: theme.palette.background.default,
WebkitTransform: "translate(-50%, -50%)",
transform: "translate(-50%, -50%)",
fontSize: "50cqmin",
}}
/>
)}
</Card>
);
});
Expand Down
8 changes: 4 additions & 4 deletions Website/src/components/onsenui/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ interface HTMLPage {
renderToolbar?: RenderFunction;
renderBottomToolbar?: RenderFunction;
renderFixed?: RenderFunction;
onInit?: Function;
onShow?: Function;
onHide?: Function;
onInfiniteScroll?: Function;
onInit?: void | Function;
onShow?: void | Function;
onHide?: void | Function;
onInfiniteScroll?: () => void;
onDeviceBackButton?: (event: DeviceBackButtonEvent) => void;
children?: React.ReactNode;
statusbarColor?: string;
Expand Down

0 comments on commit bba0857

Please sign in to comment.