-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
1 parent
252876c
commit 36ce8cf
Showing
15 changed files
with
210 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import StateMachine from 'awaited-dom/base/StateMachine'; | ||
import Resolvable from '@secret-agent/commons/Resolvable'; | ||
import IDownload from '@secret-agent/interfaces/IDownload'; | ||
import CoreTab from './CoreTab'; | ||
|
||
const { getState, setState } = StateMachine<Download, IState>(); | ||
|
||
interface IState { | ||
coreTab: Promise<CoreTab>; | ||
downloadPromise: Resolvable<void>; | ||
complete: boolean; | ||
} | ||
|
||
export default class Download { | ||
id: string; | ||
url: string; | ||
path: string; | ||
suggestedFilename: string; | ||
|
||
progress: number; | ||
totalBytes: number; | ||
canceled: boolean; | ||
|
||
get complete(): boolean { | ||
return getState(this).complete; | ||
} | ||
|
||
set complete(value) { | ||
setState(this, { complete: value }); | ||
if (value) getState(this).downloadPromise.resolve(); | ||
} | ||
|
||
waitForFinished(): Promise<void> { | ||
return getState(this).downloadPromise.promise; | ||
} | ||
|
||
async saveAs(): Promise<Buffer> { | ||
// todo: add streaming ability | ||
} | ||
} | ||
|
||
export function createDownload(coreTab: Promise<CoreTab>, data: IDownload): Download { | ||
const download = new Download(); | ||
Object.assign(download, data); | ||
setState(download, { | ||
coreTab, | ||
downloadPromise: new Resolvable<void>(), | ||
}); | ||
return download; | ||
} |
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,14 @@ | ||
export default interface IDownload { | ||
id: string; | ||
path: string; | ||
suggestedFilename: string; | ||
url: string; | ||
} | ||
|
||
export interface IDownloadState { | ||
id: string; | ||
totalBytes: number; | ||
complete: boolean; | ||
progress: number; | ||
canceled: boolean; | ||
} |
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
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
Oops, something went wrong.