Skip to content

Commit b5e275a

Browse files
committed
Readd eruda console
1 parent 8566867 commit b5e275a

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

Website/src/activitys/MainActivity.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { RouterNavigator } from "@Components/onsenui/RouterNavigator";
1919
import { DrawerFragment } from "./fragments/DrawerFragment";
2020
import { Toolbar } from "@Components/onsenui/Toolbar";
2121
import { Page } from "@Components/onsenui/Page";
22+
import eruda from "eruda";
2223

2324
const MainActivity = (): JSX.Element => {
2425
const { settings } = useSettings();
@@ -33,6 +34,16 @@ const MainActivity = (): JSX.Element => {
3334
setIsSplitterOpen(true);
3435
};
3536

37+
React.useEffect(() => {
38+
if (settings.eruda_console_enabled) {
39+
eruda.init();
40+
} else {
41+
if ((window as any).eruda) {
42+
eruda.destroy();
43+
}
44+
}
45+
}, [settings.eruda_console_enabled]);
46+
3647
React.useEffect(() => {
3748
if (!os.hasStoragePermission()) {
3849
os.requestStoargePermission();

Website/src/activitys/SettingsActivity.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Divider, List, ListItem, ListItemButton, ListItemIcon, ListSubheader, Switch } from "@mui/material";
1+
import { Divider, List, ListItem, ListItemButton, ListSubheader } from "@mui/material";
22
import { BuildConfig } from "@Native/BuildConfig";
33
import { Toolbar } from "@Components/onsenui/Toolbar";
44
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
@@ -84,19 +84,19 @@ function SettingsActivity() {
8484
<List
8585
subheader={<ListSubheader sx={(theme) => ({ bgcolor: theme.palette.background.default })}>{strings.development}</ListSubheader>}
8686
>
87-
{/* <ListItem>
88-
<StyledListItemText id="switch-list-label-eruda" primary={"Eruda console"} secondary={"Useful for development and bugs"} />
89-
<Android12Switch
90-
edge="end"
91-
onChange={(e: any) => {
92-
setSettings("eruda_console_enabled", e.target.checked);
93-
}}
94-
checked={settings.eruda_console_enabled}
95-
inputProps={{
96-
"aria-labelledby": "switch-list-label-eruda",
97-
}}
98-
/>
99-
</ListItem> */}
87+
<ListItem>
88+
<StyledListItemText id="switch-list-label-eruda" primary={"Eruda console"} secondary={"Useful for development and bugs"} />
89+
<Android12Switch
90+
edge="end"
91+
onChange={(e: any) => {
92+
setSettings("eruda_console_enabled", e.target.checked);
93+
}}
94+
checked={settings.eruda_console_enabled}
95+
inputProps={{
96+
"aria-labelledby": "switch-list-label-eruda",
97+
}}
98+
/>
99+
</ListItem>
100100
<ListItemButton
101101
onClick={() => {
102102
os.open("https://github.com/DerGoogler/MMRL/issues", {

Website/src/hooks/useSettings.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defaultComposer } from "default-composer";
44
import { useNativeStorage } from "./useNativeStorage";
55
import { languages_map } from "../locales/languages";
66
import { os } from "@Native/Os";
7+
import { SetStateAction } from "./useStateCallback";
78

89
export const accent_colors: Picker<string, any>[] = [
910
{
@@ -154,9 +155,22 @@ export const INITIAL_SETTINGS: StorageDeclaration = {
154155
test: [],
155156
};
156157

157-
export const SettingsContext = createContext<any>({
158+
export interface Context {
159+
settings: StorageDeclaration;
160+
setSettings<K extends keyof StorageDeclaration>(
161+
key: K,
162+
state: SetStateAction<StorageDeclaration[K]>,
163+
callback?: (state: StorageDeclaration[K]) => void
164+
): void;
165+
}
166+
167+
export const SettingsContext = createContext<Context>({
158168
settings: INITIAL_SETTINGS,
159-
setSettings(key: any, state: any, callback?: (state: any) => void) {},
169+
setSettings<K extends keyof StorageDeclaration>(
170+
key: K,
171+
state: SetStateAction<StorageDeclaration[K]>,
172+
callback?: (state: StorageDeclaration[K]) => void
173+
) {},
160174
});
161175

162176
export const useSettings = () => {
@@ -177,7 +191,7 @@ export const SettingsProvider = (props: React.PropsWithChildren) => {
177191
return {
178192
...prev,
179193
[name]: state,
180-
};
194+
};
181195
},
182196
(state) => callback && callback(state[name])
183197
);

0 commit comments

Comments
 (0)