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

Commit

Permalink
[Main] Introduce dynamic colors (#12)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
nexpid and riichi67 authored Jul 15, 2023
1 parent 802511a commit 2f3aec2
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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).
11 changes: 7 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import android.annotation.SuppressLint

plugins {
id("com.android.application")
id("kotlin-android")
kotlin("plugin.serialization") version "1.8.0"
}

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 {
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion app/src/main/assets/js/identity.js

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

105 changes: 105 additions & 0 deletions app/src/main/java/com/vendetta/xposed/Main.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -53,6 +56,15 @@ data class Theme(
val data: ThemeData
)

@Serializable
data class SysColors(
val neutral1: List<String>,
val neutral2: List<String>,
val accent1: List<String>,
val accent2: List<String>,
val accent3: List<String>
)

class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources {
private lateinit var modResources: XModuleResources
private val rawColorMap = mutableMapOf<String, Int>()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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<String, List<String>>()
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) {}
}
Expand Down

0 comments on commit 2f3aec2

Please sign in to comment.