-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'dev.vendicated.vencord' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "dev.vendicated.vencord" | ||
minSdk 21 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
|
||
signingConfigs { | ||
release { | ||
// Add these in ~/.gradle/gradle.properties | ||
storeFile file(KEYSTORE_FILE) | ||
storePassword KEYSTORE_PASSWORD | ||
keyAlias KEYSTORE_ALIAS | ||
keyPassword KEYSTORE_PASSWORD | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
signingConfig signingConfigs.release | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_11 | ||
targetCompatibility JavaVersion.VERSION_11 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.annotation:annotation:1.3.0' | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": 3, | ||
"artifactType": { | ||
"type": "APK", | ||
"kind": "Directory" | ||
}, | ||
"applicationId": "dev.vendicated.vencord", | ||
"variantName": "release", | ||
"elements": [ | ||
{ | ||
"type": "SINGLE", | ||
"filters": [], | ||
"attributes": [], | ||
"versionCode": 1, | ||
"versionName": "1.0", | ||
"outputFile": "app-release.apk" | ||
} | ||
], | ||
"elementType": "File" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:label="@string/app_name" | ||
android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:allowBackup="true" | ||
android:supportsRtl="true" | ||
tools:targetApi="31" | ||
> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package dev.vendicated.vencord; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.*; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.Locale; | ||
|
||
public class HttpClient { | ||
public static final String VENCORD_BUNDLE_URL = "https://github.com/Vendicated/Vencord/releases/download/devbuild/browser.js"; | ||
|
||
public static final class HttpException extends IOException { | ||
private final HttpURLConnection conn; | ||
private String message; | ||
|
||
public HttpException(HttpURLConnection conn) { | ||
this.conn = conn; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getMessage() { | ||
if (message == null) { | ||
try { | ||
message = String.format( | ||
Locale.ENGLISH, | ||
"%d: %s (%s)\n%s", | ||
conn.getResponseCode(), | ||
conn.getResponseMessage(), | ||
conn.getURL().toString(), | ||
readAsText(conn.getErrorStream()) | ||
); | ||
} catch (IOException ex) { | ||
message = "Error while building message lmao. Url is " + conn.getURL().toString(); | ||
} | ||
} | ||
return message; | ||
} | ||
} | ||
|
||
public static String vencord; | ||
|
||
public static void fetchVencord() throws IOException { | ||
if (vencord != null) return; | ||
|
||
var conn = fetch(VENCORD_BUNDLE_URL); | ||
try (var is = conn.getInputStream()) { | ||
vencord = readAsText(is); | ||
} | ||
} | ||
|
||
private static HttpURLConnection fetch(String url) throws IOException { | ||
var conn = (HttpURLConnection) new URL(url).openConnection(); | ||
if (conn.getResponseCode() >= 300) { | ||
throw new HttpException(conn); | ||
} | ||
return conn; | ||
} | ||
|
||
private static String readAsText(InputStream is) throws IOException { | ||
try (var baos = new ByteArrayOutputStream()) { | ||
int n; | ||
byte[] buf = new byte[16384]; // 16 KB | ||
while ((n = is.read(buf)) > -1) { | ||
baos.write(buf, 0, n); | ||
} | ||
baos.flush(); | ||
|
||
return baos.toString("UTF-8"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.vendicated.vencord; | ||
|
||
import android.util.Log; | ||
|
||
public final class Logger { | ||
private static final String TAG = "Vencord"; | ||
|
||
public static void e(String message) { | ||
Log.e(TAG, message); | ||
} | ||
public static void e(String message, Throwable e) { | ||
Log.e(TAG, message, e); | ||
} | ||
|
||
public static void w(String message) { | ||
Log.w(TAG, message); | ||
} | ||
|
||
public static void i(String message) { | ||
Log.i(TAG, message); | ||
} | ||
|
||
public static void d(String message) { | ||
Log.d(TAG, message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package dev.vendicated.vencord; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.os.StrictMode; | ||
import android.webkit.WebView; | ||
|
||
import java.io.IOException; | ||
|
||
public class MainActivity extends Activity { | ||
private WebView wv; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
var bar = this.getActionBar(); | ||
if (bar != null) bar.hide(); | ||
|
||
setContentView(R.layout.activity_main); | ||
|
||
wv = findViewById(R.id.webview); | ||
|
||
explodeAndroid(); | ||
|
||
wv.setWebViewClient(new VWebviewClient()); | ||
wv.setWebChromeClient(new VChromeClient()); | ||
|
||
var s = wv.getSettings(); | ||
s.setJavaScriptEnabled(true); | ||
s.setDomStorageEnabled(true); | ||
s.setAllowFileAccess(true); | ||
|
||
|
||
try { | ||
HttpClient.fetchVencord(); | ||
} catch (IOException ex) { | ||
Logger.e("Failed to fetch Vencord", ex); | ||
return; | ||
} | ||
|
||
if (savedInstanceState == null) | ||
wv.loadUrl("https://discord.com/app"); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(@NonNull Bundle state) | ||
{ | ||
super.onSaveInstanceState(state); | ||
wv.saveState(state); | ||
} | ||
|
||
@Override | ||
protected void onRestoreInstanceState(Bundle state) | ||
{ | ||
super.onRestoreInstanceState(state); | ||
wv.restoreState(state); | ||
} | ||
|
||
private void explodeAndroid() { | ||
StrictMode.setThreadPolicy( | ||
new StrictMode.ThreadPolicy.Builder() | ||
// trolley | ||
.permitNetwork() | ||
.build() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.vendicated.vencord; | ||
|
||
import android.webkit.ConsoleMessage; | ||
import android.webkit.WebChromeClient; | ||
|
||
import java.util.Locale; | ||
|
||
public class VChromeClient extends WebChromeClient { | ||
@Override | ||
public boolean onConsoleMessage(ConsoleMessage msg) { | ||
var m = String.format(Locale.ENGLISH,"[Javascript] %s @ %d: %s", msg.message(), msg.lineNumber(), msg.sourceId()); | ||
switch (msg.messageLevel()) { | ||
case LOG: | ||
Logger.i(m); | ||
break; | ||
case DEBUG: | ||
Logger.d(m); | ||
break; | ||
case ERROR: | ||
Logger.e(m); | ||
break; | ||
case WARNING: | ||
Logger.w(m); | ||
break; | ||
} | ||
return true; | ||
} | ||
} |