@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.
@@ -1575,6 +1575,10 @@ function parseTableName(fullTableName) {
1575
1575
 
1576
1576
  // src/client/init.ts
1577
1577
  var PORT_HANDSHAKE_TIMEOUT_MS = 1e4;
1578
+ function getCurrentWebviewLabel() {
1579
+ const internals = window.__TAURI_INTERNALS__;
1580
+ return internals?.metadata?.currentWebview?.label;
1581
+ }
1578
1582
  function isInIframe() {
1579
1583
  return window.self !== window.top;
1580
1584
  }
@@ -1603,6 +1607,13 @@ async function initNativeMode(ctx, log, onEvent, onContextChange) {
1603
1607
  }
1604
1608
  async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1605
1609
  const { listen } = getTauriEvent();
1610
+ const webviewLabel = getCurrentWebviewLabel();
1611
+ const listenOptions = webviewLabel ? { target: webviewLabel } : void 0;
1612
+ if (!webviewLabel) {
1613
+ log(
1614
+ "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."
1615
+ );
1616
+ }
1606
1617
  log("Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
1607
1618
  try {
1608
1619
  await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
@@ -1620,7 +1631,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1620
1631
  } else {
1621
1632
  log("Event received but no context in payload:", event);
1622
1633
  }
1623
- });
1634
+ }, listenOptions);
1624
1635
  log("Context change listener registered successfully");
1625
1636
  } catch (error) {
1626
1637
  log("Failed to setup context change listener:", error);
@@ -1638,7 +1649,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1638
1649
  } else {
1639
1650
  log("External request event has no payload!");
1640
1651
  }
1641
- });
1652
+ }, listenOptions);
1642
1653
  log("External request listener registered successfully");
1643
1654
  } catch (error) {
1644
1655
  log("Failed to setup external request listener:", error);
@@ -1656,7 +1667,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1656
1667
  } else {
1657
1668
  log("AI action request event has no payload!");
1658
1669
  }
1659
- });
1670
+ }, listenOptions);
1660
1671
  log("AI action request listener registered successfully");
1661
1672
  } catch (error) {
1662
1673
  log("Failed to setup AI action request listener:", error);
@@ -1675,7 +1686,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1675
1686
  timestamp: Date.now()
1676
1687
  });
1677
1688
  }
1678
- });
1689
+ }, listenOptions);
1679
1690
  log("File change listener registered successfully");
1680
1691
  } catch (error) {
1681
1692
  log("Failed to setup file change listener:", error);
@@ -1692,14 +1703,14 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1692
1703
  timestamp: Date.now()
1693
1704
  });
1694
1705
  }
1695
- });
1706
+ }, listenOptions);
1696
1707
  log("Sync tables updated listener registered successfully");
1697
1708
  } catch (error) {
1698
1709
  log("Failed to setup sync tables updated listener:", error);
1699
1710
  }
1700
1711
  log("Setting up LocalSend event listeners");
1701
1712
  try {
1702
- await setupLocalSendEventListeners(log, onEvent);
1713
+ await setupLocalSendEventListeners(log, onEvent, listenOptions);
1703
1714
  log("LocalSend event listeners setup complete");
1704
1715
  } catch (error) {
1705
1716
  log("Failed to setup LocalSend event listeners:", error);
@@ -1716,7 +1727,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1716
1727
  data: payload.data
1717
1728
  });
1718
1729
  }
1719
- });
1730
+ }, listenOptions);
1720
1731
  log("Shell output listener registered");
1721
1732
  await listen(SHELL_EVENTS.EXIT, (event) => {
1722
1733
  if (event.payload) {
@@ -1728,13 +1739,13 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1728
1739
  exitCode: payload.exitCode
1729
1740
  });
1730
1741
  }
1731
- });
1742
+ }, listenOptions);
1732
1743
  log("Shell exit listener registered");
1733
1744
  } catch (error) {
1734
1745
  log("Failed to setup Shell event listeners:", error);
1735
1746
  }
1736
1747
  }
