From 2f3aec21ee8a582233ebbf2d6474b90c38f11e23 Mon Sep 17 00:00:00 2001 From: Gabe616 Date: Sat, 15 Jul 2023 15:23:56 +0200 Subject: [PATCH] [Main] Introduce dynamic colors (#12) * [Main] Introduce dynamic colors as __vendetta_syscolors * [Main] Bump version * feat(readme): add install guide * [Main] Add install guide in README * [Main] Fix typo in README * [Main > App] Downgrade SDK to 31 * [Main] Make guide better * [Main > README] Make guide better * [Main] Fix guide yet again * [Main] Update README (PR #1) table of contents + markdown gaming * [Main] Improve README again (PR #2) * silly patch changes table of contents + markdown gaming * fast fix of README.md table of contents!! * real latest release link now --------- Co-authored-by: Gabe616 * [Main] Use 'this' keyword instead of 'window' * [Main] More changes (check detailed description) - use kotlin serializer instead of gson - bump target SDK to 33 - fix broken link in README * [Main] Revert README --------- Co-authored-by: riichi <88538677+riichimaru@users.noreply.github.com> --- README.md | 2 +- app/build.gradle.kts | 11 +- app/src/main/assets/js/identity.js | 2 +- app/src/main/java/com/vendetta/xposed/Main.kt | 105 ++++++++++++++++++ 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ce75c6..f75b624 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ An Xposed module to inject Vendetta, a mod for Discord's mobile apps. # Credits -I do not wish to write Kotlin, nor do I know much of it, so much of this repo can be attributed to the [first commit of AliucordXposed](https://github.com/Aliucord/AliucordXposed/commit/79ad1e224d598643057cd057c83fab851e89ac82). \ No newline at end of file +I do not wish to write Kotlin, nor do I know much of it, so much of this repo can be attributed to the [first commit of AliucordXposed](https://github.com/Aliucord/AliucordXposed/commit/79ad1e224d598643057cd057c83fab851e89ac82). diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4a3e274..8dc81e3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,3 +1,5 @@ +import android.annotation.SuppressLint + plugins { id("com.android.application") id("kotlin-android") @@ -5,14 +7,14 @@ plugins { } android { - compileSdk = 31 + compileSdk = 33 defaultConfig { applicationId = "com.vendetta.xposed" minSdk = 24 - targetSdk = 31 - versionCode = 7 - versionName = "1.1.4" + targetSdk = 33 + versionCode = 8 + versionName = "1.1.5" } buildTypes { @@ -33,6 +35,7 @@ android { } dependencies { + implementation("androidx.core:core:1.10.1") compileOnly("de.robv.android.xposed:api:82") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") } diff --git a/app/src/main/assets/js/identity.js b/app/src/main/assets/js/identity.js index eee065f..8959042 100644 --- a/app/src/main/assets/js/identity.js +++ b/app/src/main/assets/js/identity.js @@ -1 +1 @@ -this.__vendetta_loader={name:"VendettaXposed",features:{loaderConfig:true,devtools:{prop:"__vendetta_rdc",version:"4.27.1"},themes:{prop:"__vendetta_theme"}}}; \ No newline at end of file +this.__vendetta_loader={name:"VendettaXposed",features:{loaderConfig:true,devtools:{prop:"__vendetta_rdc",version:"4.27.1"},themes:{prop:"__vendetta_theme"},syscolors:{prop:"__vendetta_syscolors"}}}; \ No newline at end of file diff --git a/app/src/main/java/com/vendetta/xposed/Main.kt b/app/src/main/java/com/vendetta/xposed/Main.kt index f19c843..05d018a 100644 --- a/app/src/main/java/com/vendetta/xposed/Main.kt +++ b/app/src/main/java/com/vendetta/xposed/Main.kt @@ -1,11 +1,14 @@ package com.vendetta.xposed +import android.app.AndroidAppHelper import android.content.Context import android.graphics.Color import android.content.res.AssetManager import android.content.res.Resources import android.content.res.XModuleResources +import android.os.Build import android.util.Log +import androidx.core.content.ContextCompat import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.IXposedHookZygoteInit import de.robv.android.xposed.IXposedHookInitPackageResources @@ -53,6 +56,15 @@ data class Theme( val data: ThemeData ) +@Serializable +data class SysColors( + val neutral1: List, + val neutral2: List, + val accent1: List, + val accent2: List, + val accent3: List +) + class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources { private lateinit var modResources: XModuleResources private val rawColorMap = mutableMapOf() @@ -82,6 +94,14 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka } } + fun sysColorToHexString(context: Context, id: Int): String { + val clr = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + ContextCompat.getColor(context, id) + } else 0 + + return java.lang.String.format("#%06X", 0xFFFFFF and clr) + } + override fun handleInitPackageResources(resparam: XC_InitPackageResources.InitPackageResourcesParam) { if (resparam.packageName.contains(".webview")) return @@ -121,6 +141,7 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka val vendetta = File(cache, "vendetta.js") val etag = File(cache, "vendetta_etag.txt") val themeJs = File(cache, "vendetta_theme.js") + val syscolorsJs = File(cache, "vendetta_syscolors.js") lateinit var config: LoaderConfig val files = File(param.appInfo.dataDir, "files").also { it.mkdirs() } @@ -216,10 +237,94 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka override fun afterHookedMethod(param: MethodHookParam) { try { + val context = AndroidAppHelper.currentApplication() val themeString = try { themeFile.readText() } catch (_: Exception) { "null" } themeJs.writeText("this.__vendetta_theme=$themeString") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + val colors = mutableMapOf>() + colors["neutral1"] = arrayOf( + android.R.color.system_neutral1_0, + android.R.color.system_neutral1_10, + android.R.color.system_neutral1_50, + android.R.color.system_neutral1_100, + android.R.color.system_neutral1_200, + android.R.color.system_neutral1_300, + android.R.color.system_neutral1_400, + android.R.color.system_neutral1_500, + android.R.color.system_neutral1_600, + android.R.color.system_neutral1_700, + android.R.color.system_neutral1_800, + android.R.color.system_neutral1_900, + android.R.color.system_neutral1_1000 + ).map { sysColorToHexString(context, it) } + colors["neutral2"] = arrayOf( + android.R.color.system_neutral2_0, + android.R.color.system_neutral2_10, + android.R.color.system_neutral2_50, + android.R.color.system_neutral2_100, + android.R.color.system_neutral2_200, + android.R.color.system_neutral2_300, + android.R.color.system_neutral2_400, + android.R.color.system_neutral2_500, + android.R.color.system_neutral2_600, + android.R.color.system_neutral2_700, + android.R.color.system_neutral2_800, + android.R.color.system_neutral2_900, + android.R.color.system_neutral2_1000 + ).map { sysColorToHexString(context, it) } + colors["accent1"] = arrayOf( + android.R.color.system_accent1_0, + android.R.color.system_accent1_10, + android.R.color.system_accent1_50, + android.R.color.system_accent1_100, + android.R.color.system_accent1_200, + android.R.color.system_accent1_300, + android.R.color.system_accent1_400, + android.R.color.system_accent1_500, + android.R.color.system_accent1_600, + android.R.color.system_accent1_700, + android.R.color.system_accent1_800, + android.R.color.system_accent1_900, + android.R.color.system_accent1_1000 + ).map { sysColorToHexString(context, it) } + colors["accent2"] = arrayOf( + android.R.color.system_accent2_0, + android.R.color.system_accent2_10, + android.R.color.system_accent2_50, + android.R.color.system_accent2_100, + android.R.color.system_accent2_200, + android.R.color.system_accent2_300, + android.R.color.system_accent2_400, + android.R.color.system_accent2_500, + android.R.color.system_accent2_600, + android.R.color.system_accent2_700, + android.R.color.system_accent2_800, + android.R.color.system_accent2_900, + android.R.color.system_accent2_1000 + ).map { sysColorToHexString(context, it) } + colors["accent3"] = arrayOf( + android.R.color.system_accent3_0, + android.R.color.system_accent3_10, + android.R.color.system_accent3_50, + android.R.color.system_accent3_100, + android.R.color.system_accent3_200, + android.R.color.system_accent3_300, + android.R.color.system_accent3_400, + android.R.color.system_accent3_500, + android.R.color.system_accent3_600, + android.R.color.system_accent3_700, + android.R.color.system_accent3_800, + android.R.color.system_accent3_900, + android.R.color.system_accent3_1000 + ).map { sysColorToHexString(context, it) } + + syscolorsJs.writeText("this.__vendetta_syscolors=${Json.encodeToString(colors)}") + } else { + syscolorsJs.writeText("this.__vendetta_syscolors=null") + } XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(themeJs.absolutePath, themeJs.absolutePath, param.args[2])) + XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(syscolorsJs.absolutePath, syscolorsJs.absolutePath, param.args[2])) XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(vendetta.absolutePath, vendetta.absolutePath, param.args[2])) } catch (_: Exception) {} }