|
@ -20,16 +20,20 @@ const logger = { |
|
|
const isDev = process.argv.includes("--inspect"); |
|
|
const isDev = process.argv.includes("--inspect"); |
|
|
|
|
|
|
|
|
function createWindow(): void { |
|
|
function createWindow(): void { |
|
|
// Add before createWindow function
|
|
|
// Resolve preload path based on environment
|
|
|
const preloadPath = path.join(__dirname, "preload.js"); |
|
|
const preloadPath = app.isPackaged |
|
|
logger.log("Checking preload path:", preloadPath); |
|
|
? path.join(process.resourcesPath, "preload.js") |
|
|
logger.log("Preload exists:", fs.existsSync(preloadPath)); |
|
|
: path.join(__dirname, "preload.js"); |
|
|
|
|
|
|
|
|
|
|
|
logger.log("[Electron] Preload path:", preloadPath); |
|
|
|
|
|
logger.log("[Electron] Preload exists:", fs.existsSync(preloadPath)); |
|
|
|
|
|
|
|
|
// Log environment and paths
|
|
|
// Log environment and paths
|
|
|
logger.log("process.cwd():", process.cwd()); |
|
|
logger.log("[Electron] process.cwd():", process.cwd()); |
|
|
logger.log("__dirname:", __dirname); |
|
|
logger.log("[Electron] __dirname:", __dirname); |
|
|
logger.log("app.getAppPath():", app.getAppPath()); |
|
|
logger.log("[Electron] app.getAppPath():", app.getAppPath()); |
|
|
logger.log("app.isPackaged:", app.isPackaged); |
|
|
logger.log("[Electron] app.isPackaged:", app.isPackaged); |
|
|
|
|
|
logger.log("[Electron] process.resourcesPath:", process.resourcesPath); |
|
|
|
|
|
|
|
|
// List files in __dirname and __dirname/www
|
|
|
// List files in __dirname and __dirname/www
|
|
|
try { |
|
|
try { |
|
@ -53,7 +57,7 @@ function createWindow(): void { |
|
|
contextIsolation: true, |
|
|
contextIsolation: true, |
|
|
webSecurity: true, |
|
|
webSecurity: true, |
|
|
allowRunningInsecureContent: false, |
|
|
allowRunningInsecureContent: false, |
|
|
preload: path.join(__dirname, "preload.js"), |
|
|
preload: preloadPath, // Use the resolved preload path
|
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -66,33 +70,36 @@ function createWindow(): void { |
|
|
urls: [ |
|
|
urls: [ |
|
|
"file://*/*/assets/*", |
|
|
"file://*/*/assets/*", |
|
|
"file://*/assets/*", |
|
|
"file://*/assets/*", |
|
|
"file:///assets/*", // Catch absolute paths
|
|
|
"file:///assets/*", |
|
|
"<all_urls>", // Catch all URLs as a fallback
|
|
|
"<all_urls>", |
|
|
], |
|
|
], |
|
|
}, |
|
|
}, |
|
|
(details, callback) => { |
|
|
(details, callback) => { |
|
|
let url = details.url; |
|
|
let url = details.url; |
|
|
|
|
|
logger.debug("[Electron] Intercepted URL:", url); |
|
|
|
|
|
|
|
|
|
|
|
// Get the base directory for assets
|
|
|
|
|
|
const baseDir = app.isPackaged |
|
|
|
|
|
? `file://${process.resourcesPath}` |
|
|
|
|
|
: `file://${__dirname}`; |
|
|
|
|
|
|
|
|
// Handle paths that don't start with file://
|
|
|
// Handle paths that don't start with file://
|
|
|
if (!url.startsWith("file://") && url.includes("/assets/")) { |
|
|
if (!url.startsWith("file://") && url.includes("/assets/")) { |
|
|
url = `file://${path.join(__dirname, "www", url)}`; |
|
|
url = `${baseDir}/www${url}`; |
|
|
|
|
|
logger.debug("[Electron] Rewritten non-file URL to:", url); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Handle absolute paths starting with /assets/
|
|
|
// Handle absolute paths starting with /assets/
|
|
|
if (url.includes("/assets/") && !url.includes("/www/assets/")) { |
|
|
if (url.includes("/assets/") && !url.includes("/www/assets/")) { |
|
|
const baseDir = url.includes("dist-electron") |
|
|
|
|
|
? url.substring( |
|
|
|
|
|
0, |
|
|
|
|
|
url.indexOf("/dist-electron") + "/dist-electron".length, |
|
|
|
|
|
) |
|
|
|
|
|
: `file://${__dirname}`; |
|
|
|
|
|
const assetPath = url.split("/assets/")[1]; |
|
|
const assetPath = url.split("/assets/")[1]; |
|
|
const newUrl = `${baseDir}/www/assets/${assetPath}`; |
|
|
const newUrl = `${baseDir}/www/assets/${assetPath}`; |
|
|
|
|
|
logger.debug("[Electron] Rewritten asset URL to:", newUrl); |
|
|
callback({ redirectURL: newUrl }); |
|
|
callback({ redirectURL: newUrl }); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
callback({}); // No redirect for other URLs
|
|
|
logger.debug("[Electron] No rewrite needed for URL:", url); |
|
|
|
|
|
callback({}); |
|
|
}, |
|
|
}, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|