fix clipboard for the panel
This commit is contained in:
@ -1011,6 +1011,7 @@ const fileContextMenu = (elDisplay = null) => {
|
||||
.setLabel('Copy path')
|
||||
.setClickHandler(() => {
|
||||
const path = isNoneSelected ? activeConnection.path : selectedFiles[0].dataset.path;
|
||||
console.log('Clipboard context:', window.location.href, window.top === window ? 'Parent' : 'Iframe');
|
||||
navigator.clipboard.writeText(path);
|
||||
setStatus(`Copied path to clipboard`);
|
||||
})
|
||||
@ -2318,8 +2319,25 @@ btnShare.addEventListener('click', async() => {
|
||||
} else if (isMultiSelected)
|
||||
url = await getZipDownloadUrl(selected.map(el => el.dataset.path), activeConnection.path);
|
||||
if (url) {
|
||||
navigator.clipboard.writeText(url);
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
setStatus(`Copied download link to clipboard`);
|
||||
} catch (err) {
|
||||
console.error('Clipboard error:', err);
|
||||
// Fallback
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = url;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
setStatus(`Copied download link to clipboard (fallback)`);
|
||||
} catch (fallbackErr) {
|
||||
console.error('Fallback failed:', fallbackErr);
|
||||
setStatus(`Failed to copy link. Please copy manually: ${url}`, true);
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addAction(action => action.setLabel('Cancel'))
|
||||
|
@ -8,6 +8,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="theme-color" content="#1f2733">
|
||||
<meta http-equiv="Permissions-Policy" content="clipboard-write=(self 'https://sftp.my-mc.link')">
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<link rel="icon" href="/icon.png">
|
||||
<link rel="stylesheet" href="https://src.simplecyber.org/v2/themes.css">
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
self.clients.claim();
|
||||
});
|
||||
@ -6,24 +5,44 @@ self.addEventListener('activate', (e) => {
|
||||
self.addEventListener('fetch', (e) => {
|
||||
const reqUrl = e.request.url;
|
||||
e.respondWith((async() => {
|
||||
// Open asset cache and see if this request is in it
|
||||
// Open asset cache
|
||||
const cache = await caches.open('main');
|
||||
const match = await caches.match(e.request);
|
||||
// Request the resource from the network
|
||||
|
||||
// Request from network
|
||||
const netRes = fetch(e.request).then((res) => {
|
||||
// If the request was successful and this isn't an API call,
|
||||
// update the cached resource
|
||||
if (res.ok && !reqUrl.match(/\/api\/sftp\/.*$/)) {
|
||||
cache.put(e.request, res.clone());
|
||||
}
|
||||
// Return the response
|
||||
return res;
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
return match;
|
||||
// Create a new response with updated headers
|
||||
const newHeaders = new Headers(res.headers);
|
||||
newHeaders.set('Permissions-Policy', 'clipboard-write=(self), clipboard-read=(self)');
|
||||
|
||||
const newRes = new Response(res.body, {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
headers: newHeaders
|
||||
});
|
||||
// Return the cached resource if it exists
|
||||
// Otherwise, return the network request
|
||||
|
||||
// Cache non-API responses
|
||||
if (res.ok && !reqUrl.match(/\/api\/sftp\/.*$/)) {
|
||||
cache.put(e.request, newRes.clone());
|
||||
}
|
||||
|
||||
return newRes;
|
||||
}).catch(e => {
|
||||
console.error('Fetch error:', e);
|
||||
if (match) {
|
||||
// Add header to cached response
|
||||
const newHeaders = new Headers(match.headers);
|
||||
newHeaders.set('Permissions-Policy', 'clipboard-write=(self), clipboard-read=(self)');
|
||||
return new Response(match.body, {
|
||||
status: match.status,
|
||||
statusText: match.statusText,
|
||||
headers: newHeaders
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
|
||||
// Return cached or network response
|
||||
return match || netRes;
|
||||
})());
|
||||
});
|
Reference in New Issue
Block a user