electrobun 0.0.4 → 0.0.5

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.
package/dist/webview CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",
@@ -241,24 +241,32 @@ class Electroview<T> {
241
241
  }
242
242
 
243
243
  bunBridge(msg: string) {
244
- // Note: zig sets up this custom message handler bridge
245
- window.webkit.messageHandlers.bunBridge.postMessage(msg);
246
- }
247
-
248
- bunBridgeWithReply(msg: string) {
249
- // Note: zig sets up this custom message handler bridge
250
- // Note: Since post message is async in the browser context and bun will reply async
251
- // We're using postMessage handler (via bunBridge above) without a reply, and then letting bun reply
252
- // via pipesin and evaluateJavascript.
253
- // addScriptMessageHandlerWithReply is just here as reference and for future use cases.
254
- return window.webkit.messageHandlers.bunBridgeWithReply.postMessage(msg);
244
+ // Note: messageHandlers seem to freeze when sending large messages
245
+ // but xhr to views://rpc can run into CORS issues on non views://
246
+ // loaded content (eg: when writing extensions/preload scripts for
247
+ // remote content).
248
+
249
+ // Since most messages--especially those on remote content, are small
250
+ // we can solve most use cases by having a fallback to xhr for
251
+ // large messages
252
+
253
+ // TEMP: disable the fallback for now. for some reason suddenly can't
254
+ // repro now that other places are chunking messages and laptop restart
255
+ if (true || msg.length < 8 * 1024) {
256
+ window.webkit.messageHandlers.bunBridge.postMessage(msg);
257
+ } else {
258
+ var xhr = new XMLHttpRequest();
259
+
260
+ // Note: we're only using synchronouse http on this async
261
+ // call to get around CORS for now
262
+ // Note: DO NOT use postMessage handlers since it
263
+ // freezes the process when sending lots of large messages
264
+
265
+ xhr.open("POST", "views://rpc", false); // sychronous call
266
+ xhr.send(msg);
267
+ }
255
268
  }
256
269
 
