1
0
Fork 0

added recovery mode

This commit is contained in:
nin0dev 2024-08-28 15:17:43 -04:00
parent d2c750175f
commit f6030910e8
5 changed files with 151 additions and 72 deletions

View file

@ -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
@ -54,7 +59,13 @@ class MainActivity : Activity() {
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,12 +95,19 @@ class MainActivity : Activity() {
s.javaScriptEnabled = true
s.domStorageEnabled = true
s.allowFileAccess = true
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) {
val data = intent.data

View file

@ -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)

View file

@ -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">
<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"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/update_vencord" />
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<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"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/clear_cookies" />
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/clear_cookies_desc" />
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,13 +116,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
style="?attr/collapsingToolbarLayoutLargeStyle"
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"
@ -80,8 +124,6 @@
app:title="@string/recovery_shortcut_name"
app:titleTextColor="@color/text" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -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>

View file

@ -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"