Skip to content

Commit

Permalink
Fix #51
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Oct 31, 2023
1 parent 244859d commit 48ae9d2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NativeStorage {
private String localStorageName;

public NativeStorage(@NonNull Context ctx) {
this.localStorage = ctx.getSharedPreferences(localStorageName, Activity.MODE_PRIVATE);
this.localStorage = ctx.getSharedPreferences("localstorage_v2", Activity.MODE_PRIVATE);
}

@JavascriptInterface
Expand Down
23 changes: 22 additions & 1 deletion Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dergoogler.mmrl;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
Expand All @@ -20,6 +21,8 @@
import com.topjohnwu.superuser.ShellUtils;

import org.apache.cordova.*;
import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends CordovaActivity {
@Override
Expand All @@ -35,6 +38,16 @@ public void onCreate(Bundle savedInstanceState) {
}

WebView wv = (WebView) appView.getEngine().getView();


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


// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
Expand Down Expand Up @@ -64,7 +77,7 @@ public void onCreate(Bundle savedInstanceState) {
wv.addJavascriptInterface(new NativeShell(wv), "__shell__");
wv.addJavascriptInterface(new NativeBuildConfig(), "__buildconfig__");
wv.addJavascriptInterface(new NativeOS(this), "__os__");
wv.addJavascriptInterface(new NativeStorage(this), "__nativeStorage__");
wv.addJavascriptInterface(ns, "__nativeStorage__");
wv.addJavascriptInterface(new NativeProperties(), "__properties__");
wv.addJavascriptInterface(new NativeLog(), "__log__");

Expand All @@ -74,6 +87,14 @@ 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) throws JSONException {
String bg = ns.getItem("background_color");
if (bg == null) {
wv.setBackgroundColor(Color.parseColor("#ce93d8"));
} else {
wv.setBackgroundColor(Color.parseColor(bg.replace("\"", "")));
}
}

private boolean isEmulator = (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| Build.FINGERPRINT.startsWith("generic")
Expand Down
104 changes: 53 additions & 51 deletions Website/src/hooks/useTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { colors as kolors, useTheme as useMom, createTheme, ThemeProvider as MumProvider } from "@mui/material";
import { useTheme as useMom, createTheme, ThemeProvider as MumProvider } from "@mui/material";
import useShadeColor from "./useShadeColor";
import { colors, useSettings } from "./useSettings";
import { os } from "@Native/Os";
import { useNativeStorage } from "./useNativeStorage";

export const useTheme = () => {
const theme = useMom();
Expand Down Expand Up @@ -45,59 +46,60 @@ export const ThemeProvider = (props: React.PropsWithChildren) => {
const { settings } = useSettings();
const shade = useShadeColor();

const theme = React.useMemo(
() =>
createTheme({
shape: {
borderRadius: 8,
},
palette: !settings.darkmode
? {
mode: "light",
primary: {
light: colors[settings.accent_scheme.value][300],
main: colors[settings.accent_scheme.value][500],
dark: colors[settings.accent_scheme.value][700],
const initialBackground = colors[settings.accent_scheme.value][200];
const [, setBackgroundColor] = useNativeStorage("background_color", initialBackground);

// light: colors[settings.accent_scheme.value][300],
// main: colors[settings.accent_scheme.value][900],
// dark: colors[settings.accent_scheme.value][800],
},
background: {
default: colors[settings.accent_scheme.value][200],
paper: shade(colors[settings.accent_scheme.value][200], 14.5 * 2),
},
divider: colors[settings.accent_scheme.value][300],
secondary: {
main: colors[settings.accent_scheme.value][600],
},
}
: {
mode: "dark",
primary: {
main: shade(colors[settings.accent_scheme.value][200], settings.shade_value),
light: shade(colors[settings.accent_scheme.value][100], settings.shade_value),
dark: shade(colors[settings.accent_scheme.value][400], settings.shade_value),
// light: shade(colors[settings.accent_scheme.value][300], -10),
// main: shade(colors[settings.accent_scheme.value][500], -29),
},
background: {
paper: shade(colors[settings.accent_scheme.value][600], settings.shade_value),
default: shade(colors[settings.accent_scheme.value][700], settings.shade_value),
},
divider: shade(colors[settings.accent_scheme.value][900], settings.shade_value),
secondary: {
main: colors[settings.accent_scheme.value][600],
},
const theme = React.useMemo(() => {
const THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP = createTheme({
shape: {
borderRadius: 8,
},
palette: !settings.darkmode
? {
mode: "light",
primary: {
light: colors[settings.accent_scheme.value][300],
main: colors[settings.accent_scheme.value][500],
dark: colors[settings.accent_scheme.value][700],

// light: colors[settings.accent_scheme.value][300],
// main: colors[settings.accent_scheme.value][900],
// dark: colors[settings.accent_scheme.value][800],
},
background: {
default: initialBackground,
paper: shade(colors[settings.accent_scheme.value][200], 14.5 * 2),
},
divider: colors[settings.accent_scheme.value][300],
secondary: {
main: colors[settings.accent_scheme.value][600],
},
}
: {
mode: "dark",
primary: {
main: shade(colors[settings.accent_scheme.value][200], settings.shade_value),
light: shade(colors[settings.accent_scheme.value][100], settings.shade_value),
dark: shade(colors[settings.accent_scheme.value][400], settings.shade_value),
// light: shade(colors[settings.accent_scheme.value][300], -10),
// main: shade(colors[settings.accent_scheme.value][500], -29),
},
background: {
paper: shade(colors[settings.accent_scheme.value][600], settings.shade_value),
default: shade(colors[settings.accent_scheme.value][700], settings.shade_value),
},
divider: shade(colors[settings.accent_scheme.value][900], settings.shade_value),
secondary: {
main: colors[settings.accent_scheme.value][600],
},
}),
[settings.darkmode, settings.accent_scheme]
);
},
});

React.useEffect(() => {
os.setStatusBarColor(theme.palette.primary.main, false);
os.setNavigationBarColor(theme.palette.background.default);
}, [theme]);
os.setStatusBarColor(THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP.palette.primary.main, false);
os.setNavigationBarColor(THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP.palette.background.default);
setBackgroundColor(THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP.palette.background.default);
return THIS_IS_THE_THEME_OBJECT_OF_THIS_F_APP;
}, [settings.darkmode, settings.accent_scheme]);

return <MumProvider theme={theme} children={props.children} />;
};

0 comments on commit 48ae9d2

Please sign in to comment.