Fixed download files in Safari
This commit is contained in:
parent
1c48235c53
commit
057a36c3ba
@ -260,7 +260,18 @@ angular.module('izhukov.utils', [])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var popup = false;
|
||||||
|
if (window.safari) {
|
||||||
|
popup = window.open();
|
||||||
|
}
|
||||||
|
|
||||||
getFileCorrectUrl(blob, mimeType).then(function (url) {
|
getFileCorrectUrl(blob, mimeType).then(function (url) {
|
||||||
|
if (popup) {
|
||||||
|
try {
|
||||||
|
popup.location.href = url;
|
||||||
|
return;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
var anchor = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
|
var anchor = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
|
||||||
anchor.href = url;
|
anchor.href = url;
|
||||||
anchor.target = '_blank';
|
anchor.target = '_blank';
|
||||||
@ -318,11 +329,11 @@ angular.module('izhukov.utils', [])
|
|||||||
var storageIsAvailable = $window.indexedDB !== undefined &&
|
var storageIsAvailable = $window.indexedDB !== undefined &&
|
||||||
$window.IDBTransaction !== undefined;
|
$window.IDBTransaction !== undefined;
|
||||||
|
|
||||||
// IndexedDB was REALLY slow till Safari 8.0.3, no point in it
|
// IndexedDB is REALLY slow without blob support in Safari 8, no point in it
|
||||||
if (storageIsAvailable &&
|
if (storageIsAvailable &&
|
||||||
navigator.userAgent.indexOf('Safari') != -1 &&
|
navigator.userAgent.indexOf('Safari') != -1 &&
|
||||||
navigator.userAgent.indexOf('Chrome') == -1 &&
|
navigator.userAgent.indexOf('Chrome') == -1
|
||||||
navigator.userAgent.match(/Version\/([67]|8.0.[012])/)
|
// && navigator.userAgent.match(/Version\/([67]|8.0.[012])/)
|
||||||
) {
|
) {
|
||||||
storageIsAvailable = false;
|
storageIsAvailable = false;
|
||||||
}
|
}
|
||||||
|
@ -2584,6 +2584,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function () {
|
}, function () {
|
||||||
|
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
|
||||||
|
if (cachedBlob) {
|
||||||
|
return FileManager.download(cachedBlob, mimeType, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
MtpApiFileManager.downloadFile(
|
MtpApiFileManager.downloadFile(
|
||||||
fullPhotoSize.location.dc_id, inputFileLocation, fullPhotoSize.size, {mime: mimeType}
|
fullPhotoSize.location.dc_id, inputFileLocation, fullPhotoSize.size, {mime: mimeType}
|
||||||
).then(function (blob) {
|
).then(function (blob) {
|
||||||
@ -2803,7 +2808,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
.service('AppDocsManager', function ($sce, $rootScope, $modal, $window, $q, RichTextProcessor, MtpApiFileManager, FileManager) {
|
.service('AppDocsManager', function ($sce, $rootScope, $modal, $window, $q, RichTextProcessor, MtpApiFileManager, FileManager, qSync) {
|
||||||
var docs = {},
|
var docs = {},
|
||||||
docsForHistory = {},
|
docsForHistory = {},
|
||||||
windowW = $(window).width(),
|
windowW = $(window).width(),
|
||||||
@ -2918,8 +2923,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
access_hash: doc.access_hash
|
access_hash: doc.access_hash
|
||||||
};
|
};
|
||||||
|
|
||||||
// historyDoc.progress = {enabled: true, percent: 10, total: doc.size};
|
|
||||||
|
|
||||||
if (historyDoc.downloaded === undefined) {
|
if (historyDoc.downloaded === undefined) {
|
||||||
MtpApiFileManager.getDownloadedFile(inputFileLocation, doc.size).then(function () {
|
MtpApiFileManager.getDownloadedFile(inputFileLocation, doc.size).then(function () {
|
||||||
historyDoc.downloaded = true;
|
historyDoc.downloaded = true;
|
||||||
@ -2938,6 +2941,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
access_hash: doc.access_hash
|
access_hash: doc.access_hash
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (historyDoc.downloaded && !toFileEntry) {
|
||||||
|
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
|
||||||
|
if (cachedBlob) {
|
||||||
|
return qSync.when(cachedBlob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
historyDoc.progress = {enabled: !historyDoc.downloaded, percent: 1, total: doc.size};
|
historyDoc.progress = {enabled: !historyDoc.downloaded, percent: 1, total: doc.size};
|
||||||
|
|
||||||
var downloadPromise = MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, {
|
var downloadPromise = MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, {
|
||||||
@ -3011,7 +3021,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
.service('AppAudioManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, FileManager) {
|
.service('AppAudioManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, FileManager, qSync) {
|
||||||
var audios = {};
|
var audios = {};
|
||||||
var audiosForHistory = {};
|
var audiosForHistory = {};
|
||||||
|
|
||||||
@ -3059,6 +3069,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
access_hash: audio.access_hash
|
access_hash: audio.access_hash
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (historyAudio.downloaded && !toFileEntry) {
|
||||||
|
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
|
||||||
|
if (cachedBlob) {
|
||||||
|
return qSync.when(cachedBlob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
historyAudio.progress = {enabled: !historyAudio.downloaded, percent: 1, total: audio.size};
|
historyAudio.progress = {enabled: !historyAudio.downloaded, percent: 1, total: audio.size};
|
||||||
|
|
||||||
var downloadPromise = MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, {
|
var downloadPromise = MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user