Rewild Your Web

p2p: more context menu options

Signed-off-by: webbeef <me@webbeef.org>

+54 -17
+54 -17
ui/system/web_view.js
··· 448 448 icon: actionIcons[item.id] || item.icon, 449 449 })); 450 450 451 - // Add "Open in <peer>" items for connected paired peers. 451 + // Add P2P "Open/Send in <peer>" items for connected paired peers. 452 452 try { 453 453 const peers = await navigator.embedder.pairing.peers(); 454 454 const connected = peers.filter((p) => p.status === "paired-connected"); 455 - if (connected.length === 1) { 456 - items.push({ 457 - id: `p2p_open_in:${connected[0].id}`, 458 - label: `Open in ${connected[0].displayName}`, 459 - icon: "send", 460 - disabled: false, 461 - }); 462 - } else if (connected.length > 1) { 463 - for (const peer of connected) { 464 - items.push({ 465 - id: `p2p_open_in:${peer.id}`, 466 - label: `Open in ${peer.displayName}`, 455 + if (connected.length > 0) { 456 + const peerItems = (idPrefix, label, url) => 457 + connected.map((peer) => ({ 458 + id: `${idPrefix}:${peer.id}:${url}`, 459 + label: `${label} ${peer.displayName}`, 467 460 icon: "send", 468 461 disabled: false, 469 - }); 462 + })); 463 + 464 + // Insert "Open Link in <peer>" after "OpenLinkInNewWebView" 465 + if (params.linkUrl) { 466 + const idx = items.findIndex( 467 + (i) => i.id === "OpenLinkInNewWebView", 468 + ); 469 + if (idx !== -1) { 470 + items.splice( 471 + idx + 1, 472 + 0, 473 + ...peerItems("p2p_open_link", "Open Link in", params.linkUrl), 474 + ); 475 + } 470 476 } 477 + 478 + // Insert "Open Image in <peer>" after "OpenImageInNewView" 479 + if (params.imageUrl) { 480 + const idx = items.findIndex( 481 + (i) => i.id === "OpenImageInNewView", 482 + ); 483 + if (idx !== -1) { 484 + items.splice( 485 + idx + 1, 486 + 0, 487 + ...peerItems( 488 + "p2p_open_image", 489 + "Open Image in", 490 + params.imageUrl, 491 + ), 492 + ); 493 + } 494 + } 495 + 496 + // "Open this view in <peer>" at the end (for current page) 497 + items.push( 498 + ...peerItems("p2p_open_in", "Open in", this.currentUrl), 499 + ); 471 500 } 472 501 } catch { 473 502 // Pairing service may not be running — skip the items. ··· 540 569 541 570 this.ensureIframe(); 542 571 543 - // Handle P2P "Open in <peer>" action locally. 544 - if (action.startsWith("p2p_open_in:")) { 572 + // Handle P2P "Open in <peer>" actions locally. 573 + if ( 574 + action.startsWith("p2p_open_in:") || 575 + action.startsWith("p2p_open_link:") || 576 + action.startsWith("p2p_open_image:") 577 + ) { 545 578 this.iframe.respondToContextMenu(controlId, null); 546 579 this.contextMenu = null; 580 + // Format: "p2p_<type>:<peerId>:<url>" 581 + const firstColon = action.indexOf(":"); 582 + const secondColon = action.indexOf(":", firstColon + 1); 583 + const url = action.slice(secondColon + 1); 547 584 this.dispatchEvent( 548 585 new CustomEvent("p2p-open-in", { 549 586 bubbles: true, 550 587 composed: true, 551 - detail: { url: this.currentUrl }, 588 + detail: { url }, 552 589 }), 553 590 ); 554 591 return;