Skip to content

Commit

Permalink
Configure API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Oct 27, 2023
1 parent 641d3ba commit e360319
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 181 deletions.
436 changes: 299 additions & 137 deletions Website/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@
"@mui/material": "^5.13.7",
"@nyariv/sandboxjs": "^0.8.23",
"@primer/octicons-react": "^19.4.0",
"@wasmer/wasmfs": "^0.12.0",
"ace-builds": "^1.23.3",
"ajv": "^8.12.0",
"ansi-to-react": "^6.1.6",
"axios": "^0.27.2",
"browserfs": "^1.4.3",
"default-composer": "^0.4.0",
"eruda": "^3.0.0",
"flatlist-react": "^1.5.14",
"framer-motion": "^10.16.4",
"fs-monkey": "^1.0.5",
"googlers-tools": "^1.2.8",
"highlight.js": "^11.6.0",
"install": "^0.13.0",
Expand Down
77 changes: 60 additions & 17 deletions Website/src/components/ConfigureView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import Sandbox from "@nyariv/sandboxjs";
import { transform, registerPlugin } from "@babel/standalone";
import * as React from "react";
import { PluginObj } from "@babel/core";
import { globals } from "./libs";
import { globals, libraries } from "./libs";
import { DialogEditListItem, StyledListSubheader } from "./components";
import { SuFile, wasmFs } from "@Native/SuFile";
import { ModConf, useSettings } from "@Hooks/useSettings";

