-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a40515f
commit bba0857
Showing
6 changed files
with
189 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters