Browse Source

Fixed download files in Safari

master
Igor Zhukov 10 years ago
parent
commit
057a36c3ba
  1. 17
      app/js/lib/ng_utils.js
  2. 25
      app/js/services.js

17
app/js/lib/ng_utils.js

@ -260,7 +260,18 @@ angular.module('izhukov.utils', []) @@ -260,7 +260,18 @@ angular.module('izhukov.utils', [])
return;
}
var popup = false;
if (window.safari) {
popup = window.open();
}
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');
anchor.href = url;
anchor.target = '_blank';
@ -318,11 +329,11 @@ angular.module('izhukov.utils', []) @@ -318,11 +329,11 @@ angular.module('izhukov.utils', [])
var storageIsAvailable = $window.indexedDB !== 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 &&
navigator.userAgent.indexOf('Safari') != -1 &&
navigator.userAgent.indexOf('Chrome') == -1 &&
navigator.userAgent.match(/Version\/([67]|8.0.[012])/)
navigator.userAgent.indexOf('Chrome') == -1
// && navigator.userAgent.match(/Version\/([67]|8.0.[012])/)
) {
storageIsAvailable = false;
}

25
app/js/services.js

@ -2584,6 +2584,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2584,6 +2584,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
});
}
}, function () {
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
if (cachedBlob) {
return FileManager.download(cachedBlob, mimeType, fileName);
}
MtpApiFileManager.downloadFile(
fullPhotoSize.location.dc_id, inputFileLocation, fullPhotoSize.size, {mime: mimeType}
).then(function (blob) {
@ -2803,7 +2808,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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 = {},
docsForHistory = {},
windowW = $(window).width(),
@ -2918,8 +2923,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2918,8 +2923,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
access_hash: doc.access_hash
};
// historyDoc.progress = {enabled: true, percent: 10, total: doc.size};
if (historyDoc.downloaded === undefined) {
MtpApiFileManager.getDownloadedFile(inputFileLocation, doc.size).then(function () {
historyDoc.downloaded = true;
@ -2938,6 +2941,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2938,6 +2941,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
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};
var downloadPromise = MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, {
@ -3011,7 +3021,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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 audiosForHistory = {};
@ -3059,6 +3069,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -3059,6 +3069,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
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};
var downloadPromise = MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, {

Loading…
Cancel
Save