docs: finalize README.md and GEMINI.md with full feature set

This commit is contained in:
bipproduction
2026-02-08 13:53:27 +08:00
parent f86ac66820
commit cb0f17da15
8 changed files with 193 additions and 14 deletions

View File

@@ -0,0 +1,12 @@
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.makuro",
"sha256_cert_fingerprints": [
"00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
]
}
}
]

View File

@@ -5,10 +5,21 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#f3d5a3" />
<title>Bun + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/frontend.tsx"></script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
</body>
</html>

View File

@@ -15,6 +15,13 @@ if (!isProduction) {
const { createVite } = await import("./vite");
const vite = await createVite();
// Serve PWA/TWA assets in dev
app.get("/manifest.json", () => Bun.file("src/manifest.json"));
app.get("/sw.js", () => Bun.file("src/sw.js"));
app.get("/.well-known/assetlinks.json", () =>
Bun.file("src/.well-known/assetlinks.json"),
);
app.post("/__open-in-editor", ({ body }) => {
const { relativePath, lineNumber, columnNumber } = body as {
relativePath: string;
@@ -42,7 +49,10 @@ if (!isProduction) {
(!pathname.includes(".") &&
!pathname.startsWith("/@") &&
!pathname.startsWith("/inspector") &&
!pathname.startsWith("/__open-stack-frame-in-editor"))
!pathname.startsWith("/__open-stack-frame-in-editor") &&
!pathname.startsWith("/manifest.json") &&
!pathname.startsWith("/sw.js") &&
!pathname.startsWith("/.well-known/"))
) {
try {
const htmlPath = path.resolve("src/index.html");
@@ -134,6 +144,18 @@ if (!isProduction) {
pathname === "/" ? "index.html" : pathname,
);
// 1.1 Special handling for PWA/TWA assets that might not be in dist (since we use custom bun build)
if (
pathname === "/manifest.json" ||
pathname === "/sw.js" ||
pathname === "/.well-known/assetlinks.json"
) {
const srcPath = path.join("src", pathname);
if (fs.existsSync(srcPath)) {
filePath = srcPath;
}
}
// 2. If not found and looks like an asset (has extension), try root of dist
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
if (pathname.includes(".") && !pathname.endsWith("/")) {
@@ -146,13 +168,22 @@ if (!isProduction) {
}
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
return new Response(Bun.file(filePath));
const file = Bun.file(filePath);
return new Response(file, {
headers: {
"Vary": "Accept-Encoding",
}
});
}
// 3. SPA Fallback: Serve index.html
const indexHtml = path.join("dist", "index.html");
if (fs.existsSync(indexHtml)) {
return new Response(Bun.file(indexHtml));
return new Response(Bun.file(indexHtml), {
headers: {
"Vary": "Accept-Encoding",
}
});
}
return new Response("Not Found", { status: 404 });

17
src/manifest.json Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "Makuro Base Template",
"short_name": "Makuro",
"description": "A high-performance full-stack React template",
"start_url": "/",
"display": "standalone",
"background_color": "#1a1a1a",
"theme_color": "#f3d5a3",
"icons": [
{
"src": "/logo.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any maskable"
}
]
}

25
src/sw.js Normal file
View File

@@ -0,0 +1,25 @@
const CACHE_NAME = 'makuro-v1';
const ASSETS = [
'/',
'/index.html',
'/logo.svg'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
console.log('SW: Pre-caching assets');
return cache.addAll(ASSETS).catch(err => {
console.error('SW: Pre-cache failed (likely due to Vary header or missing file):', err);
});
})
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
return response || fetch(event.request);
})
);
});

View File

@@ -34,7 +34,7 @@ export async function createVite() {
},
appType: "custom",
optimizeDeps: {
include: ["react", "react-dom", "@mantine/core"],
include: ["react", "react-dom", "@mantine/core", "manifest.json", "sw.js"],
},
});
}