|
1 | 1 | package com.vendetta.xposed
|
2 | 2 |
|
| 3 | +import android.app.AndroidAppHelper |
3 | 4 | import android.content.Context
|
4 | 5 | import android.graphics.Color
|
5 | 6 | import android.content.res.AssetManager
|
6 | 7 | import android.content.res.Resources
|
7 | 8 | import android.content.res.XModuleResources
|
| 9 | +import android.os.Build |
8 | 10 | import android.util.Log
|
| 11 | +import androidx.core.content.ContextCompat |
9 | 12 | import de.robv.android.xposed.IXposedHookLoadPackage
|
10 | 13 | import de.robv.android.xposed.IXposedHookZygoteInit
|
11 | 14 | import de.robv.android.xposed.IXposedHookInitPackageResources
|
@@ -53,6 +56,15 @@ data class Theme(
|
53 | 56 | val data: ThemeData
|
54 | 57 | )
|
55 | 58 |
|
| 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 | + |
56 | 68 | class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources {
|
57 | 69 | private lateinit var modResources: XModuleResources
|
58 | 70 | private val rawColorMap = mutableMapOf<String, Int>()
|
@@ -82,6 +94,14 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
|
82 | 94 | }
|
83 | 95 | }
|
84 | 96 |
|
| 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 | + |
85 | 105 | override fun handleInitPackageResources(resparam: XC_InitPackageResources.InitPackageResourcesParam) {
|
86 | 106 | if (resparam.packageName.contains(".webview")) return
|
87 | 107 |
|
@@ -121,6 +141,7 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
|
121 | 141 | val vendetta = File(cache, "vendetta.js")
|
122 | 142 | val etag = File(cache, "vendetta_etag.txt")
|
123 | 143 | val themeJs = File(cache, "vendetta_theme.js")
|
| 144 | + val syscolorsJs = File(cache, "vendetta_syscolors.js") |
124 | 145 |
|
125 | 146 | lateinit var config: LoaderConfig
|
126 | 147 | val files = File(param.appInfo.dataDir, "files").also { it.mkdirs() }
|
@@ -216,10 +237,94 @@ class Main : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPacka
|
216 | 237 |
|
217 | 238 | override fun afterHookedMethod(param: MethodHookParam) {
|
218 | 239 | try {
|
| 240 | + val context = AndroidAppHelper.currentApplication() |
219 | 241 | val themeString = try { themeFile.readText() } catch (_: Exception) { "null" }
|
220 | 242 | 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 | + } |
221 | 325 |
|
222 | 326 | 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])) |
223 | 328 | XposedBridge.invokeOriginalMethod(loadScriptFromFile, param.thisObject, arrayOf(vendetta.absolutePath, vendetta.absolutePath, param.args[2]))
|
224 | 329 | } catch (_: Exception) {}
|
225 | 330 | }
|
|
0 commit comments