Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 2f3aec2

Browse files
nexpidmollyvita
andauthored
[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 <[email protected]> * [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 <[email protected]>
1 parent 802511a commit 2f3aec2

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
An Xposed module to inject Vendetta, a mod for Discord's mobile apps.
33

44
# Credits
5-
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).
5+
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).

app/build.gradle.kts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import android.annotation.SuppressLint
2+
13
plugins {
24
id("com.android.application")
35
id("kotlin-android")
46
kotlin("plugin.serialization") version "1.8.0"
57
}
68

79
android {
8-
compileSdk = 31
10+
compileSdk = 33
911

1012
defaultConfig {
1113
applicationId = "com.vendetta.xposed"
1214
minSdk = 24
13-
targetSdk = 31
14-
versionCode = 7
15-
versionName = "1.1.4"
15+
targetSdk = 33
16+
versionCode = 8
17+
versionName = "1.1.5"
1618
}
1719

1820
buildTypes {
@@ -33,6 +35,7 @@ android {
3335
}
3436

3537
dependencies {
38+
implementation("androidx.core:core:1.10.1")
3639
compileOnly("de.robv.android.xposed:api:82")
3740
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
3841
}

app/src/main/assets/js/identity.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/vendetta/xposed/Main.kt

+105
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.vendetta.xposed
22

3+
import android.app.AndroidAppHelper
34
import android.content.Context
45
import android.graphics.Color
56
import android.content.res.AssetManager
67
import android.content.res.Resources
78
import android.content.res.XModuleResources
9+
import android.os.Build
810
import android.util.Log
11+
import androidx.core.content.ContextCompat
912
import de.robv.android.xposed.IXposedHookLoadPackage
1013
import de.robv.android.xposed.IXposedHookZygoteInit
1114
import de.robv.android.xposed.IXposedHookInitPackageResources
@@ -53,6 +56,15 @@ data class Theme(
5356
val data: ThemeData
5457
)
5558

59+
@Serializable
60+
data class SysColors(
61+
val neutral1: List<String>,
62+
val neutral2: List<String>,
63+
val accent1: List<String>,
64+
val accent2: List<String>,
65+
val accent3: List<String>
66+
)
67+
5668
class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources {
5769
private lateinit var modResources: XModuleResources
5870
private val rawColorMap = mutableMapOf<String, Int>()
@@ -82,6 +94,14 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
8294
}
8395
}
8496

97+
fun sysColorToHexString(context: Context, id: Int): String {
98+
val clr = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
99+
ContextCompat.getColor(context, id)
100+
} else 0
101+
102+
return java.lang.String.format("#%06X", 0xFFFFFF and clr)
103+
}
104+
85105
override fun handleInitPackageResources(resparam: XC_InitPackageResources.InitPackageResourcesParam) {
86106
if (resparam.packageName.contains(".webview")) return
87107

@@ -121,6 +141,7 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
121141
val vendetta = File(cache, "vendetta.js")
122142
val etag = File(cache, "vendetta_etag.txt")
123143
val themeJs = File(cache, "vendetta_theme.js")
144+
val syscolorsJs = File(cache, "vendetta_syscolors.js")
124145

125146
lateinit var config: LoaderConfig
126147
val files = File(param.appInfo.dataDir, "files").also { it.mkdirs() }
@@ -216,10 +237,94 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
216237

217238
override fun afterHookedMethod(param: MethodHookParam) {
218239
try {
240+
val context = AndroidAppHelper.currentApplication()
219241
val themeString = try { themeFile.readText() } catch (_: Exception) { "null" }
220242
themeJs.writeText("this.__vendetta_theme=$themeString")
243+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
244+
val colors = mutableMapOf<String, List<String>>()
245+
colors["neutral1"] = arrayOf(
246+
android.R.color.system_neutral1_0,
247+
android.R.color.system_neutral1_10,
248+
android.R.color.system_neutral1_50,
249+
android.R.color.system_neutral1_100,
250+
android.R.color.system_neutral1_200,
251+
android.R.color.system_neutral1_300,
252+
android.R.color.system_neutral1_400,
253+
android.R.color.system_neutral1_500,
254+
android.R.color.system_neutral1_600,
255+
android.R.color.system_neutral1_700,
256+
android.R.color.system_neutral1_800,
257+
android.R.color.system_neutral1_900,
258+
android.R.color.system_neutral1_1000
259+
).map { sysColorToHexString(context, it) }
260+
colors["neutral2"] = arrayOf(
261+
android.R.color.system_neutral2_0,
262+
android.R.color.system_neutral2_10,
263+
android.R.color.system_neutral2_50,
264+
android.R.color.system_neutral2_100,
265+
android.R.color.system_neutral2_200,
266+
android.R.color.system_neutral2_300,
267+
android.R.color.system_neutral2_400,
268+
android.R.color.system_neutral2_500,
269+
android.R.color.system_neutral2_600,
270+
android.R.color.system_neutral2_700,
271+
android.R.color.system_neutral2_800,
272+
android.R.color.system_neutral2_900,
273+
android.R.color.system_neutral2_1000
274+
).map { sysColorToHexString(context, it) }
275+
colors["accent1"] = arrayOf(
276+
android.R.color.system_accent1_0,
277+
android.R.color.system_accent1_10,
278+
android.R.color.system_accent1_50,
279+
android.R.color.system_accent1_100,
280+
android.R.color.system_accent1_200,
281+
android.R.color.system_accent1_300,
282+
android.R.color.system_accent1_400,
283+
android.R.color.system_accent1_500,
284+
android.R.color.system_accent1_600,
285+
android.R.color.system_accent1_700,
286+
android.R.color.system_accent1_800,
287+
android.R.color.system_accent1_900,
288+
android.R.color.system_accent1_1000
289+
).map { sysColorToHexString(context, it) }
290+
colors["accent2"] = arrayOf(
291+
android.R.color.system_accent2_0,
292+
android.R.color.system_accent2_10,
293+
android.R.color.system_accent2_50,
294+
android.R.color.system_accent2_100,
295+
android.R.color.system_accent2_200,
296+
android.R.color.system_accent2_300,
297+
android.R.color.system_accent2_400,
298+
android.R.color.system_accent2_500,
299+
android.R.color.system_accent2_600,
300+
android.R.color.system_accent2_700,
301+
android.R.color.system_accent2_800,
302+
android.R.color.system_accent2_900,
303+
android.R.color.system_accent2_1000
304+
).map { sysColorToHexString(context, it) }
305+
colors["accent3"] = arrayOf(
306+
android.R.color.system_accent3_0,
307+
android.R.color.system_accent3_10,
308+
android.R.color.system_accent3_50,
309+
android.R.color.system_accent3_100,
310+
android.R.color.system_accent3_200,
311+
android.R.color.system_accent3_300,
312+
android.R.color.system_accent3_400,
313+
android.R.color.system_accent3_500,
314+
android.R.color.system_accent3_600,
315+
android.R.color.system_accent3_700,
316+
android.R.color.system_accent3_800,
317+
android.R.color.system_accent3_900,
318+
android.R.color.system_accent3_1000
319+
).map { sysColorToHexString(context, it) }
320+
321+
syscolorsJs.writeText("this.__vendetta_syscolors=${Json.encodeToString(colors)}")
322+
} else {
323+
syscolorsJs.writeText("this.__vendetta_syscolors=null")
324+
}
221325

222326
XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(themeJs.absolutePath, themeJs.absolutePath, param.args[2]))
327+
XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(syscolorsJs.absolutePath, syscolorsJs.absolutePath, param.args[2]))
223328
XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(vendetta.absolutePath, vendetta.absolutePath, param.args[2]))
224329
} catch (_: Exception) {}
225330
}

0 commit comments

Comments
 (0)