forked from trent_larson/crowd-funder-for-time-pwa
Multi-build support; tested successfully for Electron
This commit is contained in:
51
src/electron/main.js
Normal file
51
src/electron/main.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const path = require("path");
|
||||
|
||||
let mainWindow;
|
||||
|
||||
app.on("ready", () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
//preload: path.join(__dirname, "preload.js"),
|
||||
contextIsolation: true, // Security setting
|
||||
},
|
||||
});
|
||||
|
||||
const indexPath = path.join(
|
||||
__dirname,
|
||||
"../../",
|
||||
"dist-electron",
|
||||
"index.html",
|
||||
);
|
||||
|
||||
console.log("Loading Vue app from:", indexPath);
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
mainWindow.webContents.on(
|
||||
"did-fail-load",
|
||||
(event, errorCode, errorDescription, validatedURL) => {
|
||||
console.error(
|
||||
"Failed to load:",
|
||||
validatedURL,
|
||||
"Error:",
|
||||
errorDescription,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
mainWindow.webContents.on("console-message", (event, level, message) => {
|
||||
console.log(`[Renderer] ${message}`);
|
||||
});
|
||||
|
||||
mainWindow.loadFile(indexPath).catch((err) => {
|
||||
console.error("Failed to load index.html:", err);
|
||||
});
|
||||
});
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
5
src/electron/preload.js
Normal file
5
src/electron/preload.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { contextBridge } = require("electron");
|
||||
|
||||
contextBridge.exposeInMainWorld("api", {
|
||||
logMessage: (message) => console.log(`[Electron]: ${message}`),
|
||||
});
|
||||
Reference in New Issue
Block a user