257
- // webviewTagBridge(msg) {
258
- // // Note: zig sets up this custom message handler bridge
259
- // window.webkit.messageHandlers.webviewTagBridge.postMessage(msg);
260
- // }
261
-
262
270
  receiveMessageFromBun(msg) {
263
271
  // NOTE: in the webview messages are passed by executing ElectrobunView.receiveMessageFromBun(object)
264
272
  // so they're already parsed into an object here
@@ -239,7 +239,6 @@ const ConfigureWebviewTags = (
239
239
  if (this.wasZeroRect === false) {
240
240
  this.wasZeroRect = true;
241
241
  this.toggleHidden(true, true);
242
- this.stopMirroring();
243
242
  }
244
243
  return;
245
244
  }
@@ -338,59 +337,6 @@ const ConfigureWebviewTags = (
338
337
  this.positionCheckLoop = setInterval(() => this.syncDimensions(), delay);
339
338
  }
340
339
 
341
- // The global document mousemove will fire even when the mouse is over
342
- // an OOPIF that's layered above this host webview. The two edge cases we
343
- // solve for are:
344
- // 1. dragging an element on the host over or dropping on the webview anchor
345
- // 2. clicking on an element that's "layered over" the OOPIF visually but really uses a
346
- // mask to make a section transparent. We want the underlying overlay UI to be
347
- // interactive not the OOPIF.
348
- //
349
- // Solution: Have mirroing on by default.
350
- // 1. mouse move events don't fire during drag. So the OOPIF remains non-interactive
351
- // and effectively passes through to the host's anchor element underneath letting you
352
- // react to drag events on the host as needed.
353
- // 2. Detect when the mouse is moving over the anchor and turn mirroring off to make
354
- // it interactive. Unless the mouse is over a masked area in which case we want to
355
- // keep it non-interactive and pass through to the host "overylay UI".
356
- handleDocumentMouseMove(e: MouseEvent) {
357
- if (this.hidden) {
358
- return;
359
- }
360
-
361
- const isInBounds =
362
- e.clientX >= this.lastRect.x &&
363
- e.clientX <= this.lastRect.x + this.lastRect.width &&
364
- e.clientY >= this.lastRect.y &&
365
- e.clientY <= this.lastRect.y + this.lastRect.height;
366
-
367
- if (isInBounds) {
368
- const isInMaskBounds = this.lastMasks.find((mask) => {
369
- // we send relative x/y to objc but here we need the clientX/Y
370
- // to compare against. consider doing the opposite or storing both.
371
- const clientX = this.lastRect.x + mask.x;
372
- const clientY = this.lastRect.y + mask.y;
373
- const isInMaskBounds =
374
- e.clientX >= clientX &&
375
- e.clientX <= clientX + mask.width &&
376
- e.clientY <= clientY + mask.height &&
377
- e.clientY >= clientY;
378
-
379
- return isInMaskBounds;
380
- });
381
- if (isInMaskBounds) {
382
- this.startMirroring();
383
- } else {
384
- this.stopMirroring();
385
- }
386
- } else {
387
- this.startMirroring();
388
- }
389
- }
390
-
391
- boundhandleDocumentMouseMove = (e: MouseEvent) =>
392
- this.handleDocumentMouseMove(e);
393
-
394
340
  connectedCallback() {
395
341
  this.setPositionCheckLoop();
396
342
 
@@ -404,13 +350,6 @@ const ConfigureWebviewTags = (
404
350
  // otherwise it'll move around unexpectedly.
405
351
  window.addEventListener("resize", this.boundForceSyncDimensions);
406
352
  window.addEventListener("scroll", this.boundSyncDimensions);
407
- // Note: mousemove won't fire during a drag so we get that behaviour
408
- // for free without doing calculations.
409
- document.addEventListener(
410
- "mousemove",
411
- this.boundhandleDocumentMouseMove,
412
- true
413
- );
414
353
 
415
354
  // todo: For chromium webviews (windows native or chromium bundled)
416
355
  // should be able to use performanceObservers on layout-shift to
@@ -420,17 +359,12 @@ const ConfigureWebviewTags = (
420
359
  disconnectedCallback() {
421
360
  // removed from the dom
422
361
  clearInterval(this.positionCheckLoop);
423
- this.stopMirroring();
424
362
 
425
363
  this.resizeObserver?.disconnect();
426
364
  // this.intersectionObserver?.disconnect();
427
365
  // this.mutationObserver?.disconnect();
428
366
  window.removeEventListener("resize", this.boundForceSyncDimensions);
429
367
  window.removeEventListener("scroll", this.boundSyncDimensions);
430
- document.removeEventListener(
431
- "mousemove",
432
- this.boundhandleDocumentMouseMove
433
- );
434
368
  this.zigRpc.send.webviewTagRemove({ id: this.webviewId });
435
369
  }
436
370
 
@@ -539,6 +473,11 @@ const ConfigureWebviewTags = (
539
473
  }
540
474
 
541
475
  startMirroring() {
476
+ // TEMP: mirroring now happens automatically in objc
477
+ // when the mouse moves. I'm leaving this here for now
478
+ // because I suspect there may still be use cases to
479
+ // toggle it from the dom outside of the mouse moving.
480
+ return;
542
481
  if (this.isMirroring === false) {
543
482
  this.isMirroring = true;
544
483
  this.zigRpc.send.webviewTagToggleMirroring({
@@ -549,6 +488,7 @@ const ConfigureWebviewTags = (
549
488
  }
550
489
 
551
490
  stopMirroring() {
491
+ return;
552
492
  if (this.isMirroring === true) {
553
493
  this.isMirroring = false;
554
494
  this.zigRpc.send.webviewTagToggleMirroring({
@@ -16,7 +16,7 @@ import type { BuiltinBunToWebviewSchema } from "../../browser/builtinrpcSchema";
16
16
  const BrowserViewMap = {};
17
17
  let nextWebviewId = 1;
18
18
 
19
- const CHUNK_SIZE = 4096; // 4KB
19
+ const CHUNK_SIZE = 1024 * 4; // 4KB
20
20
 
21
21
  type BrowserViewOptions<T = undefined> = {
22
22
  url: string | null;
Binary file
Binary file