• Copies text to clipboard with Electron-compatible fallback for unfocused documents.

    Parameters

    • text: string

      Text to copy to clipboard.

    Returns Promise<void>

    Promise that resolves when copy succeeds.

    If copy operation fails in all attempts.

    export async function copyToClipboard(text: string): Promise<void> {
    // Try the standard Clipboard API first
    if (navigator.clipboard && globalThis.isSecureContext) {
    try {
    await navigator.clipboard.writeText(text);
    return;
    } catch (err) {
    // Document may not be focused in Electron - continue to fallback
    if (err instanceof Error && err.message.includes("not focused")) {
    // Expected in some Electron contexts, use fallback
    } else {
    throw err;
    }
    }
    }

    // Fallback: Use textarea selection method (works in Electron)
    fallbackCopyToClipboard(text);
    }