Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed Nov 25, 2022
0 parents commit fbc6ec5
Show file tree
Hide file tree
Showing 49 changed files with 1,555 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
42 changes: 42 additions & 0 deletions app/build.gradle
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'
}

21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
Binary file added app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
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"
}
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
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>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions app/src/main/java/dev/vendicated/vencord/HttpClient.java
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");
}
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/dev/vendicated/vencord/Logger.java
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);
}
}
70 changes: 70 additions & 0 deletions app/src/main/java/dev/vendicated/vencord/MainActivity.java
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()
);
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/dev/vendicated/vencord/VChromeClient.java
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;
}
}
Loading

0 comments on commit fbc6ec5

Please sign in to comment.