diff --git a/app/capabilities.js b/app/capabilities.js index 3939fea2..33b9daf8 100644 --- a/app/capabilities.js +++ b/app/capabilities.js @@ -90,6 +90,7 @@ export default async function getCapabilities() { } catch (e) { account = false; } + const share = !!navigator.share; return { account, @@ -98,6 +99,7 @@ export default async function getCapabilities() { streamUpload: nativeStreams || polyStreams, streamDownload: nativeStreams && serviceWorker && browserName() !== 'safari', - multifile: nativeStreams || polyStreams + multifile: nativeStreams || polyStreams, + share }; } diff --git a/app/controller.js b/app/controller.js index 31117834..47ec3ecc 100644 --- a/app/controller.js +++ b/app/controller.js @@ -5,6 +5,7 @@ import * as metrics from './metrics'; import { bytes } from './utils'; import okDialog from './ui/okDialog'; import copyDialog from './ui/copyDialog'; +import shareDialog from './ui/shareDialog'; import signupDialog from './ui/signupDialog'; export default function(state, emitter) { @@ -168,7 +169,9 @@ export default function(state, emitter) { file: ownedFile }); } - state.modal = copyDialog(ownedFile.name, ownedFile.url); + state.modal = state.capabilities.share + ? shareDialog(ownedFile.name, ownedFile.url) + : copyDialog(ownedFile.name, ownedFile.url); } catch (err) { if (err.message === '0') { //cancelled. do nothing diff --git a/app/ui/shareDialog.js b/app/ui/shareDialog.js new file mode 100644 index 00000000..6cd3acfb --- /dev/null +++ b/app/ui/shareDialog.js @@ -0,0 +1,61 @@ +const html = require('choo/html'); + +/* Possible strings for l10n +shareLinkDescription = Share the link to your file: +shareLinkButton = Share link +shareMessage = Download { $name } with { -send-brand }: simple, safe file sharing + */ + +module.exports = function(name, url) { + return function(state, emit, close) { + return html` + +

+ ${state.translate('notifyUploadEncryptDone')} +

+

+ Share the link to your file:
+ ${name} +

+ + + +
+ `; + + async function share(event) { + event.stopPropagation(); + try { + await navigator.share({ + title: state.translate('-send-brand'), + text: `Download ${name} with Firefox Send: simple, safe file sharing`, + //state.translate('shareMessage', { name }), + url + }); + } catch (e) { + console.error(e); + } + setTimeout(close, 1000); + } + }; +};