Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Nov 11, 2023
1 parent c37a9d0 commit 9cbb45f
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 120 deletions.
4 changes: 0 additions & 4 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ android {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexEnabled true
// project.tasks.preBuild.dependsOn("webProd")
}
debug {
resValue "string", "app_name", "${app_name} Debug"
Expand All @@ -52,7 +51,6 @@ android {
minifyEnabled false
multiDexEnabled false
applicationIdSuffix '.debug'
// project.tasks.preBuild.dependsOn("webDev")
}
}
externalNativeBuild {
Expand Down Expand Up @@ -94,8 +92,6 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "org.apache.cordova:framework:10.1.1"
implementation "androidx.webkit:webkit:1.8.0"
implementation 'com.jraska:console:1.2.0'
// implementation 'com.google.android.material:material:1.6.0'
}

configurations.implementation.setCanBeResolved(true)
Expand Down
9 changes: 4 additions & 5 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<queries>
<package android:name="com.topjohnwu.magisk" />
Expand All @@ -31,9 +33,6 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="mmrl.dergoogler.com" />
<data android:scheme="mmrl" android:host="mmrl.dergoogler.com" />
</intent-filter>
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public void defineName(String name) {
this.localStorageName = name;
}

@JavascriptInterface
public String getItem(String key, String def) {
try {
return this.localStorage.getString(key, def);
} catch (Exception e) {
return null;
}
}

