Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Der_Googler committed Jun 13, 2022
1 parent 090ef78 commit 594bdb1
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public void setAllowUniversalAccessFromFileURLs(boolean enabled) {
this.webSettings.setAllowUniversalAccessFromFileURLs(enabled);
}

public void setDomStorageEnabled(boolean enabled) {
this.webSettings.setDomStorageEnabled(enabled);
}

public void setDatabaseEnabled(boolean enabled) {
this.webSettings.setDatabaseEnabled(enabled);
}

public void loadHTML(String htmlString) {
this.loadData(htmlString, "text/html", "UTF-8");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected void onCreate(Bundle savedInstanceState) {
view.setAllowContentAccess(true);
view.setAllowFileAccessFromFileURLs(true);
view.setAllowUniversalAccessFromFileURLs(true);
view.setDatabaseEnabled(true);
view.setDomStorageEnabled(false);
view.setUserAgentString("MMRL");

// Content
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Fixed Android version
- Removed `setPref` & `getPref`. Now should be merged to the new API
- Depen. updated
-
- Added fake url system

## App
- Fix white statusbar
Expand Down
59 changes: 20 additions & 39 deletions Website/src/activitys/MainActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MainApplication from "@Activitys/MainApplication";
import Constants from "@Native/Constants";
import NoRootActivity from "./NoRootActivity";
import Shell from "@Native/ShellBuilder";
import tools from "@Utils/tools";

interface ModuleOptions {
verified?: boolean;
Expand All @@ -20,9 +21,9 @@ export interface ModuleProps {
}

export interface PushProps {
activity?: JSX.Element | any;
activity: any;
key?: any;
extras?: any;
extra?: any;
moduleOptions?: ModuleOptions;
moduleProps?: ModuleProps;
}
Expand Down Expand Up @@ -53,59 +54,36 @@ class MainActivity extends Component<PushProps, States> {
component: CheckRoot(),
props: {
key: "main",
pushPage: (...args: any) => this.pushPage.apply(null, args),
pushPage: (...args: [props: PushProps]) => this.pushPage.apply(null, args),
},
},
]);

this.state = { routeConfig, currentPage: "main" };
}

public componentDidMount = () => {
window.addEventListener("load", this.windowLoadPush);
};

public componentWillUnmount = () => {
window.removeEventListener("load", this.windowLoadPush);
};

private windowLoadPush = () => {
if (typeof history.pushState === "function") {
history.pushState("jibberish", "", null);
window.onpopstate = () => {
history.pushState("newjibberish", "", null);
if (this.state.currentPage === "main") {
if (Constants.isAndroid) {
nos.close();
}
} else {
this.popPage();
}
};
} else {
var ignoreHashChange = true;
window.onhashchange = () => {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random().toString();
} else {
ignoreHashChange = false;
}
};
}
};

private pushPage = (props: any) => {
private pushPage = (props: PushProps): void & PushProps => {
const route = {
component: props.activity,
props: {
key: props.key,
extra: props?.extra,
popPage: () => this.popPage(),
pushPage: (...args: any) => this.pushPage.apply(null, args),
pushPage: (...args: [props: PushProps]) => this.pushPage.apply(null, args),
},
};

// Make an fake path. Note: The page should not refreshed!
tools.setURL((set, currentPath) => {
const acty = props.activity;
const getName = () => {
return acty.name.toLowerCase().replace("activity", "");
};
if (!acty.ignoreURL) {
set(props.key, props.key, `${currentPath}/#${getName()}`);
}
});

let routeConfig = this.state.routeConfig;

routeConfig = RouterUtil.push({
Expand All @@ -131,6 +109,9 @@ class MainActivity extends Component<PushProps, States> {
},
});

// Remove fake path
window.history.back();

this.setState({ routeConfig, currentPage: "main" });
};

Expand Down
3 changes: 2 additions & 1 deletion Website/src/activitys/MainApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SettingsRounded } from "@mui/icons-material";
import SharedPreferences from "@Native/SharedPreferences";
import Toast from "@Native/Toast";
import ons from "onsenui";
import { Tab, Tabbar, Toolbar, ToolbarButton } from "react-onsenui";
import AppCompatActivity from "./AppCompatActivity";
Expand Down Expand Up @@ -37,7 +38,7 @@ class MainApplication extends AppCompatActivity<Props> {
<div
className="center"
onClick={() => {
ons.notification.toast("My gf left me ... :(", { timeout: 1000, animation: "fall" });
Toast.makeText("My gf left me ... :(", Toast.LENGTH_SHORT).show();
}}
>
Magisk Module Repo Loader
Expand Down
4 changes: 3 additions & 1 deletion Website/src/activitys/ViewModuleActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Toolbar, ToolbarButton, BackButton, Button, Dialog } from "react-onsenui";
import { ToolbarButton, Dialog, Button } from "react-onsenui";
import ons from "onsenui";
import axios from "axios";
import { DownloadRounded, InfoRounded, InstallMobileRounded, VerifiedRounded } from "@mui/icons-material";
Expand All @@ -21,6 +21,8 @@ interface States {
}

