1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import { t } from './i18n.js';
import * as platform from './platform.js';
import { groupLinkRoute } from './group-link.js';
import { say } from './note.js';
/**
* "Copy link": the `#/name@owner/path` address of a file or folder
* (group-link.js), on this hub, put on the clipboard.
*
* The hub's origin, never the page's: in the desktop application the page is
* `app://meshbay`, and a link that only opens inside one person's application
* is not a link.
*/
/** The full link to `path` inside `group` (`{ name, owner_username }`). */
export function groupItemLink(group, path) {
return platform.hubOrigin() + '/#' + groupLinkRoute(group, path);
}
/** An entry's path inside its group: its folder, root first, then its name. */
export function entryPath(entry, dir = entry.path) {
return [dir, entry.name].filter(Boolean).join('/');
}
// The async clipboard first; the old command where it is refused — a page
// without focus, a WebView without the permission. Neither needs to read
// anything back.
async function _write(text) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch { /* fall through */ }
const area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', '');
area.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none';
document.body.appendChild(area);
area.select();
let ok = false;
try { ok = document.execCommand('copy'); } catch { ok = false; }
area.remove();
return ok;
}
/** Copy `url`, and say whether it worked. The link itself is shown if not. */
export async function copyLink(url) {
if (!url) return;
const ok = await _write(url);
say(ok ? t('link.copied') : t('link.copy_failed', { url }));
}
|