]> _ Git - fluidbook-html5.git/commitdiff
wip #2303 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 25 Jan 2019 16:12:34 +0000 (17:12 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 25 Jan 2019 16:12:34 +0000 (17:12 +0100)
js/libs/fluidbook/fluidbook.js

index 9e0e70c6c11a7a5691187c54b61ab82ff5f2d265..ec4a61dcc80c1939b2889c6c051850bce0f16be6 100644 (file)
@@ -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)));
+        }
+    },
 }