Update: Electron implementation changed BrowserRouter to HashRouter due to Electron implementation issues. Basic Electron build configuration in package.json.

This commit is contained in:
DNLRQ 2024-11-27 22:24:02 -07:00
parent 3f633d6dc5
commit f2e239beaa
5 changed files with 74 additions and 27 deletions

View File

@ -1,41 +1,30 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow, Menu } = require('electron');
const path = require('node:path'); const path = require('path');
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
function createWindow() { function createWindow() {
const isDev = !app.isPackaged; // Detectar si es entorno de desarrollo const isDev = !app.isPackaged;
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
//icon: path.join(__dirname, 'public/favicon.ico'), icon: path.join(__dirname, 'favicon.ico'),
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js'),
contextIsolation: true, // Mejora la seguridad contextIsolation: true,
enableRemoteModule: false, // Deshabilitar módulos remotos por seguridad enableRemoteModule: false,
nodeIntegration: false, // Desactiva integración con Node.js
}, },
}); });
if (isDev) { if (isDev) {
// En desarrollo, cargar la URL del servidor de Vite
win.loadURL('http://localhost:5173'); win.loadURL('http://localhost:5173');
win.webContents.openDevTools(); // Abrir herramientas de desarrollo win.webContents.openDevTools();
} else { } else {
// En producción, cargar el archivo index.html de la carpeta dist win.loadURL(`file://${path.join(__dirname, 'dist/index.html')}`);
win.loadFile(path.join(__dirname, 'dist/index.html')); Menu.setApplicationMenu(null);
}
if (!isDev) {
import('@vercel/analytics').then(({ inject }) => inject());
} }
} }
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow(); createWindow();

51
package-lock.json generated
View File

@ -7507,6 +7507,17 @@
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
"dev": true "dev": true
}, },
"node_modules/isomorphic.js": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.2.5.tgz",
"integrity": "sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==",
"license": "MIT",
"peer": true,
"funding": {
"type": "GitHub Sponsors ❤",
"url": "https://github.com/sponsors/dmonad"
}
},
"node_modules/iterator.prototype": { "node_modules/iterator.prototype": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.3.tgz", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.3.tgz",
@ -7772,6 +7783,28 @@
"resolved": "https://registry.npmjs.org/lexical/-/lexical-0.12.6.tgz", "resolved": "https://registry.npmjs.org/lexical/-/lexical-0.12.6.tgz",
"integrity": "sha512-Nlfjc+k9cIWpOMv7XufF0Mv09TAXSemNAuAqFLaOwTcN+RvhvYTDtVLSp9D9r+5I097fYs1Vf/UYwH2xEpkFfQ==" "integrity": "sha512-Nlfjc+k9cIWpOMv7XufF0Mv09TAXSemNAuAqFLaOwTcN+RvhvYTDtVLSp9D9r+5I097fYs1Vf/UYwH2xEpkFfQ=="
}, },
"node_modules/lib0": {
"version": "0.2.98",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.98.tgz",
"integrity": "sha512-XteTiNO0qEXqqweWx+b21p/fBnNHUA1NwAtJNJek1oPrewEZs2uiT4gWivHKr9GqCjDPAhchz0UQO8NwU3bBNA==",
"license": "MIT",
"peer": true,
"dependencies": {
"isomorphic.js": "^0.2.4"
},
"bin": {
"0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js",
"0gentesthtml": "bin/gentesthtml.js",
"0serve": "bin/0serve.js"
},
"engines": {
"node": ">=16"
},
"funding": {
"type": "GitHub Sponsors ❤",
"url": "https://github.com/sponsors/dmonad"
}
},
"node_modules/lilconfig": { "node_modules/lilconfig": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz",
@ -12775,6 +12808,24 @@
"fd-slicer": "~1.1.0" "fd-slicer": "~1.1.0"
} }
}, },
"node_modules/yjs": {
"version": "13.6.20",
"resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.20.tgz",
"integrity": "sha512-Z2YZI+SYqK7XdWlloI3lhMiKnCdFCVC4PchpdO+mCYwtiTwncjUbnRK9R1JmkNfdmHyDXuWN3ibJAt0wsqTbLQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"lib0": "^0.2.98"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"funding": {
"type": "GitHub Sponsors ❤",
"url": "https://github.com/sponsors/dmonad"
}
},
"node_modules/yocto-queue": { "node_modules/yocto-queue": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",

View File

@ -62,6 +62,12 @@
"win": { "win": {
"target": "nsis", "target": "nsis",
"signAndEditExecutable": false "signAndEditExecutable": false
},
"mac": {
"target": "dmg"
},
"linux": {
"target": ["AppImage", "deb", "rpm"]
} }
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,4 +1,4 @@
import { BrowserRouter, Routes, Route, useLocation } from "react-router-dom"; import { HashRouter, Routes, Route, useLocation } from "react-router-dom";
import { useLayoutEffect } from "react"; import { useLayoutEffect } from "react";
import Editor from "./pages/Editor"; import Editor from "./pages/Editor";
import Survey from "./pages/Survey"; import Survey from "./pages/Survey";
@ -13,7 +13,8 @@ import NotFound from "./pages/NotFound";
export default function App() { export default function App() {
return ( return (
<SettingsContextProvider> <SettingsContextProvider>
<BrowserRouter> {/* Cambiado de BrowserRouter a HashRouter */}
<HashRouter>
<RestoreScroll /> <RestoreScroll />
<Routes> <Routes>
<Route path="/" element={<LandingPage />} /> <Route path="/" element={<LandingPage />} />
@ -52,7 +53,7 @@ export default function App() {
<Route path="/templates" element={<Templates />} /> <Route path="/templates" element={<Templates />} />
<Route path="*" element={<NotFound />} /> <Route path="*" element={<NotFound />} />
</Routes> </Routes>
</BrowserRouter> </HashRouter>
</SettingsContextProvider> </SettingsContextProvider>
); );
} }

View File

@ -4,13 +4,13 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
base: './', // Esto asegura que las rutas generadas sean relativas al archivo index.html base: './',
build: { build: {
outDir: 'dist', // Carpeta de salida para producción outDir: 'dist',
emptyOutDir: true, // Limpia la carpeta antes de construir emptyOutDir: true,
}, },
server: { server: {
port: 5173, // El puerto donde Vite escucha por defecto port: 5173,
}, },
}) })