A platform for community discussion. Free, open, simple.
FIX: more reliable native sharing (#7039)
Joffrey JAFFEUX18296b421177
diff --git a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6index b538e0453e1..54ef5e59f77 100644--- a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6+++ b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6@@ -6,34 +6,6 @@ export default {name: "topic-footer-buttons",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",@@ -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.es6index 5fdbe63f281..f44665af3d8 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.es6index 7710e75fede..0ec09d86b0e 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);}});