From 5861b49948e48f4d2fc2d95cbf889fc769bb38df Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 25 Jan 2019 17:12:34 +0100 Subject: [PATCH] wip #2303 @3 --- js/libs/fluidbook/fluidbook.js | 66 +++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 9e0e70c6..ec4a61dc 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -744,7 +744,7 @@ Fluidbook.prototype = { offset.left *= 2; offset.top *= 2; - if ($(e).data('ios-preview') == '1') { + if ($(e).data('ios-preview') === '1') { offset.top = offset.left = 0; } } catch (err) { @@ -773,31 +773,42 @@ Fluidbook.prototype = { if (this.datas.phonegap === 'android') { if (types_android[type] !== undefined) { + + var errorCallback = function (e) { + $this.bugreport(e); + $this.hideLoader(); + }; + console.log('open pdf file'); this.displayLoader(); - window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { - console.log('got local file system'); - console.log('try to resolve url'); - window.resolveLocalFileSystemURL(url, function (entry) { - console.log('resolved from file'); - window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) { - console.log('resolved to dir'); - entry.copyTo(dirEntry, 'document.pdf', function (copyEntry) { - console.log('copied file'); - window.plugins.webintent.startActivity({ - action: window.plugins.webintent.ACTION_VIEW, - type: types_android[type], - url: copyEntry.toURL() - }, function (args) { - $this.hideLoader(5); - }, function (args) { - $this.wopen(copyEntry.toURL(), '_blank', ''); - $this.hideLoader(5); - }); - }, lazy); - }, lazy); - }, lazy); - }, lazy); + try { + window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { + console.log('got local file system'); + console.log('try to resolve url'); + window.resolveLocalFileSystemURL(url, function (entry) { + console.log('resolved from file'); + window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) { + console.log('resolved to dir'); + entry.copyTo(dirEntry, entry.name, function (copyEntry) { + console.log('copied file'); + window.plugins.webintent.startActivity({ + action: window.plugins.webintent.ACTION_VIEW, + type: types_android[type], + url: copyEntry.toURL() + }, function (args) { + $this.hideLoader(5); + }, function (args) { + $this.wopen(copyEntry.toURL(), '_blank', ''); + $this.hideLoader(5); + }); + }, errorCallback); + }, errorCallback); + }, errorCallback); + }, errorCallback); + } catch (e) { + $this.bugreport(e); + $this.hideLoader(); + } } return true; } @@ -1000,4 +1011,11 @@ Fluidbook.prototype = { $this.flushNetworkQueue(); }, 100); }, + + bugreport: function (e) { + if (window.confirm('An error occured: ' + e.name + '. Do you want to send a report ?')) { + var subject = '[Fluidbook report] ' + e.message; + window.open('mailto:tech@fluidbook.com?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(JSON.stringify(e))); + } + }, } -- 2.39.5