Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Desktop Client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SeeBeyond
Desktop Client
Commits
f20404cc
Commit
f20404cc
authored
Jun 14, 2020
by
Amy Yan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed background.js
parent
ae49df63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
28 deletions
+33
-28
src/background.js
src/background.js
+33
-28
No files found.
src/background.js
View file @
f20404cc
...
...
@@ -161,9 +161,26 @@ ipcMain.on("getDeeplink", (event) => {
function
download
(
url
,
fileName
,
cb
)
{
let
dest
=
path
.
join
(
app
.
getPath
(
'
temp
'
),
fileName
+
"
.zip
"
);
let
file
=
fs
.
createWriteStream
(
dest
);
var
partiallength
=
0
//sets partiallength to 0
if
(
new
URL
(
url
).
protocol
==
"
https:
"
)
{
let
request
=
https
.
get
(
url
,
function
(
response
)
{
response
.
pipe
(
file
);
var
totallength
=
parseInt
(
response
.
headers
[
'
content-length
'
],
10
);
//sets totallength of file
response
.
on
(
"
data
"
,
function
(
chunk
)
{
partiallength
+=
chunk
.
length
//adds each time
let
decimallength
=
partiallength
/
totallength
if
(
decimallength
!=
1
)
{
win
.
setProgressBar
(
decimallength
)
//sets progress bar to decimal
win
.
webContents
.
send
(
"
downloadProgress
"
,
decimallength
)
}
else
{
win
.
setProgressBar
(
0
)
//sets progress bar to blank when done
win
.
webContents
.
send
(
"
downloadProgress
"
,
0
)
}
});
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
(
cb
(
null
,
dest
));
// async call of the callback
});
...
...
@@ -171,9 +188,25 @@ function download(url, fileName, cb) {
fs
.
unlink
(
dest
);
// Delete the file async. (But we don't check the result)
if
(
cb
)
cb
(
err
.
message
,
dest
);
});
}
else
{
let
request
=
http
.
get
(
url
,
function
(
response
)
{
response
.
pipe
(
file
);
var
totallength
=
parseInt
(
response
.
headers
[
'
content-length
'
],
10
);
//sets totallength of file
response
.
on
(
"
data
"
,
function
(
chunk
)
{
partiallength
+=
chunk
.
length
//adds each time
let
decimallength
=
partiallength
/
totallength
if
(
decimallength
!=
1
)
{
win
.
setProgressBar
(
decimallength
)
//sets progress bar to decimal
win
.
webContents
.
send
(
"
downloadProgress
"
,
decimallength
)
}
else
{
win
.
setProgressBar
(
0
)
//sets progress bar to blank when done
win
.
webContents
.
send
(
"
downloadProgress
"
,
0
)
}
});
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
(
cb
(
null
,
dest
));
// async call of the callback
});
...
...
@@ -182,32 +215,4 @@ function download(url, fileName, cb) {
if
(
cb
)
cb
(
err
.
message
,
dest
);
});
}
let
request
=
https
.
get
(
url
,
function
(
response
)
{
var
partiallength
=
0
//sets partiallength to 0
var
totallength
=
parseInt
(
response
.
headers
[
'
content-length
'
],
10
);
//sets totallength of file
response
.
on
(
"
data
"
,
function
(
chunk
)
{
partiallength
+=
chunk
.
length
//adds each time
let
decimallength
=
partiallength
/
totallength
if
(
decimallength
!=
1
)
{
win
.
setProgressBar
(
decimallength
)
//sets progress bar to decimal
win
.
webContents
.
send
(
"
downloadProgress
"
,
decimallength
)
}
else
{
win
.
setProgressBar
(
0
)
//sets progress bar to blank when done
win
.
webContents
.
send
(
"
downloadProgress
"
,
0
)
}
});
response
.
pipe
(
file
);
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
(
cb
(
null
,
dest
));
// async call of the callback
});
}).
on
(
'
error
'
,
function
(
err
)
{
// Handle errors
fs
.
unlink
(
dest
);
// Delete the file async. (But we don't check the result)
if
(
cb
)
cb
(
err
.
message
,
dest
);
});
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment