@haex-space/vault-sdk 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1573,6 +1573,10 @@ function parseTableName(fullTableName) {
1573
1573
 
1574
1574
  // src/client/init.ts
1575
1575
  var PORT_HANDSHAKE_TIMEOUT_MS = 1e4;
1576
+ function getCurrentWebviewLabel() {
1577
+ const internals = window.__TAURI_INTERNALS__;
1578
+ return internals?.metadata?.currentWebview?.label;
1579
+ }
1576
1580
  function isInIframe() {
1577
1581
  return window.self !== window.top;
1578
1582
  }
@@ -1601,6 +1605,13 @@ async function initNativeMode(ctx, log, onEvent, onContextChange) {
1601
1605
  }
1602
1606
  async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1603
1607
  const { listen } = getTauriEvent();
1608
+ const webviewLabel = getCurrentWebviewLabel();
1609
+ const listenOptions = webviewLabel ? { target: webviewLabel } : void 0;
1610
+ if (!webviewLabel) {
1611
+ log(
1612
+ "WARNING: could not read __TAURI_INTERNALS__.metadata.currentWebview.label \u2014 registering listeners without a target. Label-scoped emits from the host will not be delivered until the metadata is available."
1613
+ );
1614
+ }
1604
1615
  log("Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
1605
1616
  try {
1606
1617
  await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
@@ -1618,7 +1629,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1618
1629
  } else {
1619
1630
  log("Event received but no context in payload:", event);
1620
1631
  }
1621
- });
1632
+ }, listenOptions);
1622
1633
  log("Context change listener registered successfully");
1623
1634
  } catch (error) {
1624
1635
  log("Failed to setup context change listener:", error);
@@ -1636,7 +1647,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1636
1647
  } else {
1637
1648
  log("External request event has no payload!");
1638
1649
  }
1639
- });
1650
+ }, listenOptions);
1640
1651
  log("External request listener registered successfully");
1641
1652
  } catch (error) {
1642
1653
  log("Failed to setup external request listener:", error);
@@ -1654,7 +1665,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1654
1665
  } else {
1655
1666
  log("AI action request event has no payload!");
1656
1667
  }
1657
- });
1668
+ }, listenOptions);
1658
1669
  log("AI action request listener registered successfully");
1659
1670
  } catch (error) {
1660
1671
  log("Failed to setup AI action request listener:", error);
@@ -1673,7 +1684,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1673
1684
  timestamp: Date.now()
1674
1685
  });
1675
1686
  }
1676
- });
1687
+ }, listenOptions);
1677
1688
  log("File change listener registered successfully");
1678
1689
  } catch (error) {
1679
1690
  log("Failed to setup file change listener:", error);
@@ -1690,14 +1701,14 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1690
1701
  timestamp: Date.now()
1691
1702
  });
1692
1703
  }
1693
- });
1704
+ }, listenOptions);
1694
1705
  log("Sync tables updated listener registered successfully");
1695
1706
  } catch (error) {
1696
1707
  log("Failed to setup sync tables updated listener:", error);
1697
1708
  }
1698
1709
  log("Setting up LocalSend event listeners");
1699
1710
  try {
1700
- await setupLocalSendEventListeners(log, onEvent);
1711
+ await setupLocalSendEventListeners(log, onEvent, listenOptions);
1701
1712
  log("LocalSend event listeners setup complete");
1702
1713
  } catch (error) {
1703
1714
  log("Failed to setup LocalSend event listeners:", error);
@@ -1714,7 +1725,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1714
1725
  data: payload.data
1715
1726
  });
1716
1727
  }
1717
- });
1728
+ }, listenOptions);
1718
1729
  log("Shell output listener registered");
1719
1730
  await listen(SHELL_EVENTS.EXIT, (event) => {
1720
1731
  if (event.payload) {
@@ -1726,13 +1737,13 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1726
1737
  exitCode: payload.exitCode
1727
1738
  });
1728
1739
  }
1729
- });
1740
+ }, listenOptions);
1730
1741
  log("Shell exit listener registered");
1731
1742
  } catch (error) {
1732
1743
  log("Failed to setup Shell event listeners:", error);
1733
1744
  }
1734
1745
  }
1735
- async function setupLocalSendEventListeners(log, onEvent) {
1746
+ async function setupLocalSendEventListeners(log, onEvent, listenOptions) {
1736
1747
  const { listen } = getTauriEvent();
1737
1748
  try {
1738
1749
  await listen(LOCALSEND_EVENTS.deviceDiscovered, (event) => {
@@ -1744,7 +1755,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1744
1755
  timestamp: Date.now()
1745
1756
  });
1746
1757
  }
1747
- });
1758
+ }, listenOptions);
1748
1759
  log("LocalSend device discovered listener registered");
1749
1760
  } catch (error) {
1750
1761
  log("Failed to setup LocalSend device discovered listener:", error);
@@ -1759,7 +1770,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1759
1770
  timestamp: Date.now()
1760
1771
  });
1761
1772
  }
1762
- });
1773
+ }, listenOptions);
1763
1774
  log("LocalSend device lost listener registered");
1764
1775
  } catch (error) {
1765
1776
  log("Failed to setup LocalSend device lost listener:", error);
@@ -1774,7 +1785,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1774
1785
  timestamp: Date.now()
1775
1786
  });
1776
1787
  }
1777
- });
1788
+ }, listenOptions);
1778
1789
  log("LocalSend transfer request listener registered");
1779
1790
  } catch (error) {
1780
1791
  log("Failed to setup LocalSend transfer request listener:", error);
@@ -1789,7 +1800,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1789
1800
  timestamp: Date.now()
1790
1801
  });
1791
1802
  }
1792
- });
1803
+ }, listenOptions);
1793
1804
  log("LocalSend transfer progress listener registered");
1794
1805
  } catch (error) {
1795
1806
  log("Failed to setup LocalSend transfer progress listener:", error);
@@ -1804,7 +1815,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1804
1815
  timestamp: Date.now()
1805
1816
  });
1806
1817
  }
1807
- });
1818
+ }, listenOptions);
1808
1819
  log("LocalSend transfer complete listener registered");
1809
1820
  } catch (error) {
1810
1821
  log("Failed to setup LocalSend transfer complete listener:", error);
@@ -1819,13 +1830,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
1819
1830
  timestamp: Date.now()
1820
1831
  });
1821
1832
  }
1822
- });
1833
+ }, listenOptions);
1823
1834
  log("LocalSend transfer failed listener registered");
1824
1835
  } catch (error) {
1825
1836
  log("Failed to setup LocalSend transfer failed listener:", error);
1826
1837
  }
1827
1838
  }
1828
- async function initIframeMode(ctx, log, messageHandler, request) {
1839
+ async function initIframeMode(ctx, log, messageHandler) {
1829
1840
  if (!isInIframe()) {
1830
1841
  throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
1831
1842
  }
@@ -1847,10 +1858,7 @@ async function initIframeMode(ctx, log, messageHandler, request) {
1847
1858
  log("Extension info loaded from manifest:", ctx.state.extensionInfo);
1848
1859
  }
1849
1860
  sendDebugInfo(ctx.config);
1850
- const context = await request(EXTENSION_COMMANDS.getContext);
1851
- ctx.state.context = context;
1852
- log("Application context received:", context);
1853
- return { context, port };
1861
+ return port;
1854
1862
  }
1855
1863
  function waitForHostPortAsync(log) {
1856
1864
  return new Promise((resolve, reject) => {
@@ -2453,7 +2461,7 @@ var HaexVaultSdk = class {
2453
2461
  () => this._extensionInfo,
2454
2462
  this.handleEvent.bind(this)
2455
2463
  );
2456
- const { context, port } = await initIframeMode(
2464
+ const port = await initIframeMode(
2457
2465
  {
2458
2466
  config: this.config,
2459
2467
  state: {
@@ -2482,8 +2490,7 @@ var HaexVaultSdk = class {
2482
2490
  }
2483
2491
  },
2484
2492
  this.log.bind(this),
2485
- this.messageHandler,
2486
- this.request.bind(this)
2493
+ this.messageHandler
2487
2494
  );
2488
2495
  this.hostPort = port;
2489
2496
  if (this.config.manifest) {
@@ -2495,6 +2502,8 @@ var HaexVaultSdk = class {
2495
2502
  };
2496
2503
  this.notifySubscribersInternal();
2497
2504
  }
2505
+ const context = await this.request(EXTENSION_COMMANDS.getContext);
2506
+ this.log("Application context received:", context);
2498
2507
  this._context = context;
2499
2508
  this.isNativeWindow = false;
2500
2509
  this.initialized = true;