|
@@ -312,24 +312,18 @@ export class FileBrowserModel implements IDisposable {
|
|
|
* @returns A promise which resolves when the file has begun
|
|
|
* downloading.
|
|
|
*/
|
|
|
- download(path: string): Promise<void> {
|
|
|
- return this.manager.services.contents.getDownloadUrl(path).then(url => {
|
|
|
- // Check the browser is Chrome https://stackoverflow.com/a/9851769
|
|
|
- const chrome = (window as any).chrome;
|
|
|
- const isChrome = !!chrome && (!!chrome.webstore || !!chrome.runtime);
|
|
|
- if (isChrome) {
|
|
|
- // Workaround https://bugs.chromium.org/p/chromium/issues/detail?id=455987
|
|
|
- window.open(url);
|
|
|
- } else {
|
|
|
- let element = document.createElement('a');
|
|
|
- document.body.appendChild(element);
|
|
|
- element.setAttribute('href', url);
|
|
|
- element.setAttribute('download', '');
|
|
|
- element.click();
|
|
|
- document.body.removeChild(element);
|
|
|
- return void 0;
|
|
|
- }
|
|
|
- });
|
|
|
+ async download(path: string): Promise<void> {
|
|
|
+ const url = await this.manager.services.contents.getDownloadUrl(path);
|
|
|
+ let element = document.createElement('a');
|
|
|
+ document.body.appendChild(element);
|
|
|
+ element.setAttribute('href', url);
|
|
|
+ // Chrome doesn't get the right name automatically
|
|
|
+ const parts = path.split('/');
|
|
|
+ const name = parts[parts.length - 1];
|
|
|
+ element.setAttribute('download', name);
|
|
|
+ element.click();
|
|
|
+ document.body.removeChild(element);
|
|
|
+ return void 0;
|
|
|
}
|
|
|
|
|
|
/**
|