FIX: more reliable native sharing (#7039)

FIX: more reliable native sharing (#7039)

diff --git a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
index b538e04..54ef5e5 100644
--- a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
+++ b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
@@ -7,34 +7,6 @@ export default {
 
   initialize() {
     registerTopicFooterButton({
-      id: "native-share",
-      icon: "link",
-      priority: 999,
-      label: "topic.share.title",
-      title: "topic.share.help",
-      action() {
-        nativeShare({ url: this.get("topic.shareUrl") }).catch(() =>
-          showModal("share-and-invite", {
-            modalClass: "share-and-invite",
-            panels: [
-              {
-                id: "share",
-                title: "topic.share.title",
-                model: { topic: this.get("topic") }
-              }
-            ]
-          })
-        );
-      },
-      dropdown: true,
-      classNames: ["native-share"],
-      dependentKeys: ["topic.shareUrl", "topic.isPrivateMessage"],
-      displayed() {
-        return window.navigator.share;
-      }
-    });
-
-    registerTopicFooterButton({
       id: "share-and-invite",
       icon: "link",
       priority: 999,
@@ -79,13 +51,7 @@ export default {
           });
         };
 
-        if (window.navigator.share) {
-          window.navigator
-            .share({ url: this.get("topic.shareUrl") })
-            .catch(() => modal());
-        } else {
-          modal();
-        }
+        nativeShare({ url: this.get("topic.shareUrl") }).then(null, modal);
       },
       dropdown() {
         return this.site.mobileView;
@@ -98,10 +64,7 @@ export default {
         "inviteDisabled",
         "isPM",
         "invitingToTopic"
-      ],
-      displayed() {
-        return !(this.site.mobileView && window.navigator.share);
-      }
+      ]
     });
 
     registerTopicFooterButton({
diff --git a/app/assets/javascripts/discourse/lib/pwa-utils.js.es6 b/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
index 5fdbe63..f44665a 100644
--- a/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
+++ b/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
@@ -6,8 +6,14 @@ export function nativeShare(data) {
     ) {
       window.navigator
         .share(data)
-        .catch(reject)
-        .then(resolve);
+        .then(resolve)
+        .catch(e => {
+          if (e.message === "Share canceled") {
+            // closing share panel do nothing
+          } else {
+            reject();
+          }
+        });
     } else {
       reject();
     }
diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6
index 7710e75..0ec09d8 100644
--- a/app/assets/javascripts/discourse/widgets/post.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post.js.es6
@@ -280,9 +280,7 @@ createWidget("post-date", {
       });
     };
 
-    // use native webshare when available
-    // navigator.share needs HTTPS, returns undefined on HTTP
-    nativeShare({ url: this.attrs.shareUrl }).catch(modalFallback);
+    nativeShare({ url: this.attrs.shareUrl }).then(null, modalFallback);
   }
 });

GitHub sha: 18296b42