From 62e161eb4f944ecfa7bb1527ffde6eb770d6832e Mon Sep 17 00:00:00 2001 From: astar76 Date: Fri, 4 Dec 2026 08:07:47 -0600 Subject: [PATCH] Add Cookie Glass (Material You): Android wallpaper colors with the GIF (1.6.0) Native half (plugin.jar + src/main) is dim's Material You palette reader, prebuilt dex taken from dim-ghub/valenced-materialyou gh-pages 1.0.9 (GPL-3.0). Falls back to the mauve palette on iOS and Android < 12. Co-Authored-By: Claude Opus 5.5 --- themes/cookie-glass/js/index.ts | 81 ++++++++++++++++-- themes/cookie-glass/manifest.json | 8 +- themes/cookie-glass/plugin.jar | Bin 0 -> 3652 bytes .../cookie-glass/src/main/AndroidManifest.xml | 2 + .../kotlin/dim/materialyou/MaterialYou.kt | 45 ++++++++++ tools/package.sh | 1 + 6 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 themes/cookie-glass/plugin.jar create mode 100644 themes/cookie-glass/src/main/AndroidManifest.xml create mode 100644 themes/cookie-glass/src/main/kotlin/dim/materialyou/MaterialYou.kt diff --git a/themes/cookie-glass/js/index.ts b/themes/cookie-glass/js/index.ts index 42483b1..658e26d 100644 --- a/themes/cookie-glass/js/index.ts +++ b/themes/cookie-glass/js/index.ts @@ -12,6 +12,8 @@ /// import { Tokens } from '@valenced/discord/common/tokens' +import { callNativeMethodSync } from '@valenced/modules/native' +import { AppState } from 'react-native' import { Palettes, Semantic } from './colors' import { Icons } from './icons' import type { @@ -19,8 +21,10 @@ import type { FontVariant, ThemeBase, ThemeColors, + ThemesApi, } from '@valenced/themes-api/types' +const PluginId = 'com.astar76.cookie-glass' const Group = 'cookie-glass' type PaletteName = keyof typeof Palettes @@ -277,14 +281,22 @@ const Tonal = Object.fromEntries( ]), ) as Record -function buildColors(discord: DiscordColors): ThemeColors { - const p = Tonal - +/** + * @param p tonal palettes: ours, or Android's system ones + * @param surfaces palette the grays are re-toned from (neutral2 tints them with the accent) + * @param glass put the desktop theme's hand-tuned mauve glass on top (only fits our palettes) + */ +function buildColors( + discord: DiscordColors, + p: Record = Tonal, + surfaces: PaletteName = 'neutral1', + glass = true, +): ThemeColors { // swap discord's grays/blurple for ours of the same tone const raw: Record = {} for (const [name, value] of Object.entries(discord.raw)) { const palette = NeutralRaw.test(name) - ? 'neutral1' + ? surfaces : BrandRaw.test(name) ? 'accent1' : undefined @@ -317,7 +329,7 @@ function buildColors(discord: DiscordColors): ThemeColors { colors[name] = withAlpha(roles[role], alpha) // the desktop theme's hand-tuned glass on top - if (GlassBases.has(base)) Object.assign(colors, Semantic) + if (glass && GlassBases.has(base)) Object.assign(colors, Semantic) semantic[base] = colors } @@ -325,6 +337,30 @@ function buildColors(discord: DiscordColors): ThemeColors { return { raw, semantic } } +// Android 12+ system palettes, read by the native half (src/main, from dim's Material You). +// Null on iOS, older Android, or before the native half has started. +let palettesJson: string | null = null + +function readPalettes() { + try { + palettesJson = callNativeMethodSync(`${PluginId}.getPalettes`, []) + } catch { + palettesJson = null + } + return palettesJson +} + +function syncedColors(discord: DiscordColors): ThemeColors { + if (!palettesJson) readPalettes() + if (!palettesJson) return buildColors(discord) + const system = Object.fromEntries( + Object.entries(JSON.parse(palettesJson) as Record).map( + ([name, shades]) => [name, tonalPalette(shades)], + ), + ) as Record + return buildColors(discord, system, 'neutral2', false) +} + // Panel see-through: lower shows more of the shapes. const Dimming = 0.55 @@ -344,7 +380,31 @@ for (const [style, wght] of Object.entries(Weights)) { path: FontItalic, weight: wght, italic: true, axes: { wght } }, ] +function registerSynced(themes: ThemesApi) { + themes.registerTheme(Group, 'system', { + name: 'Cookie Glass (Material You)', + description: + 'Drifting shapes, colors from your Android wallpaper (Android 12+). Mauve on iOS.', + getColors: syncedColors, + background: { path: 'assets/background-animated.gif', dimming: Dimming }, + }) +} + export default plugin({ + start({ themes, cleanup }) { + // the native half is up now: re-registering re-applies the theme if it's selected + readPalettes() + registerSynced(themes) + + // wallpaper/palette may have changed while backgrounded + const subscription = AppState.addEventListener('change', state => { + if (state !== 'active') return + const previous = palettesJson + if (readPalettes() !== previous) registerSynced(themes) + }) + cleanup(() => subscription.remove()) + }, + preInit({ themes }) { themes.registerGroup(Group, { name: 'Cookie Glass', @@ -366,6 +426,8 @@ export default plugin({ background: { path: 'assets/background.png', dimming: Dimming }, }) + registerSynced(themes) + themes.registerFontPack(Group, 'figtree', { name: 'Figtree', description: 'Variable font, replaces gg sans', @@ -393,3 +455,12 @@ export default plugin({ }) }, }) + +declare module '@valenced/modules/native' { + interface NativeMethods { + 'com.astar76.cookie-glass.getPalettes': [ + args: [], + returnValue: string | null, + ] + } +} diff --git a/themes/cookie-glass/manifest.json b/themes/cookie-glass/manifest.json index 13a7266..c6160da 100644 --- a/themes/cookie-glass/manifest.json +++ b/themes/cookie-glass/manifest.json @@ -4,7 +4,7 @@ "name": "Cookie Glass", "description": "Material 3 Expressive mauve theme with drifting cookie / flower shapes behind see-through panels, Figtree font and Material Symbols icons. Based on Material You by dim: every component themed, light and dark, iOS and Android.", "author": "astar76", - "version": "1.5.0", + "version": "1.6.0", "dependencies": { "valenced.api": { "version": ">=1 <2" @@ -17,6 +17,10 @@ } }, "dist": { - "script": "index.js" + "script": "index.js", + "android": { + "path": "plugin.jar", + "class": "dim.materialyou.MaterialYou" + } } } diff --git a/themes/cookie-glass/plugin.jar b/themes/cookie-glass/plugin.jar new file mode 100644 index 0000000000000000000000000000000000000000..462d615fa9bea180f4da2342a1af11355f53de90 GIT binary patch literal 3652 zcmWIWW@Zs#;Nak3U|>*WKnC0loD9i1iN(dK#d;~J6`>)l42&T8-kJ3|GRI4g-+yyY zU#|bjJ=v4W{`M7Cb2TohRsK<(B@%kPr*7i4&PA@XF7j{x^eN9%u5x?zp4*E(yr(@? zDV=gGZ!Ozj<;MR7!O8`*nOM2RIYhPx^ePlaFW_KeF1)zl?_w>f1$l{E^kyw!yz>6c zxghs8L*GZm@6Vo@eRJmbduQ&wd)m{R@c)AFmZE2;|0nGKJHPAO`pLb^*ZId+JkPG5 z{&V})W&bOS11-&}$0PjaWOkozRef6?$n&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gYjvd-}>&d>GSM&VzAM4zRnrC6Ib}F@2xO&OXWqDk6S8}ywMcyVmvxAO5yk=cU-@u!Ril-7VHXJ)UdMT4DQ6Z1u7&R?1r&WyPY|m6Ez6 zLO$K(x^Gl1Kl96vb#8tx{!vGT%vPrE>bx*#<0uW>nGNyZ$8n(7%o{dRZ-(yro+Km)_eJPB|giDFS~hS zonQ2~lC1$2djk(uMm2^%`|5Oc!L(b)B=@cnpIDdrNohye%s-LkIx=>%#l69S`J(g7<75It;@8Y{DfT`1*X)Y_+TB+d?aTfC%Rf_6 zAwF=~%ChP~&${k&nP z_h*e`Z1>XmuDgG@x?ArY;uU#y_fWTn$&S`&4HK>27rWwn|GMR9h*gHX=y$!L`2J9x zSn|!k3vVo`_+r5x*CE?Cb7R69iPhb?ao;tzC%zA~k>jtOTlwR3#@2sN84Nk+Sw=iQ zonK{_k;S$D@)2(-uk~3EKe+p97?ha{Iv)KUW%6g*G3_b4JJUk$aBgpr&(N9|cE#dw z{p)by_h!a5EgwH78t*Q?{W(!PyWU&mcEs)5Yjysmad+2WI`c^WQ@F{MzV;O!yFZ_q zJYiG#smDR{rWW~m#d-;E(%$!XXF-Mg&m(=GR?0p-(^sVT@5Nq=|Buhd6c;|fd$qXm zx#iv3WyMQ>?-qUk{9oD8-#homSH8HIAMt0e>)ZDc@A4yc9_~5(cz^mz&VO>(EAx+< zET6YOI7H~&)*tU<=e2yk*ZsS1zsU2)AIf`IJ^S*s?&Ha-e{z%j=bWGV|J=9#0p9E! zn`egqTgA)3ut1uDA;6oFNrVB>+e4NE_4Yu$I|Rno_Y3f5Wdo^TWME`)Vqjo+!wcd8 E0P>b17ytkO literal 0 HcmV?d00001 diff --git a/themes/cookie-glass/src/main/AndroidManifest.xml b/themes/cookie-glass/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b2d3ea1 --- /dev/null +++ b/themes/cookie-glass/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/themes/cookie-glass/src/main/kotlin/dim/materialyou/MaterialYou.kt b/themes/cookie-glass/src/main/kotlin/dim/materialyou/MaterialYou.kt new file mode 100644 index 0000000..1596f3f --- /dev/null +++ b/themes/cookie-glass/src/main/kotlin/dim/materialyou/MaterialYou.kt @@ -0,0 +1,45 @@ +@file:JvmName("MaterialYou") + +package dim.materialyou + +import android.app.AndroidAppHelper +import android.content.Context +import android.os.Build +import app.valenced.plugins.plugin +import app.valenced.xposed.api.registerNativeMethod +import org.json.JSONArray +import org.json.JSONObject + +private val Palettes = listOf("accent1", "accent2", "accent3", "neutral1", "neutral2") + +// lightest to darkest +private val Shades = listOf(0, 10, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000) + +@Suppress("UNUSED") +val materialYou = plugin { + start { + var appContext: Context? = null + withAppContext { appContext = it.applicationContext } + + registerNativeMethod("${manifest.id}.getPalettes") { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return@registerNativeMethod null + + val context = AndroidAppHelper.currentApplication() ?: appContext + ?: return@registerNativeMethod null + val res = context.resources + + val palettes = JSONObject() + for (palette in Palettes) { + val shades = JSONArray() + for (shade in Shades) { + @Suppress("DiscouragedApi") + val id = res.getIdentifier("system_${palette}_$shade", "color", "android") + if (id == 0) return@registerNativeMethod null + shades.put(String.format("#%06X", res.getColor(id, null) and 0xFFFFFF)) + } + palettes.put(palette, shades) + } + palettes.toString() + } + } +} diff --git a/tools/package.sh b/tools/package.sh index 390d24b..07cce93 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -13,6 +13,7 @@ for dir in themes/*/ plugins/*/; do stage=$(mktemp -d -p "$HOME/.cache") cp "$dir/manifest.json" "$dir/build/js/index.js" "$stage/" [ -d "$dir/assets" ] && cp -r "$dir/assets" "$stage/assets" + [ -f "$dir/plugin.jar" ] && cp "$dir/plugin.jar" "$stage/" rm -f "dist/$id.zip" (cd "$stage" && zip -qr -X "$OLDPWD/dist/$id.zip" .) rm -rf "$stage"