Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
added share to tile
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Mar 10, 2019
1 parent edc95f4 commit bd61d2f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
5 changes: 3 additions & 2 deletions app/capabilities.js
@@ -1,4 +1,4 @@
/* global AUTH_CONFIG */
/* global AUTH_CONFIG LOCALE */
import { browserName } from './utils';

async function checkCrypto() {
Expand Down Expand Up @@ -90,7 +90,8 @@ export default async function getCapabilities() {
} catch (e) {
account = false;
}
const share = !!navigator.share;
const share =
typeof navigator.share === 'function' && LOCALE.startsWith('en'); // en until strings merge

return {
account,
Expand Down
39 changes: 27 additions & 12 deletions app/ui/archiveTile.js
Expand Up @@ -167,24 +167,24 @@ function archiveDetails(translate, archive) {

module.exports = function(state, emit, archive) {
const copyOrShare =
platform() !== 'android'
state.capabilities.share || platform() === 'android'
? html`
<button
class="text-blue-dark hover:text-blue-darker focus:text-blue-darker focus:outline self-end flex items-center"
onclick=${copy}
title="${state.translate('copyLinkButton')}"
class="text-blue-dark hover:text-blue-darker focus:text-blue-darker self-end flex items-end"
onclick=${share}
title="Share"
>
<img src="${assets.get('copy-16.svg')}" class="mr-2" />
${state.translate('copyLinkButton')}
<img src="${assets.get('share-24.svg')}" class="mr-2" />Share
</button>
`
: html`
<button
class="text-blue-dark hover:text-blue-darker focus:text-blue-darker self-end flex items-center"
onclick=${share}
title="Share"
class="text-blue-dark hover:text-blue-darker focus:text-blue-darker focus:outline self-end flex items-center"
onclick=${copy}
title="${state.translate('copyLinkButton')}"
>
<img src="${assets.get('share-24.svg')}" class="mr-2" /> Share
<img src="${assets.get('copy-16.svg')}" class="mr-2" />
${state.translate('copyLinkButton')}
</button>
`;
const dl =
Expand Down Expand Up @@ -248,9 +248,24 @@ module.exports = function(state, emit, archive) {
emit('delete', archive);
}

function share(event) {
async function share(event) {
event.stopPropagation();
Android.shareUrl(archive.url);
if (state.capabilities.share) {
try {
await navigator.share({
title: state.translate('-send-brand'),
text: `Download "${
archive.name
}" with Firefox Send: simple, safe file sharing`,
//state.translate('shareMessage', { name }),
url: archive.url
});
} catch (e) {
// ignore
}
} else {
Android.shareUrl(archive.url);
}
}
};

Expand Down
9 changes: 6 additions & 3 deletions app/ui/shareDialog.js
Expand Up @@ -3,7 +3,7 @@ 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
shareMessage = Download "{ $name }" with { -send-brand }: simple, safe file sharing
*/

module.exports = function(name, url) {
Expand Down Expand Up @@ -48,14 +48,17 @@ module.exports = function(name, url) {
try {
await navigator.share({
title: state.translate('-send-brand'),
text: `Download ${name} with Firefox Send: simple, safe file sharing`,
text: `Download "${name}" with Firefox Send: simple, safe file sharing`,
//state.translate('shareMessage', { name }),
url
});
} catch (e) {
if (e.code === e.ABORT_ERR) {
return;
}
console.error(e);
}
setTimeout(close, 1000);
close();
}
};
};
2 changes: 1 addition & 1 deletion assets/share-24.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bd61d2f

Please sign in to comment.