mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: more reliable native sharing (#7039)
This commit is contained in:
parent
9618300d69
commit
18296b4211
@ -6,34 +6,6 @@ export default {
|
|||||||
name: "topic-footer-buttons",
|
name: "topic-footer-buttons",
|
||||||
|
|
||||||
initialize() {
|
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({
|
registerTopicFooterButton({
|
||||||
id: "share-and-invite",
|
id: "share-and-invite",
|
||||||
icon: "link",
|
icon: "link",
|
||||||
@ -79,13 +51,7 @@ export default {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.navigator.share) {
|
nativeShare({ url: this.get("topic.shareUrl") }).then(null, modal);
|
||||||
window.navigator
|
|
||||||
.share({ url: this.get("topic.shareUrl") })
|
|
||||||
.catch(() => modal());
|
|
||||||
} else {
|
|
||||||
modal();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dropdown() {
|
dropdown() {
|
||||||
return this.site.mobileView;
|
return this.site.mobileView;
|
||||||
@ -98,10 +64,7 @@ export default {
|
|||||||
"inviteDisabled",
|
"inviteDisabled",
|
||||||
"isPM",
|
"isPM",
|
||||||
"invitingToTopic"
|
"invitingToTopic"
|
||||||
],
|
]
|
||||||
displayed() {
|
|
||||||
return !(this.site.mobileView && window.navigator.share);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerTopicFooterButton({
|
registerTopicFooterButton({
|
||||||
|
@ -6,8 +6,14 @@ export function nativeShare(data) {
|
|||||||
) {
|
) {
|
||||||
window.navigator
|
window.navigator
|
||||||
.share(data)
|
.share(data)
|
||||||
.catch(reject)
|
.then(resolve)
|
||||||
.then(resolve);
|
.catch(e => {
|
||||||
|
if (e.message === "Share canceled") {
|
||||||
|
// closing share panel do nothing
|
||||||
|
} else {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
@ -280,9 +280,7 @@ createWidget("post-date", {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// use native webshare when available
|
nativeShare({ url: this.attrs.shareUrl }).then(null, modalFallback);
|
||||||
// navigator.share needs HTTPS, returns undefined on HTTP
|
|
||||||
nativeShare({ url: this.attrs.shareUrl }).catch(modalFallback);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user