@JavascriptInterface
public String getItem(String key) {
try {
Expand Down
26 changes: 7 additions & 19 deletions Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ public void onCreate(Bundle savedInstanceState) {

NativeStorage ns = new NativeStorage(this);
NativeOS os = new NativeOS(this);
try {
this.applyTheme(wv, ns, os);
} catch (JSONException e) {
throw new RuntimeException(e);
}

this.applyTheme(wv, ns, os);

// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
Expand Down Expand Up @@ -88,20 +83,13 @@ private String mmrlUserAgent() {
return "MMRL/" + BuildConfig.VERSION_NAME + " (Linux; Android " + Build.VERSION.RELEASE + "; " + Build.MODEL + " Build/" + Build.DISPLAY + ")";
}

private void applyTheme(WebView wv, NativeStorage ns, NativeOS os) throws JSONException {
String bg = ns.getItem("background_color");
String sbg = ns.getItem("statusbar_color");
private void applyTheme(WebView wv, NativeStorage ns, NativeOS os) {
String defColor = "#ce93d8";
if (bg == null) {
os.setStatusBarColor(defColor,false);
os.setNavigationBarColor(defColor);
wv.setBackgroundColor(Color.parseColor(defColor));
} else {

os.setStatusBarColor(sbg.replace("\"", ""),false);
os.setNavigationBarColor(bg.replace("\"", ""));
wv.setBackgroundColor(Color.parseColor(bg.replace("\"", "")));
}
String bg = ns.getItem("background_color", defColor);
String sbg = ns.getItem("statusbar_color", defColor);
os.setStatusBarColor(sbg.replace("\"", ""),false);
os.setNavigationBarColor(bg.replace("\"", ""));
wv.setBackgroundColor(Color.parseColor(bg.replace("\"", "")));
}

private boolean isEmulator = (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
Expand Down
13 changes: 0 additions & 13 deletions Android/app/src/main/res/layout/terminal.xml

This file was deleted.

4 changes: 0 additions & 4 deletions Website/src/hooks/useNativeStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export type SetValue<T> = Dispatch<SetStateAction<T>, T>;

export const nativeStorage = os.isAndroid ? window.__nativeStorage__ : window.localStorage;

if (window.__nativeStorage__) {
window.__nativeStorage__.defineName("localstorage");
}

export function useNativeStorage<T>(key: string, initialValue: T): [T, SetValue<T>] {
const log = useLog("useNativeStorage");
// Get from local storage then
Expand Down
15 changes: 7 additions & 8 deletions Website/src/native/BuildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,51 @@ import { Native } from "./Native";
*/
class BuildConfigClass extends Native {
public constructor() {
super();
this.interfaceName = "__buildconfig__";
super(window.__buildconfig__);
}

public get BUILD_DATE(): number {
if (this.isAndroid) {
return this.getInterface.BUILD_DATE();
return this.interface.BUILD_DATE();
} else {
return WEB_BUILD_DATE;
}
}

public get VERSION_NAME(): VersionType {
if (this.isAndroid) {
return this.getInterface.VERSION_NAME();
return this.interface.VERSION_NAME();
} else {
return pkg.config.version_name as VersionType;
}
}

public get VERSION_CODE(): number {
if (this.isAndroid) {
return this.getInterface.VERSION_CODE();
return this.interface.VERSION_CODE();
} else {
return pkg.config.version_code;
}
}

public get APPLICATION_ID(): string {
if (this.isAndroid) {
return this.getInterface.APPLICATION_ID();
return this.interface.APPLICATION_ID();
} else {
return pkg.name;
}
}
public get DEBUG(): boolean {
if (this.isAndroid) {
return this.getInterface.DEBUG;
return this.interface.DEBUG;
} else {
return __webpack__mode__ === "development";
}
}

public get BUILD_TYPE(): string {
if (this.isAndroid) {
return this.getInterface.BUILD_TYPE;
return this.interface.BUILD_TYPE;
} else {
return "unknown";
}
Expand Down
11 changes: 5 additions & 6 deletions Website/src/native/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export interface NativeEnvironment {
*/
class EnvironmentClass extends Native<NativeEnvironment> {
public constructor() {
super();
this.interfaceName = "__environment__";
super(window.__environment__);
}

public readonly DIRECTORY_MUSIC: string = "Music";
Expand All @@ -31,19 +30,19 @@ class EnvironmentClass extends Native<NativeEnvironment> {
public readonly DIRECTORY_RECORDINGS: string = "Recordings";

public getExternalStorageDir(): string {
return this.getInterface.getExternalStorageDir();
return this.interface.getExternalStorageDir();
}

public getPackageDataDir(): string {
return this.getInterface.getPackageDataDir();
return this.interface.getPackageDataDir();
}

public getPublicDir(type: string): string {
return this.getInterface.getPublicDir(type);
return this.interface.getPublicDir(type);
}

public getDataDir(): string {
return this.getInterface.getDataDir();
return this.interface.getDataDir();
}
}

Expand Down
4 changes: 4 additions & 0 deletions Website/src/native/Magisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Native } from "./Native";
import { Shell } from "./Shell";

class MagiskClass extends Native {
public constructor() {
super({});
}

/**
* Get current installed Magisk version code
*/
Expand Down
36 changes: 9 additions & 27 deletions Website/src/native/Native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface INative<T = any> {
get getInterface(): T;
get interface(): T;
get userAgent(): string;
}

Expand All @@ -9,13 +9,16 @@ export type NativeArgumentTypes<F extends Function> = F extends (...args: infer
* Core functions for native functions/interfaces
*/
export class Native<I = any> implements INative<I> {
private _internal_interface: I;

/**
* This field is required, otherwise the comunacation between Android will not work
* @required true
*/
public interfaceName: keyof AndroidWindow<I> | undefined;

public constructor() {}
public constructor(i: I) {
if (typeof i === "undefined") throw new Error("No interface defined");
this._internal_interface = i;
}

private get userAgentRegex(): RegExp {
return /MMRL\/(.+)\s\(Linux;\sAndroid\s(.+);\s(.+)\sBuild\/(.+)\)/gs;
Expand All @@ -32,28 +35,7 @@ export class Native<I = any> implements INative<I> {
return this.userAgentRegex.test(this.userAgent) || window.hasOwnProperty("cordova") ? true : false;
}

/**
* @deprecated Use `Native.interface()` instead
*/
public get getInterface(): I {
if (this.interfaceName) {
return window[this.interfaceName];
} else {
throw new Error("No interface defined");
}
}

public interface<K extends keyof I>(name: K): I[K] {
if (this.interfaceName) {
if (typeof window[this.interfaceName][name] == "undefined") {
return (window[this.interfaceName][name] = () => {
console.log("Undefined function");
}) as any;
} else {
return window[this.interfaceName][name];
}
} else {
throw new Error("No interface defined");
}
public get interface(): I {
return this._internal_interface;
}
}
Loading

0 comments on commit 9cbb45f

Please sign in to comment.