freezmo/components/InstallHint.tsx
Martin Dvorak 3ea2cea100 Freezmo: self-hosted notes-to-activities study app
Next.js 15 app that turns photos, PDFs, DOCX/PPTX and text into a swipeable
feed of AI-generated activities (flashcards, multiple choice, true/false,
fill-in-the-blank, matching, ordering, short answer) using the user's own
Ollama models.

Highlights:
- All AI calls run in server route handlers; the browser never talks to Ollama.
- Bring-your-own-key mode (default): the key lives only in the browser and is
  sent per-request; server, local-daemon and shared-key modes also supported.
- Client-side document extraction (pdf.js, mammoth, jszip) with scanned-PDF
  page rendering for the vision model; notes stay in their original language.
- ChatGPT-style shell: collapsible sidebar / mobile drawer, neutral token-based
  light + dark themes, folder organisation, PWA (manifest, SW, offline page).
- Strict JSON validation with zod + auto-repair, rate limiting, and request
  guards (cross-origin, body-size, API-key sanitising).
- setup.sh bootstraps deps, .env.local and a production build.

Gitignore excludes .env*, the generated pdf.js worker and local scratch files.
2026-10-06 20:56:55 +00:00

64 lines
2.1 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { ShareIcon } from "@/components/icons";
const DISMISS_KEY = "freezmo.installHintDismissed";
/**
* iOS has no `beforeinstallprompt`, so the only way to explain installing the
* PWA is to point at the Share sheet. Shown once, only in iOS Safari, only
* outside standalone mode.
*/
export function InstallHint() {
const [visible, setVisible] = useState(false);
useEffect(() => {
try {
if (window.localStorage.getItem(DISMISS_KEY) === "1") return;
const ua = window.navigator.userAgent;
const isIos = /iPad|iPhone|iPod/.test(ua) || (ua.includes("Macintosh") && "ontouchend" in document);
const isSafari = /Safari/.test(ua) && !/CriOS|FxiOS|EdgiOS|OPiOS/.test(ua);
const standalone =
window.matchMedia("(display-mode: standalone)").matches ||
(window.navigator as unknown as { standalone?: boolean }).standalone === true;
if (isIos && isSafari && !standalone) setVisible(true);
} catch {
/* private mode */
}
}, []);
if (!visible) return null;
const dismiss = () => {
setVisible(false);
try {
window.localStorage.setItem(DISMISS_KEY, "1");
} catch {
/* ignore */
}
};
return (
<div className="glass-panel animate-rise flex items-start gap-3 rounded-[1.35rem] p-3.5 text-sm">
<ShareIcon className="mt-0.5 size-5 shrink-0 text-accent-600 dark:text-accent-300" />
<div className="flex-1">
<p className="font-semibold text-frost-950 dark:text-frost-50">Install Freezmo</p>
<p className="text-frost-600 dark:text-frost-300">
Tap <span className="font-medium">Share</span> then{" "}
<span className="font-medium">Add to Home Screen</span> for a full-screen, app-like
experience that works without the browser chrome.
</p>
</div>
<button
type="button"
onClick={dismiss}
aria-label="Dismiss install hint"
className="rounded-lg px-2 py-1 text-frost-400 transition-colors hover:bg-[var(--surface-sunken)]"
>
✕
</button>
</div>
);
}