在电子中开发应用程序并做出反应,在开发模式下一切正常,但在生产模式下,我遇到路径问题。
Windows - v 10 电子 - v1.8.9 React - v16.3
当应用程序打开时,引发一个事件,用于将数据从服务器下载到本地系统,以便在脱机模式下显示。
在开发模式下使用互联网文件路径如下
"D:\Workspace\Electron App\images\image01.jpg"
"D:\Workspace\Electron App\images\image02.jpg"
"D:\Workspace\Electron App\images\image03.jpg"
在没有互联网的分发模式下,文件路径就像这样
"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"
从上面的网址app.asar
是一个文件而不是文件夹,我无法找到下载的文件,我不确定网址为何.eslintignore - app - app.js
以下是我下载文件的代码
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);
}
});
});
});
期待急需的帮助
谢谢