GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode-mobile/scripts/sync-app-icon.mjs at main · opencode-mobile/opencode-mobile Expand file tree/ Copy pathsync-app-icon.mjsMore file actions 385 lines (357 loc) · 12.1 KB / Copy pathsync-app-icon.mjsFile metadata and controls385 lines (357 loc) · 12.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 #!/usr/bin/env node // Generates the app launcher icon set for both platforms from // app-icon/source.svg. Emits Android adaptive-icon vectors, iOS AppIcon // PNGs (any/dark/tinted), and the iOS 26 AppIcon.icon Liquid Glass package. // See docs/design-system/app-icon.md. import { execFileSync } from "node:child_process"; import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync, unlinkSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { tmpdir } from "node:os"; import { randomBytes } from "node:crypto"; import { applyCircularAlpha, decodePng, encodePng } from "./lib/png-bytes.mjs"; import { GLASS_FILL, SOURCE_SVG, buildFlattenedSvg, buildSilhouetteSvg, buildSquareSvg, deriveInsetSquareTransform, deriveSquareTransform, ensureRsvg, parseSource, renderPng, svgTransformToAndroid, } from "./lib/app-icon-source.mjs"; const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); const IOS_APPICONSET = join(REPO_ROOT, "ios/OpenCode Mobile/OpenCode Mobile/Assets.xcassets/AppIcon.appiconset"); const IOS_ICON_COMPOSER = join(REPO_ROOT, "ios/OpenCode Mobile/OpenCode Mobile/AppIcon.icon"); const ANDROID_RES = join(REPO_ROOT, "android/app/src/main/res"); function fail(msg) { console.error(`app-icon: ${msg}`); process.exit(1); } function hexToExtendedSrgb(hex) { const h = hex.trim().replace(/^#/, ""); if (!/^[0-9a-fA-F]{6}$/.test(h)) { fail(`unsupported fill "${hex}" (need #RRGGBB)`); } const r = parseInt(h.slice(0, 2), 16) / 255; const g = parseInt(h.slice(2, 4), 16) / 255; const b = parseInt(h.slice(4, 6), 16) / 255; return `extended-srgb:${r.toFixed(5)},${g.toFixed(5)},${b.toFixed(5)},1.00000`; } function splitLayers(paths) { const norm = (f) => f.trim().toUpperCase(); const glass = paths.filter((p) => norm(p.fill) === GLASS_FILL); const body = paths.filter((p) => norm(p.fill) !== GLASS_FILL); if (body.length === 0) fail("source.svg: glyph has no body paths (non-#F1ECEC fills)"); if (glass.length === 0) fail("source.svg: glyph has no glass cap (fill #F1ECEC)"); return { body, glass }; } function writeIosContentsJson() { // iOS 14+ single-size 1024 slots. We provide any (universal) + dark + tinted // appearances, all from the same source design. "any" and "dark" use the // flattened art (dark-background design works for both luminosity modes). const json = { images: [ { filename: "icon-1024.png", idiom: "universal", platform: "ios", size: "1024x1024", }, { appearances: [{ appearance: "luminosity", value: "dark" }], filename: "icon-1024.png", idiom: "universal", platform: "ios", size: "1024x1024", }, { appearances: [{ appearance: "luminosity", value: "tinted" }], filename: "icon-tinted-1024.png", idiom: "universal", platform: "ios", size: "1024x1024", }, ], info: { author: "xcode", version: 1 }, }; writeFileSync( join(IOS_APPICONSET, "Contents.json"), JSON.stringify(json, null, 2) + "\n", "utf8", ); } function writeIconComposer(parsed, square) { const { body, glass } = splitLayers(parsed.paths); const assetsDir = join(IOS_ICON_COMPOSER, "Assets"); mkdirSync(assetsDir, { recursive: true }); const bodySvg = buildSquareSvg({ backgroundFill: "none", square, paths: body, fillOverride: "#FFFFFF", }); const glassSvg = buildSquareSvg({ backgroundFill: "none", square, paths: glass, fillOverride: "#FFFFFF", }); renderPng(bodySvg, join(assetsDir, "body.png")); renderPng(glassSvg, join(assetsDir, "glass.png")); const background = hexToExtendedSrgb(parsed.backgroundFill); const bodyFill = hexToExtendedSrgb(body[0].fill); const glassFill = hexToExtendedSrgb(glass[0].fill); const json = { "fill-specializations": [ { value: { solid: background } }, { appearance: "dark", value: { solid: background } }, ], groups: [ { name: "D Mark", layers: [ { name: "Body", "image-name": "body.png", glass: true, "fill-specializations": [ { value: { solid: bodyFill } }, { appearance: "dark", value: { solid: bodyFill } }, ], }, { name: "Glass", "image-name": "glass.png", glass: true, "fill-specializations": [ { value: { solid: glassFill } }, { appearance: "dark", value: { solid: glassFill } }, ], translucency: { enabled: true, value: 0.28 }, }, ], shadow: { kind: "neutral", opacity: 0.4 }, specular: true, translucency: { enabled: true, value: 0.16 }, lighting: "combined", }, ], "supported-platforms": { squares: ["iOS"] }, }; writeFileSync(join(IOS_ICON_COMPOSER, "icon.json"), JSON.stringify(json, null, 2) + "\n", "utf8"); } function maybeValidateIconComposer() { let ictool; try { const xcode = execFileSync("xcode-select", ["-p"], { encoding: "utf8" }).trim(); ictool = join(dirname(xcode), "Applications/Icon Composer.app/Contents/Executables/ictool"); } catch { console.log("app-icon: Icon Composer ictool not found; skipped .icon render check"); return; } if (!existsSync(ictool)) { console.log("app-icon: Icon Composer ictool not found; skipped .icon render check"); return; } const out = join(tmpdir(), `opencode-app-icon-ictool-${randomBytes(4).toString("hex")}.png`); try { execFileSync( ictool, [ IOS_ICON_COMPOSER, "--export-image", "--output-file", out, "--platform", "iOS", "--rendition", "Default", "--width", "64", "--height", "64", "--scale", "1", ], { stdio: "pipe" }, ); } catch (err) { fail(`ictool rejected AppIcon.icon: ${err.stdout?.toString() || err.stderr?.toString() || err.message}`); } finally { try { rmSync(out); } catch {} } } function androidVectorXml({ transform, paths, fillFor }) { const { translateX, translateY, scaleX, scaleY } = svgTransformToAndroid(transform); const pathsXml = paths .map((p) => { const fill = fillFor ? fillFor(p) : p.fill; return ` <path\n android:pathData="${p.d}"\n android:fillColor="${fill}" />`; }) .join("\n"); return `<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="240" android:viewportHeight="300"> <group android:scaleX="${scaleX}" android:scaleY="${scaleY}" android:translateX="${translateX}" android:translateY="${translateY}"> ${pathsXml} </group> </vector> `; } function writeAndroidRes(relativePath, contents) { const out = join(ANDROID_RES, relativePath); mkdirSync(dirname(out), { recursive: true }); writeFileSync(out, contents, "utf8"); } function writeAndroidForeground(parsed) { writeAndroidRes("drawable/ic_launcher_foreground.xml", androidVectorXml(parsed)); } function writeAndroidBackgroundColor({ backgroundFill }) { writeAndroidRes( "values/ic_launcher_background.xml", `<?xml version="1.0" encoding="utf-8"?> <resources> <color name="ic_launcher_background">${backgroundFill}</color> </resources> `, ); } function writeAndroidMonochrome(parsed) { writeAndroidRes( "drawable/ic_launcher_monochrome.xml", androidVectorXml({ ...parsed, fillFor: () => "#FFFFFF", }), ); } // Splash uses app chrome (`background-base` / light ink), not the launcher // tile `#070707`. Light mode darkens the glass cap so it still reads on // `#F8F8F8`; dark mode keeps the source two-tone. const SPLASH_BACKGROUND_LIGHT = "#F8F8F8"; const SPLASH_BACKGROUND_DARK = "#1C1C1C"; const SPLASH_GLASS_LIGHT = "#171311"; function writeAndroidSplash(parsed) { const { body, glass } = splitLayers(parsed.paths); const bodyFill = body[0].fill; const glassFill = glass[0].fill; writeAndroidRes( "values/splash_colors.xml", `<?xml version="1.0" encoding="utf-8"?> <resources> <color name="splash_background">${SPLASH_BACKGROUND_LIGHT}</color> <color name="splash_glyph_body">${bodyFill}</color> <color name="splash_glyph_glass">${SPLASH_GLASS_LIGHT}</color> </resources> `, ); writeAndroidRes( "values-night/splash_colors.xml", `<?xml version="1.0" encoding="utf-8"?> <resources> <color name="splash_background">${SPLASH_BACKGROUND_DARK}</color> <color name="splash_glyph_body">${bodyFill}</color> <color name="splash_glyph_glass">${glassFill}</color> </resources> `, ); writeAndroidRes( "drawable/ic_splash.xml", androidVectorXml({ ...parsed, fillFor: (p) => p.fill.trim().toUpperCase() === GLASS_FILL.toUpperCase() ? "@color/splash_glyph_glass" : "@color/splash_glyph_body", }), ); } function writeAndroidAdaptive() { const adaptive = `<?xml version="1.0" encoding="utf-8"?> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <background android:drawable="@color/ic_launcher_background"/> <foreground android:drawable="@drawable/ic_launcher_foreground"/> <monochrome android:drawable="@drawable/ic_launcher_monochrome"/> </adaptive-icon> `; const outDir = join(ANDROID_RES, "mipmap-anydpi-v26"); mkdirSync(outDir, { recursive: true }); writeFileSync(join(outDir, "ic_launcher.xml"), adaptive, "utf8"); writeFileSync(join(outDir, "ic_launcher_round.xml"), adaptive, "utf8"); } function writeAndroidLegacyMipmaps(squareSvg) { const densities = [ ["mipmap-mdpi", 48], ["mipmap-hdpi", 72], ["mipmap-xhdpi", 96], ["mipmap-xxhdpi", 144], ["mipmap-xxxhdpi", 192], ]; for (const [folder, size] of densities) { const dir = join(ANDROID_RES, folder); mkdirSync(dir, { recursive: true }); for (const name of ["ic_launcher", "ic_launcher_round"]) { const png = join(dir, `${name}.png`); const webp = join(dir, `${name}.webp`); renderPng(squareSvg, png, size); const decoded = decodePng(readFileSync(png)); applyCircularAlpha(decoded.rgba, decoded.width, decoded.height); writeFileSync(png, encodePng(decoded.rgba, decoded.width, decoded.height, { alpha: true })); if (existsSync(webp)) unlinkSync(webp); } } } function main() { try { run(); } catch (err) { fail(err.message); } } function run() { if (!existsSync(SOURCE_SVG)) fail(`source SVG not found: ${SOURCE_SVG}`); ensureRsvg(); const src = readFileSync(SOURCE_SVG, "utf8"); const parsed = parseSource(src); const square = deriveSquareTransform(parsed); mkdirSync(IOS_APPICONSET, { recursive: true }); // iOS: flattened icon (any + dark) and tinted silhouette, rendered into a // square viewBox so the portrait source's design intent is preserved. const flattened = buildFlattenedSvg(parsed, square); const silhouette = buildSilhouetteSvg(parsed, square); renderPng(flattened, join(IOS_APPICONSET, "icon-1024.png")); renderPng(silhouette, join(IOS_APPICONSET, "icon-tinted-1024.png")); writeIosContentsJson(); // iOS 26+: layered Liquid Glass package. Xcode generates pre-26 fallbacks // from this file; the appiconset PNGs stay as an explicit catalog copy. writeIconComposer(parsed, square); maybeValidateIconComposer(); // Android: emit adaptive-icon layers from the same source. writeAndroidForeground(parsed); writeAndroidMonochrome(parsed); writeAndroidBackgroundColor(parsed); writeAndroidAdaptive(); writeAndroidSplash(parsed); // FAD / aapt / pre-26 launchers show these PNGs unmasked. Keep the // adaptive layers full-bleed; only the fallback rasters get a pixel // circle (SVG clipPath tessellates into a polygon). writeAndroidLegacyMipmaps( buildFlattenedSvg(parsed, deriveInsetSquareTransform(parsed)), ); console.log("app-icon: synced iOS AppIcon + AppIcon.icon + Android adaptive icon + splash from app-icon/source.svg"); } if (import.meta.url === pathToFileURL(process.argv[1]).href) { main(); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |