Add Tauri v2 desktop app alongside Electron
- New tauri/ project: frameless 1280x800 window, loads the Vite dev server in dev and tauri/frontend_build in release builds. - Starts the backend on launch (node server.js in dev, pkg backend.exe sidecar in release) and stops it on exit through a Windows job object; reuses a backend already listening on port 4000. - Custom title bar works in Tauri (minimize, maximize, close, drag region) with the matching window capabilities. - react_frontend: dev:tauri / build:tauri scripts, shared platform flags so Electron and Tauri builds both use the local API and hash router. Web and Electron builds are unchanged. - tauri/README.md: prerequisites, dev, build, and gaps vs Electron.
This commit is contained in:
1 parent
06bf902ad3
commit
3144bd96c9
30 files changed
+5121
-14
No files matched your search
@@ -6,6 +6,8 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"dev:tauri": "cross-env VITE_TAURI=true vite",
|
||||
"build:tauri": "cross-env VITE_TAURI=true vite build --outDir ../tauri/frontend_build --emptyOutDir",
|
||||
"build:electron": "cross-env VITE_ELECTRON=true vite build --outDir ../electron/frontend_build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
@@ -15,6 +17,7 @@
|
||||
"@fontsource-variable/geist": "^5.2.8",
|
||||
"@hookform/resolvers": "^5.2.2",
|
||||
"@tanstack/react-query": "^5.95.2",
|
||||
"@tauri-apps/api": "^2.12.4",
|
||||
"axios": "^1.14.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
|
||||
Generated
+8
@@ -51,6 +51,9 @@ importers:
|
||||
'@tanstack/react-query':
|
||||
specifier: ^5.95.2
|
||||
version: 5.100.8(react@19.2.5)
|
||||
'@tauri-apps/api':
|
||||
specifier: ^2.12.4
|
||||
version: 2.12.4
|
||||
axios:
|
||||
specifier: ^1.20.0
|
||||
version: 1.21.0(debug@4.4.3(supports-color@7.2.0))(supports-color@7.2.0)
|
||||
@@ -798,6 +801,9 @@ packages:
|
||||
peerDependencies:
|
||||
react: ^18 || ^19
|
||||
|
||||
'@tauri-apps/api@2.12.4':
|
||||
resolution: {integrity: sha512-pVmfis+4zT8H0Qhp3xPZx9Ju7kpzvA6rr/PSJPyuwfvucTQ8sVt61NYU9KMkK703UFlYadFmjKA4HhybOtN0gg==}
|
||||
|
||||
'@ts-morph/common@0.27.0':
|
||||
resolution: {integrity: sha512-Wf29UqxWDpc+i61k3oIOzcUfQt79PIT9y/MWfAGlrkjg6lBC1hwDECLXPVJAhWjiGbfBCxZd65F/LIZF3+jeJQ==}
|
||||
|
||||
@@ -3435,6 +3441,8 @@ snapshots:
|
||||
'@tanstack/query-core': 5.100.8
|
||||
react: 19.2.5
|
||||
|
||||
'@tauri-apps/api@2.12.4': {}
|
||||
|
||||
'@ts-morph/common@0.27.0':
|
||||
dependencies:
|
||||
fast-glob: 3.3.3
|
||||
|
||||
@@ -12,9 +12,7 @@ import { Sidebar, MobileSidebarContent } from "./Sidebar";
|
||||
import { TitleBar } from "./TitleBar";
|
||||
import { CommandPalette } from "@/components/CommandPalette";
|
||||
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
||||
|
||||
const isElectron =
|
||||
import.meta.env.VITE_ELECTRON === "true" || !!window.electron?.isElectron;
|
||||
import { isDesktop } from "@/lib/platform";
|
||||
|
||||
export function AppLayout() {
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
@@ -62,7 +60,7 @@ export function AppLayout() {
|
||||
|
||||
return (
|
||||
<div className="flex h-screen flex-col overflow-hidden">
|
||||
{isElectron && <TitleBar />}
|
||||
{isDesktop && <TitleBar />}
|
||||
<CommandPalette />
|
||||
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
|
||||
@@ -1,17 +1,36 @@
|
||||
import { Minus, Square, X } from "lucide-react";
|
||||
import { isTauri } from "@/lib/platform";
|
||||
|
||||
// Loaded only inside the Tauri shell so web and Electron bundles don't pull it in eagerly.
|
||||
const tauriWindow = async () => {
|
||||
const { getCurrentWindow } = await import("@tauri-apps/api/window");
|
||||
return getCurrentWindow();
|
||||
};
|
||||
|
||||
const minimize = () =>
|
||||
isTauri
|
||||
? void tauriWindow().then((w) => w.minimize())
|
||||
: window.electron?.windowControls.minimize();
|
||||
const maximize = () =>
|
||||
isTauri
|
||||
? void tauriWindow().then((w) => w.toggleMaximize())
|
||||
: window.electron?.windowControls.maximize();
|
||||
const close = () =>
|
||||
isTauri
|
||||
? void tauriWindow().then((w) => w.close())
|
||||
: window.electron?.windowControls.close();
|
||||
|
||||
export function TitleBar() {
|
||||
const minimize = () => window.electron?.windowControls.minimize();
|
||||
const maximize = () => window.electron?.windowControls.maximize();
|
||||
const close = () => window.electron?.windowControls.close();
|
||||
|
||||
return (
|
||||
// Electron drags via -webkit-app-region; Tauri via data-tauri-drag-region,
|
||||
// which only applies to the element that carries it (not its children).
|
||||
<div
|
||||
data-tauri-drag-region
|
||||
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">
|
||||
<div data-tauri-drag-region className="flex h-full flex-1 items-center gap-2 pl-3">
|
||||
<span className="pointer-events-none text-xs font-semibold tracking-wide text-foreground/80">
|
||||
SHOWY
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import axios from 'axios';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
import { isDesktopBuild } from '@/lib/platform';
|
||||
|
||||
const API_BASE_URL =
|
||||
import.meta.env.VITE_ELECTRON === 'true'
|
||||
isDesktopBuild
|
||||
? 'http://localhost:4000/api/v1'
|
||||
: import.meta.env.VITE_API_URL || '/api/v1';
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Which shell the frontend runs in. The build-time flags come from the
|
||||
// build:electron / build:tauri / dev:tauri scripts; the runtime checks cover
|
||||
// dev mode, where the shell loads the plain Vite dev server.
|
||||
|
||||
export const isTauri =
|
||||
import.meta.env.VITE_TAURI === "true" ||
|
||||
(typeof window !== "undefined" && "__TAURI_INTERNALS__" in window);
|
||||
|
||||
export const isElectron =
|
||||
import.meta.env.VITE_ELECTRON === "true" ||
|
||||
(typeof window !== "undefined" && !!window.electron?.isElectron);
|
||||
|
||||
/** Built for a desktop shell: local backend on :4000, hash routing, custom title bar. */
|
||||
export const isDesktopBuild =
|
||||
import.meta.env.VITE_ELECTRON === "true" || import.meta.env.VITE_TAURI === "true";
|
||||
|
||||
/** Running inside a desktop shell (Electron or Tauri). */
|
||||
export const isDesktop = isElectron || isTauri;
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createBrowserRouter, createHashRouter } from "react-router-dom";
|
||||
import { lazy, Suspense, type ReactNode } from "react";
|
||||
import { AppLayout } from "@/components/layout/AppLayout";
|
||||
import { isDesktopBuild } from "@/lib/platform";
|
||||
import {
|
||||
DashboardSkeleton,
|
||||
HomeSkeleton,
|
||||
@@ -117,8 +118,7 @@ function SuspensePage({
|
||||
);
|
||||
}
|
||||
|
||||
const isElectron = import.meta.env.VITE_ELECTRON === "true";
|
||||
const createRouter = isElectron ? createHashRouter : createBrowserRouter;
|
||||
const createRouter = isDesktopBuild ? createHashRouter : createBrowserRouter;
|
||||
|
||||
export const router = createRouter([
|
||||
{
|
||||
|
||||
@@ -4,10 +4,13 @@ import tailwindcss from '@tailwindcss/vite'
|
||||
import path from 'path'
|
||||
|
||||
const isElectron = process.env.VITE_ELECTRON === 'true';
|
||||
const isTauri = process.env.VITE_TAURI === 'true';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
base: isElectron ? './' : '/',
|
||||
base: isElectron || isTauri ? './' : '/',
|
||||
// Keep Rust/Tauri output visible in the terminal during `tauri dev`.
|
||||
clearScreen: !isTauri,
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
@@ -16,6 +19,8 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
port: 4200,
|
||||
// Tauri loads devUrl http://localhost:4200, so never fall back to another port.
|
||||
strictPort: isTauri,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://showyback.coolguy.space',
|
||||
|
||||
Reference in new issue
Block a user