fix(share): robust clipboard copy with an iOS-safe fallback

navigator.clipboard.writeText is intermittent on iOS Safari (bug 9: the
download share-link copy 'often does neither'). Add lib/clipboard.ts
copyText(): a gesture-safe execCommand path FIRST (before any await can
spend the transient user activation), async Clipboard API as fallback.
Migrate all five copy call sites to it.
This commit is contained in:
2026-07-19 05:38:42 +02:00
parent 31a8835f7f
commit 42ae451c1b
6 changed files with 77 additions and 15 deletions
+4 -3
View File
@@ -1,5 +1,6 @@
import { useEffect, useMemo, useState } from "react";
import Overlay from "./Overlay";
import { copyText } from "../lib/clipboard";
import { usePrefs } from "./PrefsProvider";
/**
@@ -205,11 +206,11 @@ export default function GlassTuner() {
return lines.length ? `${scope} {\n${lines.join("\n")}\n}` : "/* all values at defaults */";
}, [vars, palette, themeTick]);
function copy() {
navigator.clipboard?.writeText(cssOut).then(() => {
async function copy() {
if (await copyText(cssOut)) {
setCopied(true);
setTimeout(() => setCopied(false), 1200);
});
}
}
function persistOpen(v: boolean) {