-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make changes required for Desktop FS updates #1099
Merged
Merged
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fc9f993
Make changes required for Desktop FS updates
SleepyLeslie 701e187
Move DocStorageManager decorator to ICreate
SleepyLeslie 189f724
Rename docStorageManagerDecorator
SleepyLeslie 6eac878
Fix --no-nodemon in watch script
SleepyLeslie e5b5f23
Stub NewDocMethods
SleepyLeslie 9f60f25
Update gitignore
SleepyLeslie 7f7b18f
Make linter happy
SleepyLeslie e5b47d6
Move login system into ICreate
SleepyLeslie 9de01df
Make changes for the "Import Document" button
SleepyLeslie fd4f048
Expose gristHomeModel to window
SleepyLeslie 60f0442
Fix linting issues
SleepyLeslie a6fbe65
Merge branch 'main' into sleepyleslie/nativefs
SleepyLeslie 9950120
Merge branch 'main' into sleepyleslie/nativefs
SleepyLeslie 449a53b
Fix server tests
SleepyLeslie 6fa0857
Fixes testing hooks registering too early
Spoffy 2f84093
Make new stubs actual simple stubs
SleepyLeslie 9fbbdc3
Replaces decorateDocStorageManager in ICreate
Spoffy afcb3de
Removes window.gristHomeModel
Spoffy 87d1d0a
Merge branch 'main' into sleepyleslie/nativefs
Spoffy 9d53e30
Adds missing semicolon
Spoffy 0030a82
Fixes tests using mergedServerMain
Spoffy 947170d
Merge branch 'main' into sleepyleslie/nativefs
Spoffy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {IProgress} from 'app/client/models/NotifyModel'; | ||
import {Disposable} from 'grainjs'; | ||
|
||
export class ImportProgress extends Disposable { | ||
// Import does upload first, then import. We show a single indicator, estimating which fraction | ||
// of the time should be given to upload (whose progress we can report well), and which to the | ||
// subsequent import (whose progress indicator is mostly faked). | ||
private _uploadFraction: number; | ||
private _estImportSeconds: number; | ||
|
||
private _importTimer: null | ReturnType<typeof setInterval> = null; | ||
private _importStart: number = 0; | ||
|
||
constructor(private _progressUI: IProgress, file: File) { | ||
super(); | ||
// We'll assume that for .grist files, the upload takes 90% of the total time, and for other | ||
// files, 40%. | ||
this._uploadFraction = file.name.endsWith(".grist") ? 0.9 : 0.4; | ||
|
||
// TODO: Import step should include a progress callback, to be combined with upload progress. | ||
// Without it, we estimate import to take 2s per MB (non-scientific unreliable estimate), and | ||
// use an asymptotic indicator which keeps moving without ever finishing. Not terribly useful, | ||
// but does slow down for larger files, and is more comforting than a stuck indicator. | ||
this._estImportSeconds = file.size / 1024 / 1024 * 2; | ||
|
||
this._progressUI.setProgress(0); | ||
this.onDispose(() => this._importTimer && clearInterval(this._importTimer)); | ||
} | ||
|
||
// Once this reaches 100, the import stage begins. | ||
public setUploadProgress(percentage: number) { | ||
this._progressUI.setProgress(percentage * this._uploadFraction); | ||
if (percentage >= 100 && !this._importTimer) { | ||
this._importStart = Date.now(); | ||
this._importTimer = setInterval(() => this._onImportTimer(), 100); | ||
} | ||
} | ||
|
||
public finish() { | ||
if (this._importTimer) { | ||
clearInterval(this._importTimer); | ||
} | ||
this._progressUI.setProgress(100); | ||
} | ||
|
||
/** | ||
* Calls _progressUI.setProgress(percent) with percentage increasing from 0 and asymptotically | ||
* approaching 100, reaching 50% after estSeconds. It's intended to look reasonable when the | ||
* estimate is good, and to keep showing slowing progress even if it's not. | ||
*/ | ||
private _onImportTimer() { | ||
const elapsedSeconds = (Date.now() - this._importStart) / 1000; | ||
const importProgress = elapsedSeconds / (elapsedSeconds + this._estImportSeconds); | ||
const progress = this._uploadFraction + importProgress * (1 - this._uploadFraction); | ||
this._progressUI.setProgress(100 * progress); | ||
} | ||
} | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we can remove this by using
window.gristApp
instead.