This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
|
||
class MailboxesDownloadManager { | ||
|
||
/* ****************************************************************************/ | ||
// Lifecycle | ||
/* ****************************************************************************/ | ||
|
||
constructor (mailboxWindow) { | ||
this.inProgress = { } | ||
this.mailboxWindow = mailboxWindow | ||
} | ||
|
||
/* ****************************************************************************/ | ||
// App | ||
/* ****************************************************************************/ | ||
|
||
/** | ||
* Updates the progress bar in the dock | ||
*/ | ||
updateProgressBar () { | ||
const all = Object.keys(this.inProgress).reduce((acc, id) => { | ||
acc.received += this.inProgress[id].received | ||
acc.total += this.inProgress[id].total | ||
return acc | ||
}, { received: 0, total: 0 }) | ||
|
||
if (all.received === 0 && all.total === 0) { | ||
this.mailboxWindow.setProgressBar(-1) | ||
} else { | ||
this.mailboxWindow.setProgressBar(all.received / all.total) | ||
} | ||
} | ||
|
||
/* ****************************************************************************/ | ||
// Updates | ||
/* ****************************************************************************/ | ||
|
||
/** | ||
* Updates the progress on a download | ||
* @param id: the download id | ||
* @param received: the bytes received | ||
* @param total: the total bytes to download | ||
*/ | ||
updateProgress (id, received, total) { | ||
this.inProgress[id] = this.inProgress[id] || {} | ||
this.inProgress[id].received = received | ||
this.inProgress[id].total = total | ||
this.updateProgressBar() | ||
} | ||
|
||
/** | ||
* Indicates that a download has finished | ||
* @param id: the download id | ||
*/ | ||
downloadFinished (id) { | ||
delete this.inProgress[id] | ||
this.updateProgressBar() | ||
} | ||
} | ||
|
||
module.exports = MailboxesDownloadManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters