|
|
@ -107,60 +107,47 @@ function createWindow(): void { |
|
|
|
logger.log("process.cwd():", process.cwd()); |
|
|
|
} |
|
|
|
|
|
|
|
let indexPath = path.resolve(__dirname, "dist-electron", "www", "index.html"); |
|
|
|
if (!fs.existsSync(indexPath)) { |
|
|
|
// Fallback for dev mode
|
|
|
|
indexPath = path.resolve( |
|
|
|
process.cwd(), |
|
|
|
"dist-electron", |
|
|
|
"www", |
|
|
|
"index.html", |
|
|
|
); |
|
|
|
} |
|
|
|
let indexPath: string; |
|
|
|
|
|
|
|
if (isDev) { |
|
|
|
logger.log("Loading index from:", indexPath); |
|
|
|
logger.log("www path:", path.join(__dirname, "www")); |
|
|
|
logger.log("www assets path:", path.join(__dirname, "www", "assets")); |
|
|
|
if (app.isPackaged) { |
|
|
|
// In production, files are inside the asar archive or extraResources
|
|
|
|
indexPath = path.join(process.resourcesPath, "www", "index.html"); |
|
|
|
logger.info("[Electron] App is packaged. Using process.resourcesPath for index.html"); |
|
|
|
} else { |
|
|
|
// In dev, use the local path
|
|
|
|
indexPath = path.resolve(__dirname, "www", "index.html"); |
|
|
|
logger.info("[Electron] App is not packaged. Using __dirname for index.html"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!fs.existsSync(indexPath)) { |
|
|
|
logger.error(`Index file not found at: ${indexPath}`); |
|
|
|
throw new Error("Index file not found"); |
|
|
|
logger.info("[Electron] Resolved index.html path:", indexPath); |
|
|
|
try { |
|
|
|
const exists = fs.existsSync(indexPath); |
|
|
|
logger.info(`[Electron] fs.existsSync for index.html: ${exists}`); |
|
|
|
} catch (e) { |
|
|
|
logger.error("[Electron] Error checking fs.existsSync for index.html:", e); |
|
|
|
} |
|
|
|
|
|
|
|
// Add CSP headers to allow API connections
|
|
|
|
mainWindow.webContents.session.webRequest.onHeadersReceived( |
|
|
|
(details, callback) => { |
|
|
|
callback({ |
|
|
|
responseHeaders: { |
|
|
|
...details.responseHeaders, |
|
|
|
"Content-Security-Policy": [ |
|
|
|
"default-src 'self';" + |
|
|
|
"connect-src 'self' https://api.endorser.ch https://*.timesafari.app;" + |
|
|
|
"img-src 'self' data: https: blob:;" + |
|
|
|
"script-src 'self' 'unsafe-inline' 'unsafe-eval';" + |
|
|
|
"style-src 'self' 'unsafe-inline';" + |
|
|
|
"font-src 'self' data:;", |
|
|
|
], |
|
|
|
}, |
|
|
|
}); |
|
|
|
}, |
|
|
|
); |
|
|
|
// Removed fs.existsSync check to allow Electron to attempt loading regardless
|
|
|
|
|
|
|
|
// Load the index.html
|
|
|
|
logger.info("[Electron] Attempting to load index.html via mainWindow.loadFile"); |
|
|
|
mainWindow |
|
|
|
.loadFile(indexPath) |
|
|
|
.then(() => { |
|
|
|
logger.log("Successfully loaded index.html"); |
|
|
|
logger.info("[Electron] Successfully loaded index.html"); |
|
|
|
if (isDev) { |
|
|
|
mainWindow.webContents.openDevTools(); |
|
|
|
logger.log("DevTools opened - running in dev mode"); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch((err) => { |
|
|
|
logger.error("Failed to load index.html:", err); |
|
|
|
logger.error("Attempted path:", indexPath); |
|
|
|
logger.error("[Electron] Failed to load index.html:", err); |
|
|
|
logger.error("[Electron] Attempted path:", indexPath); |
|
|
|
try { |
|
|
|
const exists = fs.existsSync(indexPath); |
|
|
|
logger.error(`[Electron] fs.existsSync after loadFile error: ${exists}`); |
|
|
|
} catch (e) { |
|
|
|
logger.error("[Electron] Error checking fs.existsSync after loadFile error:", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// Listen for console messages from the renderer
|
|
|
|