added recovery mode
This commit is contained in:
parent
d2c750175f
commit
f6030910e8
5 changed files with 151 additions and 72 deletions
|
@ -11,7 +11,10 @@ import android.os.Bundle
|
|||
import android.os.StrictMode
|
||||
import android.os.StrictMode.ThreadPolicy
|
||||
import android.view.KeyEvent
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.WindowManager
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.CookieSyncManager
|
||||
import android.webkit.ValueCallback
|
||||
import android.webkit.WebView
|
||||
import android.widget.Toast
|
||||
|
@ -21,8 +24,10 @@ import com.android.volley.toolbox.Volley
|
|||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.nin0dev.vendroid.HttpClient.fetchVencord
|
||||
import com.nin0dev.vendroid.Logger.e
|
||||
import pl.droidsonroids.gif.GifImageView
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
class MainActivity : Activity() {
|
||||
private var wvInitialized = false
|
||||
private var wv: WebView? = null
|
||||
|
@ -36,25 +41,31 @@ class MainActivity : Activity() {
|
|||
val queue = Volley.newRequestQueue(this)
|
||||
val url = "https://raw.githubusercontent.com/VendroidEnhanced/UpdateTracker/main/vendroid"
|
||||
val stringRequest = StringRequest(
|
||||
Request.Method.GET, url,
|
||||
{ response ->
|
||||
if(Integer.parseInt(response.trim()) != BuildConfig.VERSION_CODE)
|
||||
{
|
||||
val madb = MaterialAlertDialogBuilder(this)
|
||||
madb.setTitle(getString(R.string.vendroid_update_available))
|
||||
madb.setMessage("To make sure that no unexpected bugs happen, it is recommended to update.")
|
||||
madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i ->
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk"))
|
||||
startActivity(browserIntent)
|
||||
})
|
||||
madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> })
|
||||
madb.show()
|
||||
}
|
||||
if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) {
|
||||
showDiscordToast("No updates available", "MESSAGE")
|
||||
}
|
||||
},
|
||||
{ })
|
||||
Request.Method.GET, url,
|
||||
{ response ->
|
||||
if(Integer.parseInt(response.trim()) != BuildConfig.VERSION_CODE)
|
||||
{
|
||||
val madb = MaterialAlertDialogBuilder(this)
|
||||
madb.setTitle(getString(R.string.vendroid_update_available))
|
||||
madb.setMessage("To make sure that no unexpected bugs happen, it is recommended to update.")
|
||||
madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i ->
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk"))
|
||||
startActivity(browserIntent)
|
||||
})
|
||||
madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> })
|
||||
madb.show()
|
||||
}
|
||||
if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) {
|
||||
showDiscordToast("No updates available", "MESSAGE")
|
||||
}
|
||||
},
|
||||
{ error ->
|
||||
if (BuildConfig.DEBUG) {
|
||||
e("Network error during update check", error)
|
||||
}
|
||||
Toast.makeText(this, "Failed to check for updates", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
)
|
||||
stringRequest.setShouldCache(false);
|
||||
queue.add(stringRequest)
|
||||
}
|
||||
|
@ -69,9 +80,13 @@ class MainActivity : Activity() {
|
|||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val editor = sPrefs.edit()
|
||||
// https://developer.chrome.com/docs/devtools/remote-debugging/webviews/
|
||||
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
|
||||
setContentView(R.layout.activity_main)
|
||||
if (sPrefs.getString("splash", "viggy") == "viggy") findViewById<GifImageView>(R.id.viggy_gif).visibility = VISIBLE
|
||||
else if (sPrefs.getString("splash", "viggy") == "shiggy") findViewById<GifImageView>(R.id.shiggy_gif).visibility = VISIBLE
|
||||
else if (sPrefs.getString("splash", "viggy") == "oneko") findViewById<GifImageView>(R.id.oneko_gif).visibility = VISIBLE
|
||||
wv = findViewById(R.id.webview)!!
|
||||
explodeAndroid()
|
||||
wv!!.setWebViewClient(VWebviewClient())
|
||||
|
@ -80,11 +95,18 @@ class MainActivity : Activity() {
|
|||
s.javaScriptEnabled = true
|
||||
s.domStorageEnabled = true
|
||||
s.allowFileAccess = true
|
||||
wv?.addJavascriptInterface(VencordNative(this, wv!!), "VencordMobileNative")
|
||||
try {
|
||||
fetchVencord(this)
|
||||
} catch (ex: IOException) {
|
||||
if(!sPrefs.getBoolean("safeMode", false)) {
|
||||
wv?.addJavascriptInterface(VencordNative(this, wv!!), "VencordMobileNative")
|
||||
try {
|
||||
fetchVencord(this)
|
||||
} catch (ex: IOException) {
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
Toast.makeText(this, "Safe mode enabled, Vencord won't be loaded", Toast.LENGTH_SHORT).show()
|
||||
editor.putBoolean("safeMode", false)
|
||||
editor.apply()
|
||||
}
|
||||
val intent = intent
|
||||
if (intent.action == Intent.ACTION_VIEW) {
|
||||
|
@ -138,9 +160,9 @@ class MainActivity : Activity() {
|
|||
|
||||
private fun explodeAndroid() {
|
||||
StrictMode.setThreadPolicy(
|
||||
ThreadPolicy.Builder() // trolley
|
||||
.permitNetwork()
|
||||
.build()
|
||||
ThreadPolicy.Builder() // trolley
|
||||
.permitNetwork()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,15 @@ import android.content.Intent
|
|||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.CookieSyncManager
|
||||
import android.webkit.WebView
|
||||
import android.widget.Button
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
class RecoveryActivity : AppCompatActivity() {
|
||||
|
@ -23,14 +27,23 @@ class RecoveryActivity : AppCompatActivity() {
|
|||
|
||||
setContentView(R.layout.activity_recovery)
|
||||
|
||||
findViewById<Button>(R.id.reset_vencord_location).setOnClickListener {
|
||||
findViewById<MaterialCardView>(R.id.start_normally).setOnClickListener {
|
||||
finish()
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
}
|
||||
findViewById<MaterialCardView>(R.id.safe_mode).setOnClickListener {
|
||||
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val e = sPrefs.edit()
|
||||
e.putString("vencordLocation", Constants.JS_BUNDLE_URL)
|
||||
e.putBoolean("pendingReset", true)
|
||||
e.putBoolean("safeMode", true)
|
||||
e.apply()
|
||||
Snackbar.make(findViewById(R.id.main_layout), "Successfully reset Vencord location", Snackbar.LENGTH_LONG).show()
|
||||
finish()
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
}
|
||||
findViewById<MaterialCardView>(R.id.settings).setOnClickListener {
|
||||
finish()
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
|
|
|
@ -16,46 +16,97 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/reset_vencord_location"
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/start_normally"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/reset_vencord_location" />
|
||||
android:clickable="true">
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Start normally"
|
||||
android:textAppearance="?attr/textAppearanceTitleMedium" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Don't do anything and start the app normally."
|
||||
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/safe_mode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/reset_vencord_location_desc" />
|
||||
android:clickable="true">
|
||||
|
||||
<Button
|
||||
android:id="@+id/update_vencord"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/update_vencord" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Safe mode"
|
||||
android:textAppearance="?attr/textAppearanceTitleMedium" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Use this option to launch the app and load Discord, but without Vencord or any VendroidEnhanced tweak injected."
|
||||
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/update_vencord_desc" />
|
||||
android:clickable="true">
|
||||
|
||||
<Button
|
||||
android:id="@+id/clear_cookies"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/clear_cookies" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/clear_cookies_desc" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Open settings"
|
||||
android:textAppearance="?attr/textAppearanceTitleMedium" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Configure VendroidEnhanced."
|
||||
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
@ -65,22 +116,13 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
style="?attr/collapsingToolbarLayoutLargeStyle"
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
|
||||
app:contentScrim="?attr/colorSurfaceContainer"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="0dp"
|
||||
app:layout_collapseMode="pin"
|
||||
app:title="@string/recovery_shortcut_name"
|
||||
app:titleTextColor="@color/text" />
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="0dp"
|
||||
app:layout_collapseMode="pin"
|
||||
app:title="@string/recovery_shortcut_name"
|
||||
app:titleTextColor="@color/text" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
|
|
@ -22,4 +22,6 @@
|
|||
<string name="shiggy">Shiggy, by naga_U</string>
|
||||
<string name="oneko">Oneko</string>
|
||||
<string name="splashscreen">Splash screen</string>
|
||||
<string name="recovery_shortcut_name">Recovery mode</string>
|
||||
<string name="cleared_all">Cleared all cookies</string>
|
||||
</resources>
|
|
@ -3,8 +3,8 @@
|
|||
android:shortcutId="recovery"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/reset"
|
||||
android:shortcutShortLabel="@string/recovery_shortcut_name"
|
||||
android:shortcutLongLabel="@string/recovery_shortcut_name">
|
||||
android:shortcutShortLabel="Recovery mode"
|
||||
android:shortcutLongLabel="Recovery mode">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="com.nin0dev.vendroid"
|
||||
|
|
Loading…
Reference in a new issue