1737
- async function setupLocalSendEventListeners(log, onEvent) {
1748
+ async function setupLocalSendEventListeners(log, onEvent, listenOptions) {
1738
1749
  const { listen } = getTauriEvent();
1739
1750
  try {
1740
1751
  await listen(LOCALSEND_EVENTS.deviceDiscovered, (event) => {
@@ -1746,7 +1757,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1746
1757
  timestamp: Date.now()
1747
1758
  });
1748
1759
  }
1749
- });
1760
+ }, listenOptions);
1750
1761
  log("LocalSend device discovered listener registered");
1751
1762
  } catch (error) {
1752
1763
  log("Failed to setup LocalSend device discovered listener:", error);
@@ -1761,7 +1772,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1761
1772
  timestamp: Date.now()
1762
1773
  });
1763
1774
  }
1764
- });
1775
+ }, listenOptions);
1765
1776
  log("LocalSend device lost listener registered");
1766
1777
  } catch (error) {
1767
1778
  log("Failed to setup LocalSend device lost listener:", error);
@@ -1776,7 +1787,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1776
1787
  timestamp: Date.now()
1777
1788
  });
1778
1789
  }
1779
- });
1790
+ }, listenOptions);
1780
1791
  log("LocalSend transfer request listener registered");
1781
1792
  } catch (error) {
1782
1793
  log("Failed to setup LocalSend transfer request listener:", error);
@@ -1791,7 +1802,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1791
1802
  timestamp: Date.now()
1792
1803
  });
1793
1804
  }
1794
- });
1805
+ }, listenOptions);
1795
1806
  log("LocalSend transfer progress listener registered");
1796
1807
  } catch (error) {
1797
1808
  log("Failed to setup LocalSend transfer progress listener:", error);
@@ -1806,7 +1817,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1806
1817
  timestamp: Date.now()
1807
1818
  });
1808
1819
  }
1809
- });
1820
+ }, listenOptions);
1810
1821
  log("LocalSend transfer complete listener registered");
1811
1822
  } catch (error) {
1812
1823
  log("Failed to setup LocalSend transfer complete listener:", error);
@@ -1821,13 +1832,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
1821
1832
  timestamp: Date.now()
1822
1833
  });
1823
1834
  }
1824
- });
1835
+ }, listenOptions);
1825
1836
  log("LocalSend transfer failed listener registered");
1826
1837
  } catch (error) {
1827
1838
  log("Failed to setup LocalSend transfer failed listener:", error);
1828
1839
  }
1829
1840
  }
1830
- async function initIframeMode(ctx, log, messageHandler, request) {
1841
+ async function initIframeMode(ctx, log, messageHandler) {
1831
1842
  if (!isInIframe()) {
1832
1843
  throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
1833
1844
  }
@@ -1849,10 +1860,7 @@ async function initIframeMode(ctx, log, messageHandler, request) {
1849
1860
  log("Extension info loaded from manifest:", ctx.state.extensionInfo);
1850
1861
  }
1851
1862
  sendDebugInfo(ctx.config);
1852
- const context = await request(EXTENSION_COMMANDS.getContext);
1853
- ctx.state.context = context;
1854
- log("Application context received:", context);
1855
- return { context, port };
1863
+ return port;
1856
1864
  }
1857
1865
  function waitForHostPortAsync(log) {
1858
1866
  return new Promise((resolve, reject) => {
@@ -2455,7 +2463,7 @@ var HaexVaultSdk = class {
2455
2463
  () => this._extensionInfo,
2456
2464
  this.handleEvent.bind(this)
2457
2465
  );
2458
- const { context, port } = await initIframeMode(
2466
+ const port = await initIframeMode(
2459
2467
  {
2460
2468
  config: this.config,
2461
2469
  state: {
@@ -2484,8 +2492,7 @@ var HaexVaultSdk = class {
2484
2492
  }
2485
2493
  },
2486
2494
  this.log.bind(this),
2487
- this.messageHandler,
2488
- this.request.bind(this)
2495
+ this.messageHandler
2489
2496
  );
2490
2497
  this.hostPort = port;
2491
2498
  if (this.config.manifest) {
@@ -2497,6 +2504,8 @@ var HaexVaultSdk = class {
2497
2504
  };
2498
2505
  this.notifySubscribersInternal();
2499
2506
  }
2507
+ const context = await this.request(EXTENSION_COMMANDS.getContext);
2508
+ this.log("Application context received:", context);
2500
2509
  this._context = context;
2501
2510
  this.isNativeWindow = false;
2502
2511
  this.initialized = true;