Merge pull request #1382 from JeLuF/remoteclflr

Don't show copy button without clipboard access
This commit is contained in:
cmdr2 2023-07-01 09:06:05 +05:30 committed by GitHub
commit 4dd254263f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -1575,6 +1575,7 @@ body.wait-pause {
margin-top: 0.2em;
margin-bottom: 0.2em;
display: inline-block;
width: 80%;
}
#copy-cloudflare-address {

View File

@ -2103,7 +2103,7 @@ function tunnelUpdate(event) {
if ("cloudflare" in event) {
document.getElementById("cloudflare-off").classList.add("displayNone")
document.getElementById("cloudflare-on").classList.remove("displayNone")
cloudflareAddressField.innerHTML = event.cloudflare
cloudflareAddressField.value = event.cloudflare
document.getElementById("toggle-cloudflare-tunnel").innerHTML = "Stop"
} else {
document.getElementById("cloudflare-on").classList.add("displayNone")

View File

@ -233,7 +233,7 @@ var PARAMETERS = [
note: `<span id="cloudflare-off">Create a VPN tunnel to share your Easy Diffusion instance with your friends. This will
generate a web server address on the public Internet for your Easy Diffusion instance. </span>
<div id="cloudflare-on" class="displayNone"><div>This Easy Diffusion server is available on the Internet using the
address:</div><div><div id="cloudflare-address"></div><button id="copy-cloudflare-address">Copy</button></div></div>
address:</div><div><input id="cloudflare-address" value="" readonly><button id="copy-cloudflare-address">Copy</button></div></div>
<b>Anyone knowing this address can access your server.</b> The address of your server will change each time
you share a session.<br>
Uses <a href="https://try.cloudflare.com/" target="_blank">Cloudflare services</a>.`,
@ -714,9 +714,17 @@ listenPortField.addEventListener("change", debounce( ()=>{
let copyCloudflareAddressBtn = document.querySelector("#copy-cloudflare-address")
let cloudflareAddressField = document.getElementById("cloudflare-address")
copyCloudflareAddressBtn.addEventListener("click", (e) => {
navigator.permissions.query({ name: "clipboard-write" }).then(function (result) {
if (result.state === "granted") {
// you can read from the clipboard
copyCloudflareAddressBtn.addEventListener("click", (e) => {
navigator.clipboard.writeText(cloudflareAddressField.innerHTML)
showToast("Copied server address to clipboard")
})
})
} else {
copyCloudflareAddressBtn.classList.add("displayNone")
}
});
document.addEventListener("system_info_update", (e) => setDeviceInfo(e.detail))