diff --git a/Android/app/src/main/java/com/dergoogler/component/ModuleView.java b/Android/app/src/main/java/com/dergoogler/component/ModuleView.java index 64f55dd6..321c87c0 100644 --- a/Android/app/src/main/java/com/dergoogler/component/ModuleView.java +++ b/Android/app/src/main/java/com/dergoogler/component/ModuleView.java @@ -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"); } diff --git a/Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java b/Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java index 4b9905c4..b224e5d7 100755 --- a/Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java +++ b/Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d21b482..ecc0e371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Website/src/activitys/MainActivity.tsx b/Website/src/activitys/MainActivity.tsx index 5a84928e..d5649b6b 100644 --- a/Website/src/activitys/MainActivity.tsx +++ b/Website/src/activitys/MainActivity.tsx @@ -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; @@ -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; } @@ -53,7 +54,7 @@ class MainActivity extends Component { component: CheckRoot(), props: { key: "main", - pushPage: (...args: any) => this.pushPage.apply(null, args), + pushPage: (...args: [props: PushProps]) => this.pushPage.apply(null, args), }, }, ]); @@ -61,51 +62,28 @@ class MainActivity extends Component { 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({ @@ -131,6 +109,9 @@ class MainActivity extends Component { }, }); + // Remove fake path + window.history.back(); + this.setState({ routeConfig, currentPage: "main" }); }; diff --git a/Website/src/activitys/MainApplication.tsx b/Website/src/activitys/MainApplication.tsx index a1fb9cd1..d2875824 100644 --- a/Website/src/activitys/MainApplication.tsx +++ b/Website/src/activitys/MainApplication.tsx @@ -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"; @@ -37,7 +38,7 @@ class MainApplication extends AppCompatActivity {
{ - 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 diff --git a/Website/src/activitys/ViewModuleActivity.tsx b/Website/src/activitys/ViewModuleActivity.tsx index 9a93b95d..d5f052b8 100644 --- a/Website/src/activitys/ViewModuleActivity.tsx +++ b/Website/src/activitys/ViewModuleActivity.tsx @@ -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"; @@ -21,6 +21,8 @@ interface States { } class ViewModuleActivity extends AppCompatActivity { + public static readonly ignoreURL: bool = true; + public constructor(props: Props | Readonly) { super(props); this.state = { diff --git a/Website/src/activitys/fragments/ExploreModuleFragment.tsx b/Website/src/activitys/fragments/ExploreModuleFragment.tsx index 66e806be..a5454590 100644 --- a/Website/src/activitys/fragments/ExploreModuleFragment.tsx +++ b/Website/src/activitys/fragments/ExploreModuleFragment.tsx @@ -84,21 +84,6 @@ class ExploreModuleFragment extends Component { public render = () => { const { search, loading } = this.state; - const modules = this.state.modulesIndex.map((item: any) => { - return ( - - ); - }); return ( <> @@ -160,24 +145,34 @@ class ExploreModuleFragment extends Component { paddingBottom: "4px", }} > - {(() => { - if (loading) { + {loading ? ( + + ) : ( + this.state.modulesIndex.map((item: any) => { return ( - ); - } else { - return modules; - } - })()} + }) + )}
diff --git a/Website/src/components/ExploreModule.tsx b/Website/src/components/ExploreModule.tsx index 8e4a85e2..aaca0af8 100644 --- a/Website/src/components/ExploreModule.tsx +++ b/Website/src/components/ExploreModule.tsx @@ -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; @@ -131,6 +132,11 @@ class ExploreModule extends Component {
{ + // 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, diff --git a/Website/src/index.tsx b/Website/src/index.tsx index f7e786cf..d00b9020 100644 --- a/Website/src/index.tsx +++ b/Website/src/index.tsx @@ -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 @@ -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"); @@ -44,8 +42,7 @@ class Bootloader { this.log.i("Loading MainActivty"); ReactDOM.render( <> - - + , this.mountNode ); diff --git a/Website/src/native/Toast.ts b/Website/src/native/Toast.ts index deaab294..65906fcd 100644 --- a/Website/src/native/Toast.ts +++ b/Website/src/native/Toast.ts @@ -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; @@ -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" }); } } } diff --git a/Website/src/utils/tools.ts b/Website/src/utils/tools.ts index 1df40cc2..12da387f 100644 --- a/Website/src/utils/tools.ts +++ b/Website/src/utils/tools.ts @@ -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;