Implement click on QR-code to copy room or pair link (#174)

This commit is contained in:
schlagmichdoch 2023-10-11 20:19:19 +02:00
parent a32b310bf0
commit bb1468fa42
8 changed files with 76 additions and 20 deletions

View file

@ -223,7 +223,7 @@
</div> </div>
<div class="row center"> <div class="row center">
<div class="column"> <div class="column">
<div class="center key-qr-code"></div> <div class="center key-qr-code" data-i18n-key="dialogs.pair-devices-qr-code" data-i18n-attrs="title"></div>
<h1 class="center key" dir="ltr">000 000</h1> <h1 class="center key" dir="ltr">000 000</h1>
<p class="center text-center key-instructions"> <p class="center text-center key-instructions">
<span class="font-subheading" data-i18n-key="dialogs.input-key-on-this-device" data-i18n-attrs="text"></span> <span class="font-subheading" data-i18n-key="dialogs.input-key-on-this-device" data-i18n-attrs="text"></span>
@ -293,7 +293,7 @@
</div> </div>
<div class="row center"> <div class="row center">
<div class="column"> <div class="column">
<div class="center key-qr-code"></div> <div class="center key-qr-code" data-i18n-key="dialogs.public-room-qr-code" data-i18n-attrs="title"></div>
<h1 class="center key" dir="ltr"></h1> <h1 class="center key" dir="ltr"></h1>
<p class="center text-center key-instructions"> <p class="center text-center key-instructions">
<span class="font-subheading" data-i18n-key="dialogs.input-room-id-on-another-device" data-i18n-attrs="text"></span> <span class="font-subheading" data-i18n-key="dialogs.input-room-id-on-another-device" data-i18n-attrs="text"></span>

View file

@ -90,7 +90,9 @@
"receive-title": "{{descriptor}} Received", "receive-title": "{{descriptor}} Received",
"download-again": "Download again", "download-again": "Download again",
"language-selector-title": "Set Language", "language-selector-title": "Set Language",
"system-language": "System Language" "system-language": "System Language",
"public-room-qr-code_title": "Click to copy link to public room",
"pair-devices-qr-code_title": "Click to copy link to pair this device"
}, },
"about": { "about": {
"close-about_aria-label": "Close About PairDrop", "close-about_aria-label": "Close About PairDrop",
@ -114,6 +116,8 @@
"public-room-id-invalid": "Invalid room ID", "public-room-id-invalid": "Invalid room ID",
"public-room-left": "Left public room {{publicRoomId}}", "public-room-left": "Left public room {{publicRoomId}}",
"copied-to-clipboard": "Copied to clipboard", "copied-to-clipboard": "Copied to clipboard",
"pair-url-copied-to-clipboard": "Link to pair this device copied to clipboard",
"room-url-copied-to-clipboard": "Link to public room copied to clipboard",
"copied-to-clipboard-error": "Copying not possible. Copy manually.", "copied-to-clipboard-error": "Copying not possible. Copy manually.",
"text-content-incorrect": "Text content is incorrect.", "text-content-incorrect": "Text content is incorrect.",
"file-content-incorrect": "File content is incorrect.", "file-content-incorrect": "File content is incorrect.",

View file

@ -1215,6 +1215,7 @@ class PairDeviceDialog extends Dialog {
Events.on('evaluate-number-room-secrets', _ => this._evaluateNumberRoomSecrets()) Events.on('evaluate-number-room-secrets', _ => this._evaluateNumberRoomSecrets())
Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail)); Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail));
this.$el.addEventListener('paste', e => this._onPaste(e)); this.$el.addEventListener('paste', e => this._onPaste(e));
this.$qrCode.addEventListener('click', _ => this._copyPairUrl());
this.evaluateUrlAttributes(); this.evaluateUrlAttributes();
@ -1255,7 +1256,7 @@ class PairDeviceDialog extends Dialog {
this.$key.innerText = `${this.pairKey.substring(0,3)} ${this.pairKey.substring(3,6)}` this.$key.innerText = `${this.pairKey.substring(0,3)} ${this.pairKey.substring(3,6)}`
// Display the QR code for the url // Display the QR code for the url
const qr = new QRCode({ const qr = new QRCode({
content: this._getPairURL(), content: this._getPairUrl(),
width: 150, width: 150,
height: 150, height: 150,
padding: 0, padding: 0,
@ -1269,12 +1270,22 @@ class PairDeviceDialog extends Dialog {
this.show(); this.show();
} }
_getPairURL() { _getPairUrl() {
let url = new URL(location.href); let url = new URL(location.href);
url.searchParams.append('pair_key', this.pairKey) url.searchParams.append('pair_key', this.pairKey)
return url.href; return url.href;
} }
_copyPairUrl() {
navigator.clipboard.writeText(this._getPairUrl())
.then(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.pair-url-copied-to-clipboard"));
})
.catch(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.copied-to-clipboard-error"));
})
}
_onSubmit(e) { _onSubmit(e) {
e.preventDefault(); e.preventDefault();
this._submit(); this._submit();
@ -1546,6 +1557,7 @@ class PublicRoomDialog extends Dialog {
Events.on('public-room-id-invalid', e => this._onPublicRoomIdInvalid(e.detail)); Events.on('public-room-id-invalid', e => this._onPublicRoomIdInvalid(e.detail));
Events.on('public-room-left', _ => this._onPublicRoomLeft()); Events.on('public-room-left', _ => this._onPublicRoomLeft());
this.$el.addEventListener('paste', e => this._onPaste(e)); this.$el.addEventListener('paste', e => this._onPaste(e));
this.$qrCode.addEventListener('click', _ => this._copyShareRoomUrl());
this.evaluateUrlAttributes(); this.evaluateUrlAttributes();
@ -1594,7 +1606,7 @@ class PublicRoomDialog extends Dialog {
// Display the QR code for the url // Display the QR code for the url
const qr = new QRCode({ const qr = new QRCode({
content: this._getShareRoomURL(), content: this._getShareRoomUrl(),
width: 150, width: 150,
height: 150, height: 150,
padding: 0, padding: 0,
@ -1619,16 +1631,26 @@ class PublicRoomDialog extends Dialog {
Events.fire('evaluate-footer-badges'); Events.fire('evaluate-footer-badges');
} }
_getShareRoomURL() { _getShareRoomUrl() {
let url = new URL(location.href); let url = new URL(location.href);
url.searchParams.append('room_key', this.roomId) url.searchParams.append('room_id', this.roomId)
return url.href; return url.href;
} }
_copyShareRoomUrl() {
navigator.clipboard.writeText(this._getShareRoomUrl())
.then(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.room-url-copied-to-clipboard"));
})
.catch(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.copied-to-clipboard-error"));
})
}
evaluateUrlAttributes() { evaluateUrlAttributes() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('room_key')) { if (urlParams.has('room_id')) {
this._joinPublicRoom(urlParams.get('room_key')); this._joinPublicRoom(urlParams.get('room_id'));
const url = getUrlWithoutArguments(); const url = getUrlWithoutArguments();
window.history.replaceState({}, "Rewrite URL", url); //remove pair_key from url window.history.replaceState({}, "Rewrite URL", url); //remove pair_key from url
} }

View file

@ -831,6 +831,8 @@ x-dialog a {
.key-qr-code { .key-qr-code {
margin: 16px; margin: 16px;
width: fit-content;
align-self: center;
} }
.key-instructions { .key-instructions {

View file

@ -228,7 +228,7 @@
</div> </div>
<div class="row center"> <div class="row center">
<div class="column"> <div class="column">
<div class="center key-qr-code"></div> <div class="center key-qr-code" data-i18n-key="dialogs.pair-devices-qr-code" data-i18n-attrs="title"></div>
<h1 class="center key" dir="ltr">000 000</h1> <h1 class="center key" dir="ltr">000 000</h1>
<p class="center text-center key-instructions"> <p class="center text-center key-instructions">
<span class="font-subheading" data-i18n-key="dialogs.input-key-on-this-device" data-i18n-attrs="text"></span> <span class="font-subheading" data-i18n-key="dialogs.input-key-on-this-device" data-i18n-attrs="text"></span>
@ -298,7 +298,7 @@
</div> </div>
<div class="row center"> <div class="row center">
<div class="column"> <div class="column">
<div class="center key-qr-code"></div> <div class="center key-qr-code" data-i18n-key="dialogs.public-room-qr-code" data-i18n-attrs="title"></div>
<h1 class="center key" dir="ltr"></h1> <h1 class="center key" dir="ltr"></h1>
<p class="center text-center key-instructions"> <p class="center text-center key-instructions">
<span class="font-subheading" data-i18n-key="dialogs.input-room-id-on-another-device" data-i18n-attrs="text"></span> <span class="font-subheading" data-i18n-key="dialogs.input-room-id-on-another-device" data-i18n-attrs="text"></span>

View file

@ -90,7 +90,9 @@
"receive-title": "{{descriptor}} Received", "receive-title": "{{descriptor}} Received",
"download-again": "Download again", "download-again": "Download again",
"language-selector-title": "Set Language", "language-selector-title": "Set Language",
"system-language": "System Language" "system-language": "System Language",
"public-room-qr-code_title": "Click to copy link to public room",
"pair-devices-qr-code_title": "Click to copy link to pair this device"
}, },
"about": { "about": {
"close-about_aria-label": "Close About PairDrop", "close-about_aria-label": "Close About PairDrop",
@ -114,6 +116,8 @@
"public-room-id-invalid": "Invalid room ID", "public-room-id-invalid": "Invalid room ID",
"public-room-left": "Left public room {{publicRoomId}}", "public-room-left": "Left public room {{publicRoomId}}",
"copied-to-clipboard": "Copied to clipboard", "copied-to-clipboard": "Copied to clipboard",
"pair-url-copied-to-clipboard": "Link to pair this device copied to clipboard",
"room-url-copied-to-clipboard": "Link to public room copied to clipboard",
"copied-to-clipboard-error": "Copying not possible. Copy manually.", "copied-to-clipboard-error": "Copying not possible. Copy manually.",
"text-content-incorrect": "Text content is incorrect.", "text-content-incorrect": "Text content is incorrect.",
"file-content-incorrect": "File content is incorrect.", "file-content-incorrect": "File content is incorrect.",

View file

@ -1217,6 +1217,7 @@ class PairDeviceDialog extends Dialog {
Events.on('evaluate-number-room-secrets', _ => this._evaluateNumberRoomSecrets()) Events.on('evaluate-number-room-secrets', _ => this._evaluateNumberRoomSecrets())
Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail)); Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail));
this.$el.addEventListener('paste', e => this._onPaste(e)); this.$el.addEventListener('paste', e => this._onPaste(e));
this.$qrCode.addEventListener('click', _ => this._copyPairUrl());
this.evaluateUrlAttributes(); this.evaluateUrlAttributes();
@ -1257,7 +1258,7 @@ class PairDeviceDialog extends Dialog {
this.$key.innerText = `${this.pairKey.substring(0,3)} ${this.pairKey.substring(3,6)}` this.$key.innerText = `${this.pairKey.substring(0,3)} ${this.pairKey.substring(3,6)}`
// Display the QR code for the url // Display the QR code for the url
const qr = new QRCode({ const qr = new QRCode({
content: this._getPairURL(), content: this._getPairUrl(),
width: 150, width: 150,
height: 150, height: 150,
padding: 0, padding: 0,
@ -1271,12 +1272,22 @@ class PairDeviceDialog extends Dialog {
this.show(); this.show();
} }
_getPairURL() { _getPairUrl() {
let url = new URL(location.href); let url = new URL(location.href);
url.searchParams.append('pair_key', this.pairKey) url.searchParams.append('pair_key', this.pairKey)
return url.href; return url.href;
} }
_copyPairUrl() {
navigator.clipboard.writeText(this._getPairUrl())
.then(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.pair-url-copied-to-clipboard"));
})
.catch(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.copied-to-clipboard-error"));
})
}
_onSubmit(e) { _onSubmit(e) {
e.preventDefault(); e.preventDefault();
this._submit(); this._submit();
@ -1548,6 +1559,7 @@ class PublicRoomDialog extends Dialog {
Events.on('public-room-id-invalid', e => this._onPublicRoomIdInvalid(e.detail)); Events.on('public-room-id-invalid', e => this._onPublicRoomIdInvalid(e.detail));
Events.on('public-room-left', _ => this._onPublicRoomLeft()); Events.on('public-room-left', _ => this._onPublicRoomLeft());
this.$el.addEventListener('paste', e => this._onPaste(e)); this.$el.addEventListener('paste', e => this._onPaste(e));
this.$qrCode.addEventListener('click', _ => this._copyShareRoomUrl());
this.evaluateUrlAttributes(); this.evaluateUrlAttributes();
@ -1596,7 +1608,7 @@ class PublicRoomDialog extends Dialog {
// Display the QR code for the url // Display the QR code for the url
const qr = new QRCode({ const qr = new QRCode({
content: this._getShareRoomURL(), content: this._getShareRoomUrl(),
width: 150, width: 150,
height: 150, height: 150,
padding: 0, padding: 0,
@ -1621,16 +1633,26 @@ class PublicRoomDialog extends Dialog {
Events.fire('evaluate-footer-badges'); Events.fire('evaluate-footer-badges');
} }
_getShareRoomURL() { _getShareRoomUrl() {
let url = new URL(location.href); let url = new URL(location.href);
url.searchParams.append('room_key', this.roomId) url.searchParams.append('room_id', this.roomId)
return url.href; return url.href;
} }
_copyShareRoomUrl() {
navigator.clipboard.writeText(this._getShareRoomUrl())
.then(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.room-url-copied-to-clipboard"));
})
.catch(_ => {
Events.fire('notify-user', Localization.getTranslation("notifications.copied-to-clipboard-error"));
})
}
evaluateUrlAttributes() { evaluateUrlAttributes() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('room_key')) { if (urlParams.has('room_id')) {
this._joinPublicRoom(urlParams.get('room_key')); this._joinPublicRoom(urlParams.get('room_id'));
const url = getUrlWithoutArguments(); const url = getUrlWithoutArguments();
window.history.replaceState({}, "Rewrite URL", url); //remove pair_key from url window.history.replaceState({}, "Rewrite URL", url); //remove pair_key from url
} }

View file

@ -861,6 +861,8 @@ x-dialog a {
.key-qr-code { .key-qr-code {
margin: 16px; margin: 16px;
width: fit-content;
align-self: center;
} }
.key-instructions { .key-instructions {