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
b90bb32a
Commit
b90bb32a
authored
Jun 17, 2020
by
SpinShare
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed redundant code, added better comments
parent
97f50101
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
src/background.js
src/background.js
+22
-16
No files found.
src/background.js
View file @
b90bb32a
...
@@ -11,6 +11,7 @@ let win;
...
@@ -11,6 +11,7 @@ let win;
let
deeplinkingData
;
let
deeplinkingData
;
let
deeplinkingView
;
let
deeplinkingView
;
// Force one instance of the app
const
gotTheLock
=
app
.
requestSingleInstanceLock
();
const
gotTheLock
=
app
.
requestSingleInstanceLock
();
if
(
!
gotTheLock
)
{
if
(
!
gotTheLock
)
{
app
.
quit
();
app
.
quit
();
...
@@ -52,9 +53,7 @@ function executeDeeplink(deeplink) {
...
@@ -52,9 +53,7 @@ function executeDeeplink(deeplink) {
}
}
}
}
// Setup Deeplinks
protocol
.
registerSchemesAsPrivileged
([{
scheme
:
'
app
'
,
privileges
:
{
secure
:
true
,
standard
:
true
}
}]);
protocol
.
registerSchemesAsPrivileged
([{
scheme
:
'
app
'
,
privileges
:
{
secure
:
true
,
standard
:
true
}
}]);
protocol
.
registerSchemesAsPrivileged
([{
scheme
:
'
app
'
,
privileges
:
{
secure
:
true
,
standard
:
true
}
}]);
protocol
.
registerSchemesAsPrivileged
([{
scheme
:
'
app
'
,
privileges
:
{
secure
:
true
,
standard
:
true
}
}]);
app
.
setAsDefaultProtocolClient
(
"
spinshare-song
"
);
app
.
setAsDefaultProtocolClient
(
"
spinshare-song
"
);
...
@@ -158,6 +157,7 @@ ipcMain.on("getDeeplink", (event) => {
...
@@ -158,6 +157,7 @@ ipcMain.on("getDeeplink", (event) => {
});
});
});
});
// Send a global event to close all overlays
ipcMain
.
on
(
"
overlays-close
"
,
()
=>
{
ipcMain
.
on
(
"
overlays-close
"
,
()
=>
{
win
.
webContents
.
send
(
"
overlays-close
"
);
win
.
webContents
.
send
(
"
overlays-close
"
);
});
});
...
@@ -165,10 +165,10 @@ ipcMain.on("overlays-close", () => {
...
@@ -165,10 +165,10 @@ ipcMain.on("overlays-close", () => {
function
download
(
url
,
fileName
,
cb
)
{
function
download
(
url
,
fileName
,
cb
)
{
let
dest
=
path
.
join
(
app
.
getPath
(
'
temp
'
),
fileName
+
"
.zip
"
);
let
dest
=
path
.
join
(
app
.
getPath
(
'
temp
'
),
fileName
+
"
.zip
"
);
let
file
=
fs
.
createWriteStream
(
dest
);
let
file
=
fs
.
createWriteStream
(
dest
);
var
partiallength
=
0
//sets partiallength to 0
let
partiallength
=
0
;
//
Replaced code double up
: https://stackoverflow.com/a/38465918
//
Adapter Switch for HTTP/HTTPS protocol
: https://stackoverflow.com/a/38465918
var
protocol
=
(
function
()
{
let
protocol
=
(
function
()
{
var
url
=
require
(
'
url
'
),
var
url
=
require
(
'
url
'
),
adapters
=
{
adapters
=
{
'
http:
'
:
http
,
'
http:
'
:
http
,
...
@@ -182,25 +182,31 @@ function download(url, fileName, cb) {
...
@@ -182,25 +182,31 @@ function download(url, fileName, cb) {
let
request
=
protocol
(
url
).
get
(
url
,
function
(
response
)
{
let
request
=
protocol
(
url
).
get
(
url
,
function
(
response
)
{
response
.
pipe
(
file
);
response
.
pipe
(
file
);
var
totallength
=
parseInt
(
response
.
headers
[
'
content-length
'
],
10
);
//sets totallength of file
// Figure out total length
let
totallength
=
parseInt
(
response
.
headers
[
'
content-length
'
],
10
);
// Add the length of the newly received chunk everytime we receive one
response
.
on
(
"
data
"
,
function
(
chunk
)
{
response
.
on
(
"
data
"
,
function
(
chunk
)
{
partiallength
+=
chunk
.
length
//adds each time
partiallength
+=
chunk
.
length
;
let
decimallength
=
partiallength
/
totallength
let
decimallength
=
partiallength
/
totallength
;
if
(
decimallength
!=
1
)
{
if
(
decimallength
!=
1
)
{
win
.
setProgressBar
(
decimallength
)
//sets progress bar to decimal
// Report back the progress
win
.
webContents
.
send
(
"
downloadProgress
"
,
decimallength
)
win
.
setProgressBar
(
decimallength
);
win
.
webContents
.
send
(
"
downloadProgress
"
,
decimallength
);
}
}
else
{
else
{
win
.
setProgressBar
(
0
)
//sets progress bar to blank when done
// Report back finished download
win
.
webContents
.
send
(
"
downloadProgress
"
,
0
)
win
.
setProgressBar
(
0
);
win
.
webContents
.
send
(
"
downloadProgress
"
,
0
);
}
}
});
});
// Call definied Callback on finish
file
.
on
(
'
finish
'
,
function
()
{
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
(
cb
(
null
,
dest
));
// async call of the callback
file
.
close
(
cb
(
null
,
dest
));
});
});
}).
on
(
'
error
'
,
function
(
err
)
{
// Handle errors
}).
on
(
'
error
'
,
function
(
err
)
{
fs
.
unlink
(
dest
);
// Delete the file async. (But we don't check the result)
fs
.
unlink
(
dest
);
if
(
cb
)
cb
(
err
.
message
,
dest
);
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