Add the Sandbar mobile companion PWA

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
VeillaxandClaude Sonnet 5.5 committed 2026-10-27 17:02:39 -06:00
commit ad165ef6a5
18 files changed
+1143

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
// Writes public/icon-192.png and icon-512.png (teal square with two white waves) with no dependencies.
import { deflateSync } from 'node:zlib';
import { writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
const crcTable = Array.from({ length: 256 }, (_, n) => {
let c = n;
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
return c >>> 0;
});
const crc = (b) => {
let c = 0xffffffff;
for (const x of b) c = crcTable[(c ^ x) & 255] ^ (c >>> 8);
return (c ^ 0xffffffff) >>> 0;
};
const chunk = (type, data) => {
const len = Buffer.alloc(4); len.writeUInt32BE(data.length);
const td = Buffer.concat([Buffer.from(type), data]);
const c = Buffer.alloc(4); c.writeUInt32BE(crc(td));
return Buffer.concat([len, td, c]);
};
function png(size) {
const raw = Buffer.alloc((size * 4 + 1) * size);
for (let y = 0; y < size; y++) {
raw[y * (size * 4 + 1)] = 0;
for (let x = 0; x < size; x++) {
const u = x / size, v = y / size; // 0..1
const wave = (off) => 0.5 + off + 0.06 * Math.sin((u - 0.19) * Math.PI * 6);
const body = v > wave(0.0) + 0.06 && v < 0.85 && u > 0.19 && u < 0.81; // lower filled wave
const line = Math.abs(v - wave(-0.1)) < 0.03 && u > 0.19 && u < 0.81;
const i = y * (size * 4 + 1) + 1 + x * 4;
const on = body || line;
raw[i] = on ? 255 : 0x1f; raw[i + 1] = on ? 255 : 0x5c; raw[i + 2] = on ? 255 : 0x5c; raw[i + 3] = 255;
}
}
const ihdr = Buffer.alloc(13);
ihdr.writeUInt32BE(size, 0); ihdr.writeUInt32BE(size, 4); ihdr[8] = 8; ihdr[9] = 6;
return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]);
}
for (const s of [192, 512]) writeFileSync(fileURLToPath(new URL(`../public/icon-${s}.png`, import.meta.url)), png(s));
console.log('icons written');
+23
View File
@@ -0,0 +1,23 @@
// Serves public/ on http://localhost:5173 for working on the app without a Sandbar-hosted copy.
// The app then needs the server's address, and the server must allow this origin:
// SANDBAR_APP_ORIGIN=http://localhost:5173
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';
import { extname, join, normalize } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../public/', import.meta.url));
const types = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.png': 'image/png', '.webmanifest': 'application/manifest+json' };
const port = Number(process.env.PORT || 5173);
createServer(async (req, res) => {
let p = normalize(decodeURIComponent(new URL(req.url, 'http://x').pathname)).replace(/^([/\])+/, '');
if (p === '' || p.endsWith('/')) p += 'index.html';
if (p.includes('..')) { res.writeHead(400).end(); return; }
try {
const body = await readFile(join(root, p));
res.writeHead(200, { 'Content-Type': types[extname(p)] || 'application/octet-stream', 'Cache-Control': 'no-cache' }).end(body);
} catch {
res.writeHead(404).end('not found');
}
}).listen(port, () => console.log(`http://localhost:${port}`));