Package a self-contained macOS app and harden serving
- Add macos/build.mjs: stages a universal .app outside the checkout, bundles and checksums Node, installs production deps per architecture, compiles the launcher shim, signs ad-hoc or with a Developer ID, and writes a zip and dmg with an optional notarization path. - Serve precompressed brotli/gzip assets and split admin panels and the public pages out of the main bundle. - Support HTTP range requests, and fix upload and quota accounting, gallery download counts and unreadable-file handling. - Add server HTTP integration tests, a Gitea CI workflow, a catalog backup script and a crash screen for the UI.
This commit is contained in:
+66
-51
@@ -1,21 +1,15 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import AboutModal from './components/AboutModal';
|
||||
import AdminPanel from './components/AdminPanel';
|
||||
import CloudPanel from './components/CloudPanel';
|
||||
import CommandPalette from './components/CommandPalette';
|
||||
import ContextMenu, { type MenuEntry } from './components/ContextMenu';
|
||||
import Develop from './components/Develop';
|
||||
import EventSidebar from './components/EventSidebar';
|
||||
import ExportModal from './components/ExportModal';
|
||||
import CompareView from './components/CompareView';
|
||||
import FilterBar from './components/FilterBar';
|
||||
import ImportModal from './components/ImportModal';
|
||||
import ImmichPanel from './components/ImmichPanel';
|
||||
import LibraryGrid from './components/LibraryGrid';
|
||||
import MergeModal from './components/MergeModal';
|
||||
import PasteSettingsModal from './components/PasteSettingsModal';
|
||||
import PrintModal from './components/PrintModal';
|
||||
import ShareModal from './components/ShareModal';
|
||||
import RawReprocessModal, {
|
||||
type RawReprocessFailure,
|
||||
type RawReprocessJob,
|
||||
@@ -26,6 +20,15 @@ import Shortcuts from './components/Shortcuts';
|
||||
import Stars, { ColorSwatches, FlagButtons } from './components/Stars';
|
||||
import TopBar from './components/TopBar';
|
||||
import { usePersistentState } from './lib/usePersistentState';
|
||||
|
||||
// Only mounted when the user opens them, so they are separate chunks: the grid
|
||||
// and the editor are what the first paint needs.
|
||||
const AdminPanel = lazy(() => import('./components/AdminPanel'));
|
||||
const CompareView = lazy(() => import('./components/CompareView'));
|
||||
const ImmichPanel = lazy(() => import('./components/ImmichPanel'));
|
||||
const MergeModal = lazy(() => import('./components/MergeModal'));
|
||||
const PrintModal = lazy(() => import('./components/PrintModal'));
|
||||
const ShareModal = lazy(() => import('./components/ShareModal'));
|
||||
import {
|
||||
currentUser,
|
||||
deleteEventRemote,
|
||||
@@ -2563,32 +2566,38 @@ export default function App() {
|
||||
)}
|
||||
|
||||
{compareOpen && selected.length >= 2 && selected.length <= 4 && (
|
||||
<CompareView
|
||||
photos={selected
|
||||
.map((id) => photos.find((photo) => photo.id === id))
|
||||
.filter((photo): photo is PhotoRecord => Boolean(photo))
|
||||
.slice(0, 4)}
|
||||
onClose={() => setCompareOpen(false)}
|
||||
onOpen={(id) => {
|
||||
setCompareOpen(false);
|
||||
openPhoto(id);
|
||||
}}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<CompareView
|
||||
photos={selected
|
||||
.map((id) => photos.find((photo) => photo.id === id))
|
||||
.filter((photo): photo is PhotoRecord => Boolean(photo))
|
||||
.slice(0, 4)}
|
||||
onClose={() => setCompareOpen(false)}
|
||||
onOpen={(id) => {
|
||||
setCompareOpen(false);
|
||||
openPhoto(id);
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{printOpen && (
|
||||
<PrintModal
|
||||
photos={photos.filter((photo) => selected.includes(photo.id))}
|
||||
onClose={() => setPrintOpen(false)}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<PrintModal
|
||||
photos={photos.filter((photo) => selected.includes(photo.id))}
|
||||
onClose={() => setPrintOpen(false)}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{mergeOpen && (
|
||||
<MergeModal
|
||||
photos={photos.filter((photo) => selected.includes(photo.id))}
|
||||
onClose={() => setMergeOpen(false)}
|
||||
onDone={(result) => void addMergedPhoto(result)}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<MergeModal
|
||||
photos={photos.filter((photo) => selected.includes(photo.id))}
|
||||
onClose={() => setMergeOpen(false)}
|
||||
onDone={(result) => void addMergedPhoto(result)}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{exportOpen && (
|
||||
@@ -2638,13 +2647,15 @@ export default function App() {
|
||||
const shared = events.find((e) => e.id === shareEventId);
|
||||
if (!shared) return null;
|
||||
return (
|
||||
<ShareModal
|
||||
event={shared}
|
||||
photos={livePhotos.filter((p) => p.eventId === shared.id)}
|
||||
onClose={() => setShareEventId(null)}
|
||||
onToast={setToast}
|
||||
onProofPublished={handleProofPublished}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<ShareModal
|
||||
event={shared}
|
||||
photos={livePhotos.filter((p) => p.eventId === shared.id)}
|
||||
onClose={() => setShareEventId(null)}
|
||||
onToast={setToast}
|
||||
onProofPublished={handleProofPublished}
|
||||
/>
|
||||
</Suspense>
|
||||
);
|
||||
})()}
|
||||
|
||||
@@ -2681,26 +2692,30 @@ export default function App() {
|
||||
)}
|
||||
|
||||
{adminOpen && cloudUser && !localMode && (
|
||||
<AdminPanel
|
||||
user={cloudUser}
|
||||
onClose={() => setAdminOpen(false)}
|
||||
onChanged={() => {
|
||||
void getHealth().then((health) => setCloudHealth(health));
|
||||
void getImmichStatus().then(setImmichStatus).catch(() => undefined);
|
||||
}}
|
||||
onRestored={() => void refreshCatalogFromServer()}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<AdminPanel
|
||||
user={cloudUser}
|
||||
onClose={() => setAdminOpen(false)}
|
||||
onChanged={() => {
|
||||
void getHealth().then((health) => setCloudHealth(health));
|
||||
void getImmichStatus().then(setImmichStatus).catch(() => undefined);
|
||||
}}
|
||||
onRestored={() => void refreshCatalogFromServer()}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{immichOpen && cloudUser && (
|
||||
<ImmichPanel
|
||||
onClose={() => setImmichOpen(false)}
|
||||
onChanged={() => {
|
||||
void getImmichStatus().then(setImmichStatus).catch(() => undefined);
|
||||
void refreshCatalogFromServer();
|
||||
}}
|
||||
onToast={setToast}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<ImmichPanel
|
||||
onClose={() => setImmichOpen(false)}
|
||||
onChanged={() => {
|
||||
void getImmichStatus().then(setImmichStatus).catch(() => undefined);
|
||||
void refreshCatalogFromServer();
|
||||
}}
|
||||
onToast={setToast}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{menu &&
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
interface State {
|
||||
error: Error | null;
|
||||
componentStack: string;
|
||||
version: string;
|
||||
copied: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Without this, one exception anywhere in the tree unmounts React and leaves a
|
||||
* blank page with nothing to report. The boundary keeps a way back (reload)
|
||||
* and a way to tell support what happened, and says plainly that the library
|
||||
* itself is untouched.
|
||||
*/
|
||||
export default class ErrorBoundary extends Component<Props, State> {
|
||||
state: State = { error: null, componentStack: '', version: '', copied: false };
|
||||
|
||||
static getDerivedStateFromError(error: Error): Partial<State> {
|
||||
return { error };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||
console.error('Luminary crashed while rendering', error, info.componentStack);
|
||||
this.setState({ componentStack: info.componentStack ?? '' });
|
||||
// The version is a nicety for the diagnostics; the page works without it.
|
||||
fetch('/api/health', { credentials: 'same-origin' })
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.then((body: { version?: string } | null) => {
|
||||
if (body?.version) this.setState({ version: body.version });
|
||||
})
|
||||
.catch(() => undefined);
|
||||
}
|
||||
|
||||
private diagnostics(): string {
|
||||
const error = this.state.error;
|
||||
return [
|
||||
'Luminary crash report',
|
||||
`Version: ${this.state.version || 'unknown'}`,
|
||||
`When: ${new Date().toISOString()}`,
|
||||
`Page: ${window.location.pathname}${window.location.search}`,
|
||||
`Browser: ${navigator.userAgent}`,
|
||||
`Screen: ${window.screen.width}x${window.screen.height} @${window.devicePixelRatio}x`,
|
||||
'',
|
||||
`Error: ${error?.name ?? 'Error'}: ${error?.message ?? 'unknown'}`,
|
||||
error?.stack ?? '',
|
||||
'',
|
||||
'Component stack:',
|
||||
this.state.componentStack,
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
private async copyDiagnostics() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(this.diagnostics());
|
||||
this.setState({ copied: true });
|
||||
window.setTimeout(() => this.setState({ copied: false }), 2500);
|
||||
} catch {
|
||||
// Clipboard access can be denied; the email link still carries the report.
|
||||
this.setState({ copied: false });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const error = this.state.error;
|
||||
if (!error) return this.props.children;
|
||||
|
||||
const subject = encodeURIComponent('Luminary crash report');
|
||||
const body = encodeURIComponent(this.diagnostics().slice(0, 1800));
|
||||
const mailto = `mailto:bhursey@gmail.com?subject=${subject}&body=${body}`;
|
||||
|
||||
return (
|
||||
<section className="crash-screen" role="alert">
|
||||
<div className="crash-card">
|
||||
<h1>Luminary hit an unexpected error</h1>
|
||||
<p>
|
||||
Your photos, edits and catalog are safe on disk — nothing was deleted. Reloading
|
||||
usually clears it. If it keeps happening, send the diagnostics below so it can be
|
||||
fixed.
|
||||
</p>
|
||||
<p className="crash-message">{error.message || 'Unknown error'}</p>
|
||||
<div className="btn-row">
|
||||
<button className="btn primary" onClick={() => window.location.reload()}>
|
||||
Reload Luminary
|
||||
</button>
|
||||
<button className="btn ghost" onClick={() => void this.copyDiagnostics()}>
|
||||
{this.state.copied ? 'Copied' : 'Copy diagnostics'}
|
||||
</button>
|
||||
<a className="btn ghost" href={mailto}>
|
||||
Email support
|
||||
</a>
|
||||
</div>
|
||||
<details className="crash-details">
|
||||
<summary>Technical details</summary>
|
||||
<pre>{this.diagnostics()}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
+19
-9
@@ -1,9 +1,15 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import App from './App';
|
||||
import ProofingGallery from './components/ProofingGallery';
|
||||
import JoinPage from './components/JoinPage';
|
||||
import ErrorBoundary from './components/ErrorBoundary';
|
||||
import './styles.css';
|
||||
|
||||
// Proofing galleries and invite pages are public and self-contained: loading
|
||||
// them lazily keeps the editor out of the chunk a client downloads to view a
|
||||
// shoot, and keeps the invite page tiny.
|
||||
const ProofingGallery = lazy(() => import('./components/ProofingGallery'));
|
||||
const JoinPage = lazy(() => import('./components/JoinPage'));
|
||||
|
||||
const root = document.getElementById('root');
|
||||
if (!root) throw new Error('root element missing');
|
||||
|
||||
@@ -14,11 +20,15 @@ const galleryMatch = /^\/g\/([A-Za-z0-9_-]+)\/?$/.exec(window.location.pathname)
|
||||
const joinMatch = /^\/join\/([A-Za-z0-9_-]+)\/?$/.exec(window.location.pathname);
|
||||
|
||||
createRoot(root).render(
|
||||
galleryMatch ? (
|
||||
<ProofingGallery token={galleryMatch[1]} />
|
||||
) : joinMatch ? (
|
||||
<JoinPage token={joinMatch[1]} />
|
||||
) : (
|
||||
<App />
|
||||
),
|
||||
<ErrorBoundary>
|
||||
<Suspense fallback={null}>
|
||||
{galleryMatch ? (
|
||||
<ProofingGallery token={galleryMatch[1]} />
|
||||
) : joinMatch ? (
|
||||
<JoinPage token={joinMatch[1]} />
|
||||
) : (
|
||||
<App />
|
||||
)}
|
||||
</Suspense>
|
||||
</ErrorBoundary>,
|
||||
);
|
||||
|
||||
@@ -6066,3 +6066,78 @@ figcaption {
|
||||
line-height: 1.7;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- crash boundary */
|
||||
/* Shown instead of a blank page when rendering throws. Kept light on purpose:
|
||||
it must not depend on any component that could itself be broken. */
|
||||
.crash-screen {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.crash-card {
|
||||
width: min(560px, 100%);
|
||||
padding: 26px 28px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
.crash-card h1 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.crash-card p {
|
||||
margin: 0 0 12px;
|
||||
color: var(--muted);
|
||||
line-height: 1.6;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.crash-card .crash-message {
|
||||
padding: 10px 12px;
|
||||
border-left: 3px solid var(--danger);
|
||||
background: rgba(224, 93, 93, 0.08);
|
||||
color: var(--text);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 12px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.crash-details {
|
||||
margin-top: 16px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.crash-details summary {
|
||||
cursor: pointer;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.crash-details pre {
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
padding: 10px 12px;
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.crash-card a.btn {
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user