function plugin({ types: t }): PluginObj {
return {
Expand Down Expand Up @@ -67,22 +69,63 @@ const scope = {

export const ConfigureView = React.memo<PreviewErrorBoundaryChildren>((props) => {
const { theme } = useTheme();
const Component = sandbox
.compile<React.FunctionComponent<any>>(parseCode(props.children as string))({
modid: props.modid,
window: {
open(href: string) {
os.open(href, {
target: "_blank",
features: {
color: theme.palette.primary.main,
},
});
},
const { modConf } = useSettings();

const format = React.useCallback<<K extends keyof ModConf>(key: K) => ModConf[K]>((key) => modConf(key, { MODID: props.modid }), []);

React.useEffect(() => {
wasmFs.volume.fromJSON(
{
[format("PROPS")]: `id=${props.modid}`,
[format("CONFINDEX")]: 'export default "DO NOT USE THIS FILE OR IMPORT IT!"',
},
...scope,
})
.run();
format("CONFCWD")
);
}, [props.modid]);

return <Component />;
const box = React.useCallback(
(code: string) =>
sandbox
.compile<React.FunctionComponent<any> | undefined>(
parseCode(code),
true
)({
modid: props.modid,
modpath: (path: string) => `${format("MODULECWD")}/${path}`,
confpath: (path: string) => `${format("CONFCWD")}/${path}`,
window: {
open(href: string) {
os.open(href, {
target: "_blank",
features: {
color: theme.palette.primary.main,
},
});
},
},
require(id: string) {
if (id.startsWith("!conf/")) {
const filename = id.replace(/!conf\/(.+)/gm, `${format("CONFCWD")}/$1`);
const file = new SuFile(filename);
if (file.exist()) {
return box(file.read());
} else {
return `Imported \"${filename}\" file not found`;
}
} else {
return libraries.find((lib) => id === lib.name)?.__esModule;
}
},
...scope,
})
.run(),
[]
);
const Component = box(props.children as string);

if (Component) {
return <Component />;
} else {
return <div>export is undefined</div>;
}
});
18 changes: 12 additions & 6 deletions Website/src/components/ConfigureView/libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useNativeProperties } from "@Hooks/useNativeProperties";
import { Markdown, PromoBanner } from "./components";
import { useActivity } from "@Hooks/useActivity";
import { Toolbar } from "@Components/onsenui/Toolbar";
import { SuFile } from "@Native/SuFile";
import { os } from "@Native/Os";

export const libraries = [
{
Expand Down Expand Up @@ -54,18 +56,22 @@ export const libraries = [
},

{
name: "@mmrl/native",
name: "@mmrl/sufile",
__esModule: {
// SuFile: SuFile,
read: SuFile.read,
write: SuFile.write,
list: SuFile.list,
exist: SuFile.exist,
delete: SuFile.delete,
deleteRecursive: SuFile.deleteRecursive,
},
},
];

const prototypeWhitelist = Sandbox.SAFE_PROTOTYPES;
prototypeWhitelist.set(Node, new Set());

export const globals = {
...Sandbox.SAFE_GLOBALS,
Object,
// React: require("react"),
require(id: string) {
return libraries.find((lib) => id === lib.name)?.__esModule;
},
};
30 changes: 16 additions & 14 deletions Website/src/hooks/useSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface ModConf {
// default paths
ADB: string;
MODULES: string;
MODULECWD: string;
PROPS: string;
SYSTEM: string;
SEPOLICY: string;
Expand Down Expand Up @@ -215,26 +216,27 @@ export const INITIAL_MOD_CONF: ModConf = {
// default paths
ADB: "/data/adb",
MODULES: "<ADB>/modules",
PROPS: "<MODULES>/<MODID>/module.prop",
SYSTEM: "<MODULES>/<MODID>/system.prop",
SEPOLICY: "<MODULES>/<MODID>/sepolicy.rule",
CONFIG: `<MODULES>/<MODID>/system/usr/share/mmrl/config/<MODID>.mdx`,
MODULECWD: "<MODULES>/<MODID>",
PROPS: "<MODULECWD>/module.prop",
SYSTEM: "<MODULECWD>/system.prop",
SEPOLICY: "<MODULECWD>/sepolicy.rule",
CONFIG: `<MODULECWD>/system/usr/share/mmrl/config/<MODID>.mdx`,

// service paths
LATESERVICE: "<MODULES>/<MODID>/service.sh",
POSTSERVICE: "<MODULES>/<MODID>/post-fs-data.sh",
POSTMOUNT: "<MODULES>/<MODID>/post-mount.sh",
BOOTCOMP: "<MODULES>/<MODID>/boot-completed.sh",
LATESERVICE: "<MODULECWD>/service.sh",
POSTSERVICE: "<MODULECWD>/post-fs-data.sh",
POSTMOUNT: "<MODULECWD>/post-mount.sh",
BOOTCOMP: "<MODULECWD>/boot-completed.sh",

// status paths
SKIPMOUNT: "<MODULES>/<MODID>/skip_mount",
DISABLE: "<MODULES>/<MODID>/disable",
REMOVE: "<MODULES>/<MODID>/remove",
UPDATE: "<MODULES>/<MODID>/update",
SKIPMOUNT: "<MODULECWD>/skip_mount",
DISABLE: "<MODULECWD>/disable",
REMOVE: "<MODULECWD>/remove",
UPDATE: "<MODULECWD>/update",

// others
MMRLINI: "<MODULES>/mmrl_install_tools",
CONFCWD: "<MODULES>/<MODID>/system/usr/share/mmrl/config/<MODID>",
MMRLINI: "<MODULECWD>/mmrl_install_tools",
CONFCWD: "<MODULECWD>/system/usr/share/mmrl/config/<MODID>",
CONFINDEX: "<CONFCWD>/index.jsx",
};

Expand Down
25 changes: 23 additions & 2 deletions Website/src/native/SuFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IFs } from "memfs";
import { Native } from "./Native";
import { WasmFs } from "@wasmer/wasmfs";

export const wasmFs = new WasmFs();

interface NativeSuFile {
readFile(path: string): string;
Expand All @@ -15,18 +19,31 @@ interface NativeSuFile {
*/
class SuFile extends Native<NativeSuFile> {
private path: string;
private _fs: IFs = wasmFs.fs;

public constructor(path?: string) {
super();
this.path = path ? path : "";
this.interfaceName = "__sufile__";
// Support for browsers
// if (!this.isAndroid) {
// this._fs = null as unknown as IFs;
// }
}

public read(): string {
if (this.isAndroid) {
return this.getInterface.readFile(this.path);
} else {
return "";
return this._fs.readFileSync(this.path).toString();
}
}

public write(content: string): void {
if (this.isAndroid) {
null;
} else {
this._fs.writeFileSync(this.path, content);
}
}

Expand All @@ -49,7 +66,7 @@ class SuFile extends Native<NativeSuFile> {
if (this.isAndroid) {
return this.getInterface.existFile(this.path);
} else {
return false;
return this._fs.existsSync(this.path);
}
}

Expand Down Expand Up @@ -79,6 +96,10 @@ class SuFile extends Native<NativeSuFile> {
return new SuFile(path).read();
}

public static write(path: string, content: string): void {
new SuFile(path).write(content);
}

/**
*
* @param path
Expand Down
5 changes: 3 additions & 2 deletions Website/src/util/configure-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,6 @@ function InstallToolsConfig() {
);
}
export default InstallToolsConfig;
`;
export default {
onCreate: InstallToolsConfig
};`;
1 change: 0 additions & 1 deletion Website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"emitDeclarationOnly": false,
"experimentalDecorators": true,
"declarationMap": false,
"allowImportingTsExtensions": true,
"typeRoots": ["src/typings/global.d.ts"],
"sourceMap": true,
"strict": true,
Expand Down
1 change: 0 additions & 1 deletion Website/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Configuration, DefinePlugin } from "webpack";
import webpackDevServer from "webpack-dev-server";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import * as fs from "fs";

const outputPath = "./../www";

Expand Down

0 comments on commit e360319

Please sign in to comment.