Skip to content

Commit

Permalink
modconf
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Feb 29, 2024
1 parent fd574a2 commit 661e915
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Website/src/activitys/MainApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import ListItemAvatar from "@mui/material/ListItemAvatar";
import Avatar from "@mui/material/Avatar";
import Stack from "@mui/material/Stack";
import Chip from "@mui/material/Chip";
import { ConfigureView } from "@Components/ConfigureView";
import { ModConfView } from "@Components/ModConfView";

const MainApplication = () => {
const { strings } = useStrings();
Expand Down Expand Up @@ -135,7 +135,7 @@ const MainApplication = () => {
component: FetchTextActivity,
key: "changelog",
extra: {
rendering: ConfigureView,
rendering: ModConfView,
url: "https://raw.githubusercontent.com/wiki/DerGoogler/MMRL/JSX-Changelog.md",
modulename: "Update available!",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useActivity } from "@Hooks/useActivity";
import React from "react";
import { SuFile } from "@Native/SuFile";
import { ConfigureView } from "@Components/ConfigureView";
import { ModConfView } from "@Components/ModConfView";
import { useModFS } from "@Hooks/useModFS";
import { PreviewErrorBoundary } from "./ModConfPlaygroundActivity";

Expand All @@ -11,7 +11,7 @@ type Extra = {
moduleid: string;
};

const ConfigureActivity = () => {
const ModConfActivity = () => {
const { modFS } = useModFS();
const { extra } = useActivity<Extra>();

Expand All @@ -31,9 +31,9 @@ const ConfigureActivity = () => {

return (
<PreviewErrorBoundary>
<ConfigureView modid={extra.moduleid} children={config} />
<ModConfView modid={extra.moduleid} children={config} />
</PreviewErrorBoundary>
);
};

export { ConfigureActivity };
export { ModConfActivity };
6 changes: 3 additions & 3 deletions Website/src/activitys/ModConfPlaygroundActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as monacoEditor from "monaco-editor/esm/vs/editor/editor.api";
import Editor, { Monaco } from "@monaco-editor/react";
import { ErrorBoundaryProps, ErrorBoundaryState, errorBoundaryInitialState } from "@Components/ErrorBoundary";
import editorTheme from "@Util/editorTheme";
import { ConfigureView } from "@Components/ConfigureView";
import { ModConfView } from "@Components/ModConfView";
import { useNativeStorage } from "@Hooks/useNativeStorage";
import { useStrings } from "@Hooks/useStrings";
import { useNativeFileStorage } from "@Hooks/useNativeFileStorage";
Expand Down Expand Up @@ -124,7 +124,7 @@ const ModConfPlaygroundActivity = () => {

const handlePreview = () => {
context.pushPage({
component: ConfigureView,
component: ModConfView,
key: extra.title,
extra: {
modulename: "Preview",
Expand Down Expand Up @@ -203,7 +203,7 @@ const ModConfPlaygroundActivity = () => {
<Preview>
<Box component="section" sx={{ width: "100%", height: "100%" }}>
<PreviewErrorBoundary key={"preview_error_bound_key_" + errBoundKey}>
<ConfigureView modid={modFS("MODCONF_PLAYGROUND_MODID")} children={description} />
<ModConfView modid={modFS("MODCONF_PLAYGROUND_MODID")} children={description} />
</PreviewErrorBoundary>
</Box>
</Preview>
Expand Down
5 changes: 2 additions & 3 deletions Website/src/activitys/fragments/DrawerFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { IntentPusher } from "@Hooks/useActivity";
import FetchTextActivity, { FetchTextActivityExtra } from "@Activitys/FetchTextActivity";
import AboutActivity from "@Activitys/AboutActivity";
import PlaygroundsActivity, { PlaygroundExtra } from "@Activitys/PlaygroundsActivity";
import { ConfigureView } from "@Components/ConfigureView";
import { ConfigureActivity } from "@Activitys/ConfigureActivity";
import { ModConfView } from "@Components/ModConfView";
import { Markup } from "@Components/Markdown";
import { configureSample } from "@Util/configure-sample";
import { dapiSample } from "@Util/dapi-sample";
Expand Down Expand Up @@ -139,7 +138,7 @@ export const DrawerFragment = (props: Props) => {
component: FetchTextActivity,
key: "changelog",
extra: {
rendering: ConfigureView,
rendering: ModConfView,
url: "https://raw.githubusercontent.com/wiki/DerGoogler/MMRL/JSX-Changelog.md",
modulename: "Changelog",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const scope = {
Divider: Divider,
};

export const ConfigureView = React.forwardRef<any, { children: string; modid: string }>((props, ref) => {
export const ModConfView = React.forwardRef<any, { children: string; modid: string }>((props, ref) => {
const { theme } = useTheme();
const { modFS } = useModFS();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ prototypeWhitelist.set(Object, new Set());
prototypeWhitelist.set(Document, new Set());
prototypeWhitelist.set(Response, new Set());
prototypeWhitelist.set(Element, new Set());
prototypeWhitelist.set(FileReader, new Set());
prototypeWhitelist.set(Blob, new Set());
prototypeWhitelist.set(SuFile, new Set());
prototypeWhitelist.set(Event, new Set());
prototypeWhitelist.set(View, new Set());
prototypeWhitelist.set(DOMParser, new Set());
prototypeWhitelist.set(ShellClass, new Set());
prototypeWhitelist.set(OsClass, new Set());
prototypeWhitelist.set(BuildConfigClass, new Set());
prototypeWhitelist.set(Build, new Set());
prototypeWhitelist.set(NamedNodeMap, new Set());

export const globals = {
...Sandbox.SAFE_GLOBALS,
Expand All @@ -120,12 +125,17 @@ export const globals = {
INI: require("ini"),
Element: Element,
document: document,
DOMParser: DOMParser,
Toast: Toast,
view: view,
os: os,
Shell: Shell,
Build: Build,
BuildConfig: BuildConfig,
Blob: Blob,
Event: Event,
NamedNodeMap: NamedNodeMap,
FileReader: FileReader,
SuFile: SuFile,
Object: Object,
Response: Response,
Expand Down
4 changes: 2 additions & 2 deletions Website/src/components/module/DeviceModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Chip from "@mui/material/Chip";
import Divider from "@mui/material/Divider";
import Button from "@mui/material/Button";

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

import { Android12Switch } from "@Components/Android12Switch";

Expand Down Expand Up @@ -151,7 +151,7 @@ const DeviceModule = React.memo<Props>((props) => {
<Button
onClick={() => {
context.pushPage({
component: ConfigureActivity,
component: ModConfActivity,
key: `${id}_configure`,
extra: {
modulename: name,
Expand Down
18 changes: 15 additions & 3 deletions Website/src/native/SuFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface NativeSuFileV2 {
class SuFile extends Native<NativeSuFile> {
// @ts-ignore - Won't get even called
private _file: ReturnType<NativeSuFile["v2"]>;
private _fs: IFs = wasmFs.fs;
private _path: string;
private _imgblob: string | ArrayBuffer | null = null;

/**
* @returns `0` as number to create a new file
Expand Down Expand Up @@ -68,6 +68,18 @@ class SuFile extends Native<NativeSuFile> {
}
}

public readAsDataURL(type: string) {
const fileReader = new FileReader();
const imgBlob = new Blob([this.read()], { type: type });
fileReader.readAsDataURL(imgBlob);
fileReader.onload = (e) => {
if (e.target) {
this._imgblob = e.target.result;
}
};
return this._imgblob;
}

public write(content: string): void {
if (this.isAndroid) {
this._file.write(content);
Expand Down Expand Up @@ -156,8 +168,8 @@ class SuFile extends Native<NativeSuFile> {
new SuFile(path).deleteRecursive();
}

public static create(path: string): boolean {
return new SuFile(path).create();
public static create(path: string, type: number = SuFile.NEW_FILE): boolean {
return new SuFile(path).create(type);
}
}

Expand Down

0 comments on commit 661e915

Please sign in to comment.