Developing an app in electron and react, everything is working fine in development mode but in production mode, I'm getting path issue.
Windows - v 10 Electron - v1.8.9 React - v16.3
When the app opens, raising an event for downloading data from server to local system for displaying in offline mode.
In development mode with internet the file paths as below
"D:\Workspace\Electron App\images\image01.jpg"
"D:\Workspace\Electron App\images\image02.jpg"
"D:\Workspace\Electron App\images\image03.jpg"
In distribution mode without internet the file paths are like this
"C:\Program Files\Electron App\resources\app.asar\images\.eslintignore"
"C:\Program Files\Electron App\resources\app.asar\images\app"
"C:\Program Files\Electron App\resources\app.asar\images\app.js"
"C:\Program Files\Electron App\resources\app.asar\images\node_modules"
From above URL app.asar is a file not a folder, and i'm not able to find the downloaded files, and i'm not sure why the URL has .eslintignore - app - app.js
Here is my code to download files
const downloadFile = (configuration) => {
const { remoteFile, localFile } = configuration;
return new Promise((resolve, reject) => {
const req = request({
method: 'GET',
uri: remoteFile,
});
const out = fs.createWriteStream(localFile);
req.pipe(out);
req.on('end', () => resolve());
req.on('error', () => reject());
});
};
ipcMain.on(STORE_DATA, (event, data) => {
const storedPaths = [];
const dataLength = data.length;
const storingPath = path.join(__dirname, '/images/');
data.map((remoteFileSource) => {
const filename = remoteFileSource.url.split('/').pop().split('#')[0].split('?')[0];
downloadFile({
remoteFile: remoteFileSource.url,
localFile: storingPath + filename,
}).then(() => {
const storedData = {
url: storingPath + filename,
};
storedPaths.push(storedData);
// Send paths to local files
if (dataLength === storedPaths.length) {
mainWindow.send(STORED_DATA, storedPaths);
}
});
});
});
Looking forward for much needed help
Thank you