Skip to content

Commit 8af3037

Browse files
committed
update js api
1 parent 3e60c7e commit 8af3037

File tree

18 files changed

+15873
-2428
lines changed

18 files changed

+15873
-2428
lines changed

app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/webui/WebUIScreen.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.dergoogler.mmrl.ui.activity.webui.interfaces.ksu.AdvancedKernelSUAPI
2727
import com.dergoogler.mmrl.ui.activity.webui.interfaces.ksu.BaseKernelSUAPI
2828
import com.dergoogler.mmrl.ui.activity.webui.interfaces.mmrl.FileInterface
2929
import com.dergoogler.mmrl.ui.activity.webui.interfaces.mmrl.MMRLInterface
30+
import com.dergoogler.mmrl.ui.activity.webui.interfaces.mmrl.VersionInterface
3031
import com.dergoogler.mmrl.ui.component.ConfirmDialog
3132
import com.dergoogler.mmrl.ui.component.Loading
3233
import com.dergoogler.mmrl.ui.providable.LocalUserPreferences
@@ -130,8 +131,6 @@ fun WebUIScreen(
130131
AndroidView(
131132
factory = {
132133
webView.apply {
133-
134-
135134
layoutParams = ViewGroup.LayoutParams(
136135
ViewGroup.LayoutParams.MATCH_PARENT,
137136
ViewGroup.LayoutParams.MATCH_PARENT
@@ -148,6 +147,14 @@ fun WebUIScreen(
148147
userPrefs = userPrefs,
149148
viewModel = viewModel,
150149
)
150+
151+
addJavascriptInterface(
152+
VersionInterface(
153+
context = context,
154+
webView = this,
155+
viewModel = viewModel,
156+
), "mmrl"
157+
)
151158
}
152159
},
153160
update = {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.dergoogler.mmrl.ui.activity.webui.interfaces.mmrl
2+
3+
import android.content.Context
4+
import android.webkit.JavascriptInterface
5+
import android.webkit.WebView
6+
import android.widget.Toast
7+
import com.dergoogler.mmrl.BuildConfig
8+
import com.dergoogler.mmrl.viewmodel.WebUIViewModel
9+
10+
class VersionInterface(
11+
private val context: Context,
12+
private val webView: WebView,
13+
private val viewModel: WebUIViewModel,
14+
) {
15+
inner class BuildConfigDetails {
16+
@get:JavascriptInterface
17+
val applicationId = BuildConfig.APPLICATION_ID
18+
19+
@get:JavascriptInterface
20+
val buildType = BuildConfig.BUILD_TYPE
21+
22+
@get:JavascriptInterface
23+
val versionCode = BuildConfig.VERSION_CODE
24+
25+
@get:JavascriptInterface
26+
val versionName = BuildConfig.VERSION_NAME
27+
28+
@get:JavascriptInterface
29+
val isDevVersion: Boolean = BuildConfig.IS_DEV_VERSION
30+
31+
@get:JavascriptInterface
32+
val isGooglePlayBuild: Boolean = BuildConfig.IS_GOOGLE_PLAY_BUILD
33+
}
34+
35+
inner class RootConfigDetails {
36+
@get:JavascriptInterface
37+
val platform = viewModel.platform.current
38+
39+
@get:JavascriptInterface
40+
val versionName = viewModel.versionName
41+
42+
@get:JavascriptInterface
43+
val versionCode = viewModel.versionCode
44+
}
45+
46+
@get:JavascriptInterface
47+
val buildConfig get() = BuildConfigDetails()
48+
49+
@get:JavascriptInterface
50+
val rootConfig get() = RootConfigDetails()
51+
52+
inner class ToastBuilderInterface {
53+
private val toast = Toast(context)
54+
55+
@JavascriptInterface
56+
fun setText(msg: String) {
57+
toast.setText(msg)
58+
}
59+
60+
@JavascriptInterface
61+
fun show() {
62+
webView.post {
63+
toast.show()
64+
}
65+
}
66+
67+
@JavascriptInterface
68+
fun cancel() {
69+
webView.post {
70+
toast.cancel()
71+
}
72+
}
73+
74+
@JavascriptInterface
75+
fun setDuration(duration: Int) {
76+
toast.duration = duration
77+
}
78+
}
79+
80+
@JavascriptInterface
81+
fun toastBuilder(): ToastBuilderInterface {
82+
return ToastBuilderInterface()
83+
}
84+
}

js/.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": [
3+
["@babel/plugin-proposal-decorators", { "legacy": true }],
4+
"@babel/plugin-proposal-class-properties"
5+
]
6+
}

js/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Dependency directories
22
node_modules/
3+
.parcel-cache/
34

45
src/
56
test/

js/.parcelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"bundler": "@parcel/bundler-library"
4+
}

js/bun.lockb

99.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)