Skip to content

Commit

Permalink
Fixes #804. Ensure only writable close event triggers data send to wi…
Browse files Browse the repository at this point in the history
…ndow.
  • Loading branch information
Matthew Mulholland committed Jun 3, 2018
1 parent 5abb466 commit ca51de0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"datapackage": "^1.0.6",
"electron-settings": "^3.2.0",
"escape-regexp": "^0.0.1",
"etl": "^0.5.8",
"etl": "^0.5.12",
"fs-extra": "~5.0.0",
"handsontable": "^0.35.1",
"imports-loader": "^0.8.0",
Expand All @@ -101,7 +101,7 @@
"svgo": "^1.0.5",
"tableschema": "^1.9.1",
"tmp": "^0.0.33",
"unzipper": "^0.8.12",
"unzipper": "^0.8.14",
"vee-validate": "^2.0.4",
"vue": "^2.5.2",
"vue-async-computed": "^3.3.1",
Expand Down
15 changes: 8 additions & 7 deletions src/main/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,26 @@ export async function importDataPackageZipFromUrl(urlText) {
const zipPath = path.join(zipDir, basename)
fs.ensureFileSync(zipPath)
const writable = fs.createWriteStream(zipPath)
let errors = false
// close will be called automatically - just need to ensure close on error
response.data.on('error', (error) => {
response.data.end()
writable.end()
console.log(`Problem with read stream`, error)
errors = true
})
writable.on('error', (error) => {
response.data.end()
writable.end()
console.log(`Problem with write stream`, error)
errors = true
})
await response.data.pipe(writable)
mainWindow.webContents.send('closeLoadingScreen')
if (!errors) {
// response.data.on('end', () => {
// console.log('finished writing response')
// })
// do not send file path to renderer until response has completed writing
writable.on('close', () => {
mainWindow.webContents.send('closeLoadingScreen')
handleDownloadedZip(zipPath, mainWindow)
}
})
await response.data.pipe(writable)
} catch (error) {
console.log(`Unable to download zip: ${urlText}`, error)
mainWindow.webContents.send('closeLoadingScreen')
Expand Down
22 changes: 9 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1489,8 +1489,8 @@ better-assert@~1.0.0:
callsite "1.0.0"

big-integer@^1.6.17:
version "1.6.27"
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.27.tgz#8e56c6f8b2dd6c4fe8d32102b83d4f25868e4b3a"
version "1.6.30"
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.30.tgz#7796f04acdd6ba56345f19049c8fffd427f09d16"

big.js@^3.1.3:
version "3.2.0"
Expand Down Expand Up @@ -4147,14 +4147,14 @@ etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"

etl@^0.5.8:
version "0.5.8"
resolved "https://registry.yarnpkg.com/etl/-/etl-0.5.8.tgz#684bf6f20a0a23d31b75e3d63f56848dfe511243"
etl@^0.5.12:
version "0.5.12"
resolved "https://registry.yarnpkg.com/etl/-/etl-0.5.12.tgz#71fa98e39706dcd216e5ae09e0f29dfc9f6d128b"
dependencies:
bluebird "~3.5.0"
csv-parser "~1.8.0"
duplexer2 "~0.1.4"
moment "~2.18.1"
moment "~2.21.0"
streamz "~1.8.4"

event-emitter@~0.3.5:
Expand Down Expand Up @@ -6965,10 +6965,6 @@ [email protected], moment@^2.21.0, moment@~2.21.0:
version "2.21.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.21.0.tgz#2a114b51d2a6ec9e6d83cf803f838a878d8a023a"

moment@~2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
Expand Down Expand Up @@ -10228,9 +10224,9 @@ unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"

unzipper@^0.8.12:
version "0.8.12"
resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.8.12.tgz#178de4e263d96a2550fb6f4804d26c06edb9c8bd"
unzipper@^0.8.14:
version "0.8.14"
resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.8.14.tgz#ade0524cd2fc14d11b8de258be22f9d247d3f79b"
dependencies:
big-integer "^1.6.17"
binary "~0.3.0"
Expand Down

0 comments on commit ca51de0

Please sign in to comment.