WIP PWA for Grain
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 27 lines 772 B view raw
1/** 2 * Share utility with Web Share API and clipboard fallback. 3 * Returns { success: boolean, method: 'share' | 'clipboard' } 4 */ 5export async function share(url) { 6 // Try Web Share API first 7 if (navigator.share) { 8 try { 9 await navigator.share({ url }); 10 return { success: true, method: 'share' }; 11 } catch (err) { 12 // User cancelled or error - fall through to clipboard 13 if (err.name === 'AbortError') { 14 return { success: false, method: 'share' }; 15 } 16 } 17 } 18 19 // Fallback to clipboard 20 try { 21 await navigator.clipboard.writeText(url); 22 return { success: true, method: 'clipboard' }; 23 } catch (err) { 24 console.error('Failed to copy to clipboard:', err); 25 return { success: false, method: 'clipboard' }; 26 } 27}