experiments in a post-browser web
10
fork

Configure Feed

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

fix repeated default browser prompt

+45 -3
+45 -3
index.js
··· 488 488 // handle peek:// 489 489 initAppProtocol(); 490 490 491 - // Register as default handler for http/https URLs 492 - app.setAsDefaultProtocolClient('http'); 493 - app.setAsDefaultProtocolClient('https'); 491 + // Register as default handler for http/https URLs (if not already and user hasn't declined) 492 + const defaultBrowserPrefFile = path.join(profileDataPath, 'default-browser-pref.json'); 493 + let shouldPromptForDefault = true; 494 + 495 + // Check if user has previously declined 496 + try { 497 + if (fs.existsSync(defaultBrowserPrefFile)) { 498 + const pref = JSON.parse(fs.readFileSync(defaultBrowserPrefFile, 'utf8')); 499 + if (pref.declined === true) { 500 + shouldPromptForDefault = false; 501 + console.log('User previously declined default browser prompt'); 502 + } 503 + } 504 + } catch (e) { 505 + // Ignore errors reading pref file 506 + } 507 + 508 + // Only try to register if user hasn't declined and we're not already default 509 + if (shouldPromptForDefault) { 510 + const isDefaultHttp = app.isDefaultProtocolClient('http'); 511 + const isDefaultHttps = app.isDefaultProtocolClient('https'); 512 + 513 + if (!isDefaultHttp || !isDefaultHttps) { 514 + console.log('Registering as default protocol client for http/https'); 515 + app.setAsDefaultProtocolClient('http'); 516 + app.setAsDefaultProtocolClient('https'); 517 + 518 + // Check if registration succeeded - if not, user likely declined 519 + setTimeout(() => { 520 + const nowDefaultHttp = app.isDefaultProtocolClient('http'); 521 + const nowDefaultHttps = app.isDefaultProtocolClient('https'); 522 + if (!nowDefaultHttp && !nowDefaultHttps) { 523 + // User declined, save preference 524 + console.log('User declined default browser, saving preference'); 525 + try { 526 + fs.writeFileSync(defaultBrowserPrefFile, JSON.stringify({ declined: true, timestamp: Date.now() })); 527 + } catch (e) { 528 + console.error('Failed to save default browser preference:', e); 529 + } 530 + } 531 + }, 2000); 532 + } else { 533 + console.log('Already default protocol client for http/https'); 534 + } 535 + } 494 536 495 537 // Handle CLI arguments (e.g., yarn start -- "https://example.com") 496 538 const urlArg = process.argv.find(arg =>