electrobun 0.3.0-beta.0 → 0.4.0-beta.0

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.
@@ -97,14 +97,25 @@ const startRPCServer = () => {
97
97
  }
98
98
  },
99
99
  close(ws, code, reason) {
100
+ if (!ws?.data) {
101
+ return;
102
+ }
100
103
  const { webviewId } = ws.data;
101
104
  console.log("Closed:", webviewId, code, reason);
102
- socketMap[webviewId].socket = null;
105
+ if (socketMap[webviewId]) {
106
+ socketMap[webviewId].socket = null;
107
+ }
103
108
  },
104
109
 
105
110
  message(ws, message) {
111
+ if (!ws?.data) {
112
+ return;
113
+ }
106
114
  const { webviewId } = ws.data;
107
115
  const browserView = BrowserView.getById(webviewId);
116
+ if (!browserView) {
117
+ return;
118
+ }
108
119
 
109
120
  if (browserView.rpcHandler) {
110
121
  if (typeof message === "string") {
@@ -9,4 +9,5 @@ export default {
9
9
  >("resize", data),
10
10
  move: (data) =>
11
11
  new ElectrobunEvent<{ id: number; x: number; y: number }, {}>("move", data),
12
+ focus: (data) => new ElectrobunEvent<{ id: number }, {}>("focus", data),
12
13
  };
@@ -69,13 +69,13 @@ export const native = (() => {
69
69
  args: [
70
70
  FFIType.u32, // windowId
71
71
  FFIType.f64, FFIType.f64, // x, y
72
- FFIType.f64, FFIType.f64, // width, height
73
- FFIType.u32, // styleMask
72
+ FFIType.f64, FFIType.f64, // width, height
73
+ FFIType.u32, // styleMask
74
74
  FFIType.cstring, // titleBarStyle
75
75
  FFIType.function, // closeHandler
76
76
  FFIType.function, // moveHandler
77
- FFIType.function // resizeHandler
78
-
77
+ FFIType.function, // resizeHandler
78
+ FFIType.function // focusHandler
79
79
  ],
80
80
  returns: FFIType.ptr
81
81
  },
@@ -388,16 +388,17 @@ export const ffi = {
388
388
  )
389
389
 
390
390
  const windowPtr = native.symbols.createWindowWithFrameAndStyleFromWorker(
391
- id,
391
+ id,
392
392
  // frame
393
- x, y, width, height,
393
+ x, y, width, height,
394
394
  styleMask,
395
395
  // style
396
396
  toCString(titleBarStyle),
397
397
  // callbacks
398
398
  windowCloseCallback,
399
399
  windowMoveCallback,
400
- windowResizeCallback,
400
+ windowResizeCallback,
401
+ windowFocusCallback,
401
402
  );
402
403
 
403
404
 
@@ -930,6 +931,26 @@ const windowResizeCallback = new JSCallback(
930
931
  }
931
932
  );
932
933
 
934
+ const windowFocusCallback = new JSCallback(
935
+ (id) => {
936
+ const handler = electrobunEventEmitter.events.window.focus;
937
+ const event = handler({
938
+ id,
939
+ });
940
+
941
+ let result;
942
+ // global event
943
+ result = electrobunEventEmitter.emitEvent(event);
944
+
945
+ result = electrobunEventEmitter.emitEvent(event, id);
946
+ },
947
+ {
948
+ args: ["u32"],
949
+ returns: "void",
950
+ threadsafe: true,
951
+ }
952
+ );
953
+
933
954
  const getMimeType = new JSCallback((filePath) => {
934
955
  const _filePath = new CString(filePath).toString();
935
956
  const mimeType = Bun.file(_filePath).type;// || "application/octet-stream";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.4.0-beta.0",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",