Skip to content

Commit 2f38a92

Browse files
committed
Mailbox/App: Fix paralleling file download. Fix #1170
1 parent 980e95d commit 2f38a92

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

electron_app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"scripts": {
1919
"electron": "electron .",
2020
"start": "npm run electron .",
21+
"start:dev": "npm run electron . --allow-file-access-from-file",
2122
"postinstall": "install-app-deps",
2223
"test": "criptext-js-tools test",
2324
"integration": "NODE_ENV=test criptext-js-tools integration",

electron_app/src/ipc/mailbox.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const ipc = require('@criptext/electron-better-ipc');
2-
const { app, BrowserWindow } = require('electron');
2+
const { app } = require('electron');
33
const unusedFilename = require('unused-filename');
44
const { download } = require('electron-dl');
55
const path = require('path');
@@ -67,21 +67,13 @@ ipc.answerRenderer(
6767
metadataKey
6868
});
6969
const filePath = path.join(directory, filename);
70-
if (isInlineImage) {
71-
if (checkIfExists(filePath)) return filePath;
72-
} else {
70+
if (!isInlineImage) {
7371
filename = path.basename(unusedFilename.sync(filePath));
7472
}
75-
76-
const downloadedItem = await download(
77-
BrowserWindow.getFocusedWindow(),
78-
url,
79-
{
80-
directory,
81-
filename,
82-
openFolderWhenDone: !isInlineImage
83-
}
84-
);
73+
const downloadedItem = await download(mailboxWindow.getWindow(), url, {
74+
directory,
75+
filename
76+
});
8577
const newFilePath = downloadedItem.getSavePath();
8678
return { filePath: newFilePath, filename };
8779
} catch (e) {

electron_app/src/windows/mailbox.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,14 @@ const isVisibleAndFocused = () => {
180180
return mailboxWindow.isVisible() && mailboxWindow.isFocused();
181181
};
182182

183+
function getWindow() {
184+
return mailboxWindow;
185+
}
186+
183187
module.exports = {
184188
close,
185189
hide,
186-
mailboxWindow,
190+
getWindow,
187191
send,
188192
show,
189193
isVisibleAndFocused,

email_mailbox/src/containers/Email.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-env node, process */
12
import { connect } from 'react-redux';
23
import { makeGetFiles } from './../selectors/files';
34
import EmailView from './../components/EmailWrapper';
@@ -116,6 +117,12 @@ const makeMapStateToProps = () => {
116117
return mapStateToProps;
117118
};
118119

120+
const defineInjectedSrc = imgPath => {
121+
return `src="${
122+
process.env.NODE_ENV === 'development' ? 'file://' : ''
123+
}${imgPath}"`;
124+
};
125+
119126
const mapDispatchToProps = (dispatch, ownProps) => {
120127
const email = ownProps.email;
121128
const isLast = ownProps.staticOpen;
@@ -283,7 +290,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
283290
const imgPath = cidFilepathPairs[cid];
284291
return emailContentInjected.replace(
285292
`src="cid:${cid}"`,
286-
`src="${imgPath}"`
293+
defineInjectedSrc(imgPath)
287294
);
288295
},
289296
emailContent

0 commit comments

Comments
 (0)