android/icons.mjs (1559 bytes)
1 // The launcher icons of the app, from the same drawing as the icons of the page. 2 // `node android/icons.mjs` writes them again. 3 4 import fs from 'node:fs'; 5 import path from 'node:path'; 6 import { fileURLToPath } from 'node:url'; 7 import { icon } from '../dashboard/icons.mjs'; 8 9 const RES = path.join(path.dirname(fileURLToPath(import.meta.url)), 'app', 'src', 'main', 'res'); 10 11 // The launcher icon of older Android, and the front layer of the adaptive icon. The front layer is 12 // 108dp wide, and a phone can cut any shape from the middle 72dp, so the lamp stays small there. 13 const DENSITIES = [['mdpi', 1], ['hdpi', 1.5], ['xhdpi', 2], ['xxhdpi', 3], ['xxxhdpi', 4]]; 14 15 for (const [name, scale] of DENSITIES) { 16 const dir = path.join(RES, `mipmap-${name}`); 17 fs.mkdirSync(dir, { recursive: true }); 18 fs.writeFileSync(path.join(dir, 'ic_launcher.png'), icon(Math.round(48 * scale))); 19 fs.writeFileSync(path.join(dir, 'ic_foreground.png'), icon(Math.round(108 * scale), { maskable: true })); 20 console.log(`mipmap-${name}: ${Math.round(48 * scale)} and ${Math.round(108 * scale)}`); 21 } 22 23 const adaptive = `<?xml version="1.0" encoding="utf-8"?> 24 <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> 25 <background android:drawable="@color/background" /> 26 <foreground android:drawable="@mipmap/ic_foreground" /> 27 </adaptive-icon> 28 `; 29 fs.mkdirSync(path.join(RES, 'mipmap-anydpi-v26'), { recursive: true }); 30 fs.writeFileSync(path.join(RES, 'mipmap-anydpi-v26', 'ic_launcher.xml'), adaptive); 31 console.log('mipmap-anydpi-v26/ic_launcher.xml');