class ViewModuleActivity extends AppCompatActivity<Props, States> {
public static readonly ignoreURL: bool = true;

public constructor(props: Props | Readonly<Props>) {
super(props);
this.state = {
Expand Down
55 changes: 25 additions & 30 deletions Website/src/activitys/fragments/ExploreModuleFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,6 @@ class ExploreModuleFragment extends Component<Props, States> {

public render = () => {
const { search, loading } = this.state;
const modules = this.state.modulesIndex.map((item: any) => {
return (
<ExploreModule
key={item.id}
getId={item.id}
propsUrl={item.prop_url}
notesUrl={item.notes_url}
downloadUrl={item.zip_url}
pushPage={this.props.pushPage}
searchState={search}
moduleOptions={this.state.moduleOptions}
last_update={item.last_update}
/>
);
});

return (
<>
Expand Down Expand Up @@ -160,24 +145,34 @@ class ExploreModuleFragment extends Component<Props, States> {
paddingBottom: "4px",
}}
>
{(() => {
if (loading) {
{loading ? (
<ProgressCircular
indeterminate
style={{
position: "absolute",
left: "50%",
top: "50%",
WebkitTransform: "translate(-50%, -50%)",
transform: "translate(-50%, -50%)",
}}
/>
) : (
this.state.modulesIndex.map((item: any) => {
return (
<ProgressCircular
indeterminate
style={{
position: "absolute",
left: "50%",
top: "50%",
WebkitTransform: "translate(-50%, -50%)",
transform: "translate(-50%, -50%)",
}}
<ExploreModule
key={item.id}
getId={item.id}
propsUrl={item.prop_url}
notesUrl={item.notes_url}
downloadUrl={item.zip_url}
pushPage={this.props.pushPage}
searchState={search}
moduleOptions={this.state.moduleOptions}
last_update={item.last_update}
/>
);
} else {
return modules;
}
})()}
})
)}
</module-container>
</div>
</>
Expand Down
6 changes: 6 additions & 0 deletions Website/src/components/ExploreModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ViewModuleActivity from "@Activitys/ViewModuleActivity";
import Log from "@Native/Log";
import { VerifiedRounded } from "@mui/icons-material";
import { os } from "@Native/os";
import Toast from "@Native/Toast";

interface Props {
notesUrl?: string;
Expand Down Expand Up @@ -131,6 +132,11 @@ class ExploreModule extends Component<Props, States> {
<div
ref={this.openReadmeFromParam}
onClick={() => {
// Make an fake path. Note: The page should not refreshed!
tools.setURL((set, currentPath) => {
set(`view_${props.id}`, `view_${props.id}`, `${currentPath}/?module=${props.id}`);
});

pushPage({
key: `view_${props.id}`,
activity: ViewModuleActivity,
Expand Down
7 changes: 2 additions & 5 deletions Website/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import jss from "jss";
import preset from "jss-preset-default";
import light_theme from "@Styles/light_theme";
import dark_theme from "@Styles/dark_theme";
import Constants from "@Native/Constants";
import { ToastContainer } from "react-toastify";
import MainApplication from "@Activitys/MainApplication";
import SharedPreferences, { ISharedPreferences } from "@Native/SharedPreferences";

// Webpack CSS import
Expand All @@ -18,7 +17,6 @@ import "react-toastify/dist/ReactToastify.css";
import "@Styles/addtional.scss";
import "@Styles/markdown-light.scss";
import "@Styles/markdown-dark.scss";
import { isMobile } from "react-device-detect";

class Bootloader {
private mountNode: Element | null = document.querySelector("app");
Expand All @@ -44,8 +42,7 @@ class Bootloader {
this.log.i("Loading MainActivty");
ReactDOM.render(
<>
<MainActivity />
<ToastContainer />
<MainActivity activity={MainApplication} />
</>,
this.mountNode
);
Expand Down
10 changes: 7 additions & 3 deletions Website/src/native/Toast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Constants from "@Native/Constants";
import ons from "onsenui";
import { os } from "./os";

class Toast {
public static readonly LENGTH_LONG: int = 1;
public static readonly LENGTH_SHORT: int = 0;
public static readonly LENGTH_LONG: int = os.isAndroid ? 1 : 5000;
public static readonly LENGTH_SHORT: int = os.isAndroid ? 0 : 2000;
private static duration: int;
private static text: string;

Expand All @@ -13,8 +15,10 @@ class Toast {
}

public show(): void {
if (Constants.isAndroid) {
if (os.isAndroid) {
nos.makeToast(Toast.text, Toast.duration);
} else {
ons.notification.toast(Toast.text, { timeout: Toast.duration, animation: "fall" });
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Website/src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ class tools {
return false;
}
}

public static setURL(
callback: (set: (data: any, unused: string, url?: string | URL | null | undefined) => void, currentPath: string) => void
): void {
const loc = window.location.pathname;
const set = (data: any, unused: string, url?: string | URL | null | undefined) => window.history.pushState(data, unused, url);
const currentPath: string = loc === "/" ? "" : loc;
if (typeof callback == "function") {
callback(set, currentPath);
}
}
}

export default tools;

0 comments on commit 594bdb1

Please sign in to comment.