forked from jsnbuchanan/crowd-funder-for-time-pwa
commit working index.html
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
@@ -9,29 +10,82 @@ function createWindow() {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
webSecurity: true,
|
||||
allowRunningInsecureContent: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Log the paths we're trying to load from
|
||||
const appPath = app.getAppPath();
|
||||
const indexPath = path.join(appPath, "www", "index.html");
|
||||
// Disable service worker in Electron
|
||||
mainWindow.webContents.session.setPermissionRequestHandler(
|
||||
(webContents, permission, callback) => {
|
||||
if (permission === "serviceWorker") {
|
||||
return callback(false);
|
||||
}
|
||||
callback(true);
|
||||
},
|
||||
);
|
||||
|
||||
// Get the correct app path for packaged and development environments
|
||||
const appPath = app.isPackaged ? process.resourcesPath : app.getAppPath();
|
||||
|
||||
// Add debug logging for paths
|
||||
console.log("Debug Info:");
|
||||
console.log("App is packaged:", app.isPackaged);
|
||||
console.log("Process resource path:", process.resourcesPath);
|
||||
console.log("App path:", appPath);
|
||||
console.log("Trying to load from:", indexPath);
|
||||
console.log("__dirname:", __dirname);
|
||||
console.log("process.cwd():", process.cwd());
|
||||
console.log("www path:", path.join(process.resourcesPath, "www"));
|
||||
console.log(
|
||||
"www assets path:",
|
||||
path.join(process.resourcesPath, "www", "assets"),
|
||||
);
|
||||
|
||||
// Load the index.html file
|
||||
mainWindow.loadFile(indexPath).catch((err) => {
|
||||
console.error("Failed to load index.html:", err);
|
||||
// Try to list directory contents to debug
|
||||
const fs = require("fs");
|
||||
console.log("Directory contents:", fs.readdirSync(appPath));
|
||||
});
|
||||
// Try both possible www locations
|
||||
const possiblePaths = [
|
||||
path.join(appPath, "www", "index.html"),
|
||||
path.join(appPath, "..", "www", "index.html"),
|
||||
path.join(process.resourcesPath, "www", "index.html"),
|
||||
];
|
||||
|
||||
// Open the DevTools in development
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
mainWindow.webContents.openDevTools();
|
||||
let indexPath;
|
||||
for (const testPath of possiblePaths) {
|
||||
console.log("Testing path:", testPath);
|
||||
if (fs.existsSync(testPath)) {
|
||||
indexPath = testPath;
|
||||
console.log("Found valid path:", indexPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Load the index.html
|
||||
mainWindow
|
||||
.loadFile(indexPath)
|
||||
.then(() => {
|
||||
console.log("Successfully loaded index.html");
|
||||
// Always open DevTools in packaged app for debugging
|
||||
mainWindow.webContents.openDevTools();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed to load index.html:", err);
|
||||
console.error("Attempted path:", indexPath);
|
||||
});
|
||||
|
||||
// Listen for page errors
|
||||
mainWindow.webContents.on(
|
||||
"did-fail-load",
|
||||
(event, errorCode, errorDescription) => {
|
||||
console.error("Page failed to load:", errorCode, errorDescription);
|
||||
},
|
||||
);
|
||||
|
||||
// Listen for console messages from the renderer
|
||||
mainWindow.webContents.on("console-message", (_event, level, message) => {
|
||||
console.log("Renderer Console:", message);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle app ready
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
|
||||
@@ -42,6 +96,7 @@ app.whenReady().then(() => {
|
||||
});
|
||||
});
|
||||
|
||||
// Handle all windows closed
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
|
||||
Reference in New Issue
Block a user