Perform a last minute backup when closing the last window

This commit is contained in:
Daniel Imms
2016-10-13 02:30:33 -07:00
parent e4f0dec794
commit 52c8af5abf
5 changed files with 75 additions and 6 deletions

View File

@@ -193,10 +193,18 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
this.fileService.discardBackup(this.resource);
}
private doBackup(): TPromise<void> {
public backup(): TPromise<void> {
return this.doBackup(true);
}
private doBackup(immediate?: boolean): TPromise<void> {
// Cancel any currently running backups to make this the one that succeeds
this.cancelBackupPromises();
if (immediate) {
return this.fileService.backupFile(this.resource, this.getValue()).then(f => void 0);
}
// Create new backup promise and keep it
const promise = TPromise.timeout(1000).then(() => {
this.fileService.backupFile(this.resource, this.getValue()); // Very important here to not return the promise because if the timeout promise is canceled it will bubble up the error otherwise - do not change