experiments in a post-browser web
10
fork

Configure Feed

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

extension indexing vs hard coding

+46 -10
+46 -10
index.js
··· 534 534 return null; 535 535 }; 536 536 537 + /** 538 + * Scan a directory for valid extensions (folders with manifest.json) 539 + * @param {string} basePath - Directory to scan 540 + * @returns {Array<{id: string, path: string, manifest: object}>} 541 + */ 542 + const discoverExtensions = (basePath) => { 543 + const extensions = []; 544 + 545 + if (!fs.existsSync(basePath)) return extensions; 546 + 547 + const entries = fs.readdirSync(basePath, { withFileTypes: true }); 548 + 549 + for (const entry of entries) { 550 + if (!entry.isDirectory()) continue; 551 + 552 + const extPath = path.join(basePath, entry.name); 553 + const manifestPath = path.join(extPath, 'manifest.json'); 554 + 555 + if (!fs.existsSync(manifestPath)) continue; 556 + 557 + try { 558 + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8')); 559 + 560 + // Use manifest.id or folder name as fallback 561 + const id = manifest.id || manifest.shortname || entry.name; 562 + 563 + extensions.push({ id, path: extPath, manifest }); 564 + 565 + } catch (err) { 566 + console.error(`[ext:discovery] Failed to load ${entry.name}:`, err.message); 567 + } 568 + } 569 + 570 + return extensions; 571 + }; 572 + 537 573 // ***** Extension Window Management ***** 538 574 // Each extension runs in its own isolated BrowserWindow at peek://ext/{id}/background.html 539 575 ··· 669 705 670 706 // Load enabled extensions on startup 671 707 const loadEnabledExtensions = async () => { 672 - // Built-in extensions 673 - const builtinExtensions = ['groups', 'peeks', 'slides']; 708 + // Get all discovered extensions (registered via discoverExtensions) 709 + const builtinExtIds = Array.from(extensionPaths.keys()); 674 710 675 711 // Check which are enabled from datastore/localStorage 676 - // For now, load all builtins; actual enable/disable can be added later 677 - for (const extId of builtinExtensions) { 712 + for (const extId of builtinExtIds) { 678 713 // Check if enabled in extension_settings or extensions table 679 714 let enabled = true; // Default to enabled for builtins 680 715 ··· 841 876 // handle peek:// 842 877 initAppProtocol(); 843 878 844 - // Register built-in extensions 845 - // Built-in extensions live in ./extensions/ at the project root 846 - registerExtensionPath('groups', path.join(__dirname, 'extensions', 'groups')); 847 - registerExtensionPath('peeks', path.join(__dirname, 'extensions', 'peeks')); 848 - registerExtensionPath('slides', path.join(__dirname, 'extensions', 'slides')); 849 - registerExtensionPath('example', path.join(__dirname, 'extensions', 'example')); 879 + // Discover and register built-in extensions from extensions/ folder 880 + const discoveredExtensions = discoverExtensions(path.join(__dirname, 'extensions')); 881 + console.log(`[ext:discovery] Found ${discoveredExtensions.length} extensions:`, discoveredExtensions.map(e => e.id).join(', ')); 882 + 883 + for (const ext of discoveredExtensions) { 884 + registerExtensionPath(ext.id, ext.path); 885 + } 850 886 851 887 // Register as default handler for http/https URLs (if not already and user hasn't declined) 852 888 const defaultBrowserPrefFile = path.join(profileDataPath, 'default-browser-pref.json');