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 <[email protected]>
This commit is contained in:
astar76 2026-12-04 08:07:47 -06:00
commit 62e161eb4f
6 changed files with 130 additions and 7 deletions

View file

@ -12,6 +12,8 @@
/// <reference types="@valenced/themes-api" />
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<PaletteName, TonalPalette>
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<PaletteName, TonalPalette> = Tonal,
surfaces: PaletteName = 'neutral1',
glass = true,
): ThemeColors {
// swap discord's grays/blurple for ours of the same tone
const raw: Record<string, string> = {}
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<string, string[]>).map(
([name, shades]) => [name, tonalPalette(shades)],
),
) as Record<PaletteName, TonalPalette>
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,
]
}
}

View file

@ -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"
}
}
}

Binary file not shown.

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

View file

@ -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()
}
}
}

View file

@ -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"