feat(electron/frontend) Electron Full Rework
- **Electron Full Rework**: Completely rewrote `electron/main.js` — removed child process spawn, backend now runs in-process via `require()`; frameless window with custom title bar; dual-mode support (dev loads Vite at `:4200`, production loads built files) - **`electron/preload.js`**: Enhanced contextBridge to expose `windowControls` (minimize/maximize/close) and `isElectron` flag alongside existing `ipcRenderer` bridge - **`electron/package.json`**: Updated scripts (`start`, `dev`, `build-front` → calls React build), removed duplicated backend dependencies (backend now required in-process), updated electron-builder config with proper `files` and `extraResources` - **`TitleBar` component**: New `react_frontend/src/components/layout/TitleBar.tsx` — custom frameless window title bar with drag region, app branding, and IPC-powered minimize/maximize/close buttons - **`AppLayout`**: Conditionally renders `<TitleBar>` when built for Electron (`VITE_ELECTRON=true`); wrapped content in an extra flex container to accommodate title bar height - **`vite.config.ts`**: Added `VITE_ELECTRON` env detection — sets `base: './'` for correct asset resolution in `file://` context - **`api.ts`**: Dynamic base URL — uses `http://localhost:4000/api/v1` in Electron mode, `/api/v1` (proxy-relative) otherwise - **`router.tsx`**: Conditional router factory — uses `createHashRouter` in Electron mode (required for `file://` navigation) and `createBrowserRouter` for web - **`electron.d.ts`**: Added TypeScript declarations for `window.electron` global (windowControls, ipcRenderer, isElectron) - **`package.json`**: Added `build:electron` script with `cross-env VITE_ELECTRON=true`; added `cross-env` devDependency - Updated `Electron.md` Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
7b84f89b65
commit
4303b33677
14 files changed
+5522
-164
No files matched your search
@@ -9,6 +9,9 @@ import {
|
||||
SheetTitle,
|
||||
} from '@/components/ui/sheet';
|
||||
import { Sidebar, MobileSidebarContent } from './Sidebar';
|
||||
import { TitleBar } from './TitleBar';
|
||||
|
||||
const isElectron = import.meta.env.VITE_ELECTRON === 'true' || !!window.electron?.isElectron;
|
||||
|
||||
export function AppLayout() {
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
@@ -20,35 +23,39 @@ export function AppLayout() {
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen overflow-hidden">
|
||||
{/* Desktop sidebar */}
|
||||
<div className="hidden md:block">
|
||||
<Sidebar />
|
||||
</div>
|
||||
<div className="flex h-screen flex-col overflow-hidden">
|
||||
{isElectron && <TitleBar />}
|
||||
|
||||
{/* Mobile header */}
|
||||
<div className="fixed inset-x-0 top-0 z-40 flex h-14 items-center gap-3 border-b border-border bg-background px-4 md:hidden">
|
||||
<Button variant="ghost" size="icon" onClick={() => setMobileOpen(true)}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
<span className="text-lg font-bold">Showy</span>
|
||||
</div>
|
||||
|
||||
{/* Mobile sidebar sheet */}
|
||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||
<SheetContent side="left" className="w-64 p-0" showCloseButton={false}>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Navigation</SheetTitle>
|
||||
</SheetHeader>
|
||||
<MobileSidebarContent onNavigate={() => setMobileOpen(false)} />
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
|
||||
<main ref={mainRef} className="flex-1 overflow-y-auto md:ml-56">
|
||||
<div className="container mx-auto px-4 py-4 pt-18 md:px-6 md:py-6 md:pt-6">
|
||||
<Outlet />
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
{/* Desktop sidebar */}
|
||||
<div className="hidden md:block">
|
||||
<Sidebar />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{/* Mobile header */}
|
||||
<div className="fixed inset-x-0 top-0 z-40 flex h-14 items-center gap-3 border-b border-border bg-background px-4 md:hidden">
|
||||
<Button variant="ghost" size="icon" onClick={() => setMobileOpen(true)}>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
<span className="text-lg font-bold">Showy</span>
|
||||
</div>
|
||||
|
||||
{/* Mobile sidebar sheet */}
|
||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||
<SheetContent side="left" className="w-64 p-0" showCloseButton={false}>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Navigation</SheetTitle>
|
||||
</SheetHeader>
|
||||
<MobileSidebarContent onNavigate={() => setMobileOpen(false)} />
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
|
||||
<main ref={mainRef} className="flex-1 overflow-y-auto md:ml-56">
|
||||
<div className="container mx-auto px-4 py-4 pt-18 md:px-6 md:py-6 md:pt-6">
|
||||
<Outlet />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Minus, Square, X } from 'lucide-react';
|
||||
|
||||
export function TitleBar() {
|
||||
const minimize = () => window.electron?.windowControls.minimize();
|
||||
const maximize = () => window.electron?.windowControls.maximize();
|
||||
const close = () => window.electron?.windowControls.close();
|
||||
|
||||
return (
|
||||
<div className="flex h-14 select-none items-center justify-between border-b border-border bg-background"
|
||||
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
|
||||
>
|
||||
<div className="flex items-center gap-2 pl-3">
|
||||
<span className="text-xs font-semibold tracking-wide text-foreground/80">SHOWY</span>
|
||||
</div>
|
||||
|
||||
<div className="flex h-full" style={{ WebkitAppRegion: 'no-drag' } as React.CSSProperties}>
|
||||
<button
|
||||
onClick={minimize}
|
||||
className="flex h-full w-11 items-center justify-center transition-colors hover:bg-muted"
|
||||
>
|
||||
<Minus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button
|
||||
onClick={maximize}
|
||||
className="flex h-full w-11 items-center justify-center transition-colors hover:bg-muted"
|
||||
>
|
||||
<Square className="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
onClick={close}
|
||||
className="flex h-full w-11 items-center justify-center transition-colors hover:bg-red-500 hover:text-white"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user