Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first check for desktop app electron #668

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions electron-main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { app, BrowserWindow } from "electron";
import path from "path";
import express from "express";
import cors from "cors";
import { fileURLToPath } from 'url'; // Import fileURLToPath function

const __filename = fileURLToPath(import.meta.url); // Get the current module's filename
const __dirname = path.dirname(__filename); // Get the directory name

const localServerApp = express();
const PORT = 5173;

const startLocalServer = (done) => {
localServerApp.use(express.json({ limit: "100mb" }));
localServerApp.use(cors());
localServerApp.use(express.static('./build/'));
localServerApp.listen(PORT, async () => {
console.log("Server Started on PORT ", PORT);
done();
});
};

function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
});

// and load the index.html of the app.
// mainWindow.loadFile('index.html')
mainWindow.loadURL(`http://localhost:${PORT}`);


}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
startLocalServer(createWindow);

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});

// Quit when all windows are closed
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
Loading