experiments in a post-browser web
at main 79 lines 2.3 kB view raw
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';"> 6 <title>Editor Extension</title> 7</head> 8<body> 9<script type="module"> 10 import extension from './background.js'; 11 12 // Feature detection - check if Peek API is available 13 const hasPeekAPI = typeof window.app !== 'undefined'; 14 const api = hasPeekAPI ? window.app : null; 15 const extId = extension.id; 16 17 console.log(`[ext:${extId}] background.html loaded`); 18 console.log(`[ext:${extId}] Peek API available:`, hasPeekAPI); 19 20 if (hasPeekAPI) { 21 // Running as a Peek extension - full functionality 22 23 // Signal ready to main process 24 api.publish('ext:ready', { 25 id: extId, 26 manifest: { 27 id: extension.id, 28 labels: extension.labels, 29 version: '1.0.0' 30 } 31 }, api.scopes.SYSTEM); 32 33 // Initialize extension 34 if (extension.init) { 35 console.log(`[ext:${extId}] calling init()`); 36 extension.init(); 37 } 38 39 // Handle shutdown request from main process 40 api.subscribe('app:shutdown', () => { 41 console.log(`[ext:${extId}] received shutdown`); 42 if (extension.uninit) { 43 extension.uninit(); 44 } 45 }, api.scopes.SYSTEM); 46 47 // Handle extension-specific shutdown 48 api.subscribe(`ext:${extId}:shutdown`, () => { 49 console.log(`[ext:${extId}] received extension shutdown`); 50 if (extension.uninit) { 51 extension.uninit(); 52 } 53 }, api.scopes.SYSTEM); 54 55 } else { 56 // Running as a regular website - limited functionality 57 console.log(`[ext:${extId}] Running in standalone mode (no Peek API)`); 58 59 if (extension.init) { 60 extension.init(); 61 } 62 63 document.body.innerHTML = ` 64 <div style="font-family: system-ui; padding: 20px; max-width: 600px; margin: 0 auto;"> 65 <h1>Editor Extension</h1> 66 <p>Running in standalone mode (Peek API not available).</p> 67 <p>When running inside Peek, this extension provides:</p> 68 <ul> 69 <li>View, add, and edit saved items</li> 70 <li>Global shortcut (Option+E to open)</li> 71 <li>Type filtering and search</li> 72 </ul> 73 <p><a href="./home.html">Open Editor</a></p> 74 </div> 75 `; 76 } 77</script> 78</body> 79</html>