electrobun 0.0.13 → 0.0.15
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/api/browser/builtinrpcSchema.ts +10 -0
- package/dist/api/browser/index.ts +404 -0
- package/dist/api/browser/stylesAndElements.ts +3 -0
- package/dist/api/browser/webviewtag.ts +650 -0
- package/dist/api/bun/core/ApplicationMenu.ts +65 -0
- package/dist/api/bun/core/BrowserView.ts +402 -0
- package/dist/api/bun/core/BrowserWindow.ts +178 -0
- package/dist/api/bun/core/ContextMenu.ts +67 -0
- package/dist/api/bun/core/Paths.ts +5 -0
- package/dist/api/bun/core/Tray.ts +105 -0
- package/dist/api/bun/core/Updater.ts +387 -0
- package/dist/api/bun/core/Utils.ts +48 -0
- package/dist/api/bun/events/ApplicationEvents.ts +14 -0
- package/dist/api/bun/events/event.ts +29 -0
- package/dist/api/bun/events/eventEmitter.ts +45 -0
- package/dist/api/bun/events/trayEvents.ts +9 -0
- package/dist/api/bun/events/webviewEvents.ts +19 -0
- package/dist/api/bun/events/windowEvents.ts +12 -0
- package/dist/api/bun/index.ts +42 -0
- package/dist/api/bun/proc/zig.ts +618 -0
- package/dist/bsdiff +0 -0
- package/dist/bspatch +0 -0
- package/dist/electrobun +0 -0
- package/dist/extractor +0 -0
- package/dist/launcher +0 -0
- package/dist/webview +0 -0
- package/package.json +8 -12
- package/dist/api/browser/index.js +0 -833
- package/dist/api/bun/index.js +0 -9239
|
@@ -1,833 +0,0 @@
|
|
|
1
|
-
// node_modules/rpc-anywhere/dist/esm/rpc.js
|
|
2
|
-
function missingTransportMethodError(methods, action) {
|
|
3
|
-
const methodsString = methods.map((method) => `"${method}"`).join(", ");
|
|
4
|
-
return new Error(`This RPC instance cannot ${action} because the transport did not provide one or more of these methods: ${methodsString}`);
|
|
5
|
-
}
|
|
6
|
-
function _createRPC(options = {}) {
|
|
7
|
-
let debugHooks = {};
|
|
8
|
-
function _setDebugHooks(newDebugHooks) {
|
|
9
|
-
debugHooks = newDebugHooks;
|
|
10
|
-
}
|
|
11
|
-
let transport = {};
|
|
12
|
-
function setTransport(newTransport) {
|
|
13
|
-
if (transport.unregisterHandler)
|
|
14
|
-
transport.unregisterHandler();
|
|
15
|
-
transport = newTransport;
|
|
16
|
-
transport.registerHandler?.(handler);
|
|
17
|
-
}
|
|
18
|
-
let requestHandler = undefined;
|
|
19
|
-
function setRequestHandler(handler2) {
|
|
20
|
-
if (typeof handler2 === "function") {
|
|
21
|
-
requestHandler = handler2;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
requestHandler = (method, params) => {
|
|
25
|
-
const handlerFn = handler2[method];
|
|
26
|
-
if (handlerFn)
|
|
27
|
-
return handlerFn(params);
|
|
28
|
-
const fallbackHandler = handler2._;
|
|
29
|
-
if (!fallbackHandler)
|
|
30
|
-
throw new Error(`The requested method has no handler: ${method}`);
|
|
31
|
-
return fallbackHandler(method, params);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
const { maxRequestTime = DEFAULT_MAX_REQUEST_TIME } = options;
|
|
35
|
-
if (options.transport)
|
|
36
|
-
setTransport(options.transport);
|
|
37
|
-
if (options.requestHandler)
|
|
38
|
-
setRequestHandler(options.requestHandler);
|
|
39
|
-
if (options._debugHooks)
|
|
40
|
-
_setDebugHooks(options._debugHooks);
|
|
41
|
-
let lastRequestId = 0;
|
|
42
|
-
function getRequestId() {
|
|
43
|
-
if (lastRequestId <= MAX_ID)
|
|
44
|
-
return ++lastRequestId;
|
|
45
|
-
return lastRequestId = 0;
|
|
46
|
-
}
|
|
47
|
-
const requestListeners = new Map;
|
|
48
|
-
const requestTimeouts = new Map;
|
|
49
|
-
function requestFn(method, ...args) {
|
|
50
|
-
const params = args[0];
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
if (!transport.send)
|
|
53
|
-
throw missingTransportMethodError(["send"], "make requests");
|
|
54
|
-
const requestId = getRequestId();
|
|
55
|
-
const request2 = {
|
|
56
|
-
type: "request",
|
|
57
|
-
id: requestId,
|
|
58
|
-
method,
|
|
59
|
-
params
|
|
60
|
-
};
|
|
61
|
-
requestListeners.set(requestId, { resolve, reject });
|
|
62
|
-
if (maxRequestTime !== Infinity)
|
|
63
|
-
requestTimeouts.set(requestId, setTimeout(() => {
|
|
64
|
-
requestTimeouts.delete(requestId);
|
|
65
|
-
reject(new Error("RPC request timed out."));
|
|
66
|
-
}, maxRequestTime));
|
|
67
|
-
debugHooks.onSend?.(request2);
|
|
68
|
-
transport.send(request2);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const request = new Proxy(requestFn, {
|
|
72
|
-
get: (target, prop, receiver) => {
|
|
73
|
-
if (prop in target)
|
|
74
|
-
return Reflect.get(target, prop, receiver);
|
|
75
|
-
return (params) => requestFn(prop, params);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const requestProxy = request;
|
|
79
|
-
function sendFn(message, ...args) {
|
|
80
|
-
const payload = args[0];
|
|
81
|
-
if (!transport.send)
|
|
82
|
-
throw missingTransportMethodError(["send"], "send messages");
|
|
83
|
-
const rpcMessage = {
|
|
84
|
-
type: "message",
|
|
85
|
-
id: message,
|
|
86
|
-
payload
|
|
87
|
-
};
|
|
88
|
-
debugHooks.onSend?.(rpcMessage);
|
|
89
|
-
transport.send(rpcMessage);
|
|
90
|
-
}
|
|
91
|
-
const send = new Proxy(sendFn, {
|
|
92
|
-
get: (target, prop, receiver) => {
|
|
93
|
-
if (prop in target)
|
|
94
|
-
return Reflect.get(target, prop, receiver);
|
|
95
|
-
return (payload) => sendFn(prop, payload);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const sendProxy = send;
|
|
99
|
-
const messageListeners = new Map;
|
|
100
|
-
const wildcardMessageListeners = new Set;
|
|
101
|
-
function addMessageListener(message, listener) {
|
|
102
|
-
if (!transport.registerHandler)
|
|
103
|
-
throw missingTransportMethodError(["registerHandler"], "register message listeners");
|
|
104
|
-
if (message === "*") {
|
|
105
|
-
wildcardMessageListeners.add(listener);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (!messageListeners.has(message))
|
|
109
|
-
messageListeners.set(message, new Set);
|
|
110
|
-
messageListeners.get(message)?.add(listener);
|
|
111
|
-
}
|
|
112
|
-
function removeMessageListener(message, listener) {
|
|
113
|
-
if (message === "*") {
|
|
114
|
-
wildcardMessageListeners.delete(listener);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
messageListeners.get(message)?.delete(listener);
|
|
118
|
-
if (messageListeners.get(message)?.size === 0)
|
|
119
|
-
messageListeners.delete(message);
|
|
120
|
-
}
|
|
121
|
-
async function handler(message) {
|
|
122
|
-
debugHooks.onReceive?.(message);
|
|
123
|
-
if (!("type" in message))
|
|
124
|
-
throw new Error("Message does not contain a type.");
|
|
125
|
-
if (message.type === "request") {
|
|
126
|
-
if (!transport.send || !requestHandler)
|
|
127
|
-
throw missingTransportMethodError(["send", "requestHandler"], "handle requests");
|
|
128
|
-
const { id, method, params } = message;
|
|
129
|
-
let response;
|
|
130
|
-
try {
|
|
131
|
-
response = {
|
|
132
|
-
type: "response",
|
|
133
|
-
id,
|
|
134
|
-
success: true,
|
|
135
|
-
payload: await requestHandler(method, params)
|
|
136
|
-
};
|
|
137
|
-
} catch (error) {
|
|
138
|
-
if (!(error instanceof Error))
|
|
139
|
-
throw error;
|
|
140
|
-
response = {
|
|
141
|
-
type: "response",
|
|
142
|
-
id,
|
|
143
|
-
success: false,
|
|
144
|
-
error: error.message
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
debugHooks.onSend?.(response);
|
|
148
|
-
transport.send(response);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (message.type === "response") {
|
|
152
|
-
const timeout = requestTimeouts.get(message.id);
|
|
153
|
-
if (timeout != null)
|
|
154
|
-
clearTimeout(timeout);
|
|
155
|
-
const { resolve, reject } = requestListeners.get(message.id) ?? {};
|
|
156
|
-
if (!message.success)
|
|
157
|
-
reject?.(new Error(message.error));
|
|
158
|
-
else
|
|
159
|
-
resolve?.(message.payload);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (message.type === "message") {
|
|
163
|
-
for (const listener of wildcardMessageListeners)
|
|
164
|
-
listener(message.id, message.payload);
|
|
165
|
-
const listeners = messageListeners.get(message.id);
|
|
166
|
-
if (!listeners)
|
|
167
|
-
return;
|
|
168
|
-
for (const listener of listeners)
|
|
169
|
-
listener(message.payload);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
throw new Error(`Unexpected RPC message type: ${message.type}`);
|
|
173
|
-
}
|
|
174
|
-
const proxy = { send: sendProxy, request: requestProxy };
|
|
175
|
-
return {
|
|
176
|
-
setTransport,
|
|
177
|
-
setRequestHandler,
|
|
178
|
-
request,
|
|
179
|
-
requestProxy,
|
|
180
|
-
send,
|
|
181
|
-
sendProxy,
|
|
182
|
-
addMessageListener,
|
|
183
|
-
removeMessageListener,
|
|
184
|
-
proxy,
|
|
185
|
-
_setDebugHooks
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
var MAX_ID = 10000000000;
|
|
189
|
-
var DEFAULT_MAX_REQUEST_TIME = 1000;
|
|
190
|
-
|
|
191
|
-
// node_modules/rpc-anywhere/dist/esm/create-rpc.js
|
|
192
|
-
function createRPC(options) {
|
|
193
|
-
return _createRPC(options);
|
|
194
|
-
}
|
|
195
|
-
// src/browser/webviewtag.ts
|
|
196
|
-
var ConfigureWebviewTags = (enableWebviewTags, zigRpc, syncRpc) => {
|
|
197
|
-
if (!enableWebviewTags) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
class WebviewTag extends HTMLElement {
|
|
202
|
-
webviewId;
|
|
203
|
-
zigRpc;
|
|
204
|
-
syncRpc;
|
|
205
|
-
maskSelectors = new Set;
|
|
206
|
-
resizeObserver;
|
|
207
|
-
positionCheckLoop;
|
|
208
|
-
positionCheckLoopReset;
|
|
209
|
-
lastRect = {
|
|
210
|
-
x: 0,
|
|
211
|
-
y: 0,
|
|
212
|
-
width: 0,
|
|
213
|
-
height: 0
|
|
214
|
-
};
|
|
215
|
-
lastMasksJSON = "";
|
|
216
|
-
lastMasks = [];
|
|
217
|
-
transparent = false;
|
|
218
|
-
passthroughEnabled = false;
|
|
219
|
-
hidden = false;
|
|
220
|
-
delegateMode = false;
|
|
221
|
-
hiddenMirrorMode = false;
|
|
222
|
-
wasZeroRect = false;
|
|
223
|
-
isMirroring = false;
|
|
224
|
-
partition = null;
|
|
225
|
-
constructor() {
|
|
226
|
-
super();
|
|
227
|
-
this.zigRpc = zigRpc;
|
|
228
|
-
this.syncRpc = syncRpc;
|
|
229
|
-
requestAnimationFrame(() => {
|
|
230
|
-
this.initWebview();
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
addMaskSelector(selector) {
|
|
234
|
-
this.maskSelectors.add(selector);
|
|
235
|
-
this.syncDimensions();
|
|
236
|
-
}
|
|
237
|
-
removeMaskSelector(selector) {
|
|
238
|
-
this.maskSelectors.delete(selector);
|
|
239
|
-
this.syncDimensions();
|
|
240
|
-
}
|
|
241
|
-
initWebview() {
|
|
242
|
-
const rect = this.getBoundingClientRect();
|
|
243
|
-
this.lastRect = rect;
|
|
244
|
-
const webviewId = this.syncRpc({
|
|
245
|
-
method: "webviewTagInit",
|
|
246
|
-
params: {
|
|
247
|
-
hostWebviewId: window.__electrobunWebviewId,
|
|
248
|
-
windowId: window.__electrobunWindowId,
|
|
249
|
-
url: this.src || this.getAttribute("src") || null,
|
|
250
|
-
html: this.html || this.getAttribute("html") || null,
|
|
251
|
-
preload: this.preload || this.getAttribute("preload") || null,
|
|
252
|
-
partition: this.partition || this.getAttribute("partition") || null,
|
|
253
|
-
frame: {
|
|
254
|
-
width: rect.width,
|
|
255
|
-
height: rect.height,
|
|
256
|
-
x: rect.x,
|
|
257
|
-
y: rect.y
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
this.webviewId = webviewId;
|
|
262
|
-
this.id = `electrobun-webview-${webviewId}`;
|
|
263
|
-
this.setAttribute("id", this.id);
|
|
264
|
-
}
|
|
265
|
-
asyncResolvers = {};
|
|
266
|
-
callAsyncJavaScript({ script }) {
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
const messageId = "" + Date.now() + Math.random();
|
|
269
|
-
this.asyncResolvers[messageId] = {
|
|
270
|
-
resolve,
|
|
271
|
-
reject
|
|
272
|
-
};
|
|
273
|
-
this.zigRpc.request.webviewTagCallAsyncJavaScript({
|
|
274
|
-
messageId,
|
|
275
|
-
webviewId: this.webviewId,
|
|
276
|
-
hostWebviewId: window.__electrobunWebviewId,
|
|
277
|
-
script
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
setCallAsyncJavaScriptResponse(messageId, response) {
|
|
282
|
-
const resolvers = this.asyncResolvers[messageId];
|
|
283
|
-
delete this.asyncResolvers[messageId];
|
|
284
|
-
try {
|
|
285
|
-
response = JSON.parse(response);
|
|
286
|
-
if (response.result) {
|
|
287
|
-
resolvers.resolve(response.result);
|
|
288
|
-
} else {
|
|
289
|
-
resolvers.reject(response.error);
|
|
290
|
-
}
|
|
291
|
-
} catch (e) {
|
|
292
|
-
resolvers.reject(e.message);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
async canGoBack() {
|
|
296
|
-
const {
|
|
297
|
-
payload: { webviewTagCanGoBackResponse }
|
|
298
|
-
} = await this.zigRpc.request.webviewTagCanGoBack({ id: this.webviewId });
|
|
299
|
-
return webviewTagCanGoBackResponse;
|
|
300
|
-
}
|
|
301
|
-
async canGoForward() {
|
|
302
|
-
const {
|
|
303
|
-
payload: { webviewTagCanGoForwardResponse }
|
|
304
|
-
} = await this.zigRpc.request.webviewTagCanGoForward({
|
|
305
|
-
id: this.webviewId
|
|
306
|
-
});
|
|
307
|
-
return webviewTagCanGoForwardResponse;
|
|
308
|
-
}
|
|
309
|
-
updateAttr(name, value) {
|
|
310
|
-
if (value) {
|
|
311
|
-
this.setAttribute(name, value);
|
|
312
|
-
} else {
|
|
313
|
-
this.removeAttribute(name);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
get src() {
|
|
317
|
-
return this.getAttribute("src");
|
|
318
|
-
}
|
|
319
|
-
set src(value) {
|
|
320
|
-
this.updateAttr("src", value);
|
|
321
|
-
}
|
|
322
|
-
get html() {
|
|
323
|
-
return this.getAttribute("html");
|
|
324
|
-
}
|
|
325
|
-
set html(value) {
|
|
326
|
-
this.updateAttr("html", value);
|
|
327
|
-
}
|
|
328
|
-
get preload() {
|
|
329
|
-
return this.getAttribute("preload");
|
|
330
|
-
}
|
|
331
|
-
set preload(value) {
|
|
332
|
-
this.updateAttr("preload", value);
|
|
333
|
-
}
|
|
334
|
-
adjustDimensionsForHiddenMirrorMode(rect) {
|
|
335
|
-
if (this.hiddenMirrorMode) {
|
|
336
|
-
rect.x = 0 - rect.width;
|
|
337
|
-
}
|
|
338
|
-
return rect;
|
|
339
|
-
}
|
|
340
|
-
on(event, listener) {
|
|
341
|
-
this.addEventListener(event, listener);
|
|
342
|
-
}
|
|
343
|
-
off(event, listener) {
|
|
344
|
-
this.removeEventListener(event, listener);
|
|
345
|
-
}
|
|
346
|
-
emit(event, detail) {
|
|
347
|
-
this.dispatchEvent(new CustomEvent(event, { detail }));
|
|
348
|
-
}
|
|
349
|
-
syncDimensions(force = false) {
|
|
350
|
-
if (!this.webviewId || !force && this.hidden) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
const rect = this.getBoundingClientRect();
|
|
354
|
-
const { x, y, width, height } = this.adjustDimensionsForHiddenMirrorMode(rect);
|
|
355
|
-
const lastRect = this.lastRect;
|
|
356
|
-
if (width === 0 && height === 0) {
|
|
357
|
-
if (this.wasZeroRect === false) {
|
|
358
|
-
this.wasZeroRect = true;
|
|
359
|
-
this.toggleHidden(true, true);
|
|
360
|
-
}
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const masks = [];
|
|
364
|
-
this.maskSelectors.forEach((selector) => {
|
|
365
|
-
const els = document.querySelectorAll(selector);
|
|
366
|
-
for (let i = 0;i < els.length; i++) {
|
|
367
|
-
const el = els[i];
|
|
368
|
-
if (el) {
|
|
369
|
-
const maskRect = el.getBoundingClientRect();
|
|
370
|
-
masks.push({
|
|
371
|
-
x: maskRect.x - x,
|
|
372
|
-
y: maskRect.y - y,
|
|
373
|
-
width: maskRect.width,
|
|
374
|
-
height: maskRect.height
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
const masksJson = masks.length ? JSON.stringify(masks) : "";
|
|
380
|
-
if (force || lastRect.x !== x || lastRect.y !== y || lastRect.width !== width || lastRect.height !== height || this.lastMasksJSON !== masksJson) {
|
|
381
|
-
this.setPositionCheckLoop(true);
|
|
382
|
-
this.lastRect = rect;
|
|
383
|
-
this.lastMasks = masks;
|
|
384
|
-
this.lastMasksJSON = masksJson;
|
|
385
|
-
this.zigRpc.send.webviewTagResize({
|
|
386
|
-
id: this.webviewId,
|
|
387
|
-
frame: {
|
|
388
|
-
width,
|
|
389
|
-
height,
|
|
390
|
-
x,
|
|
391
|
-
y
|
|
392
|
-
},
|
|
393
|
-
masks: masksJson
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
if (this.wasZeroRect) {
|
|
397
|
-
this.wasZeroRect = false;
|
|
398
|
-
this.toggleHidden(false, true);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
boundSyncDimensions = () => this.syncDimensions();
|
|
402
|
-
boundForceSyncDimensions = () => this.syncDimensions(true);
|
|
403
|
-
setPositionCheckLoop(accelerate = false) {
|
|
404
|
-
if (this.positionCheckLoop) {
|
|
405
|
-
clearInterval(this.positionCheckLoop);
|
|
406
|
-
this.positionCheckLoop = undefined;
|
|
407
|
-
}
|
|
408
|
-
if (this.positionCheckLoopReset) {
|
|
409
|
-
clearTimeout(this.positionCheckLoopReset);
|
|
410
|
-
this.positionCheckLoopReset = undefined;
|
|
411
|
-
}
|
|
412
|
-
const delay = accelerate ? 0 : 300;
|
|
413
|
-
if (accelerate) {
|
|
414
|
-
this.positionCheckLoopReset = setTimeout(() => {
|
|
415
|
-
this.setPositionCheckLoop(false);
|
|
416
|
-
}, 2000);
|
|
417
|
-
}
|
|
418
|
-
this.positionCheckLoop = setInterval(() => this.syncDimensions(), delay);
|
|
419
|
-
}
|
|
420
|
-
connectedCallback() {
|
|
421
|
-
this.setPositionCheckLoop();
|
|
422
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
423
|
-
this.syncDimensions();
|
|
424
|
-
});
|
|
425
|
-
window.addEventListener("resize", this.boundForceSyncDimensions);
|
|
426
|
-
window.addEventListener("scroll", this.boundSyncDimensions);
|
|
427
|
-
}
|
|
428
|
-
disconnectedCallback() {
|
|
429
|
-
clearInterval(this.positionCheckLoop);
|
|
430
|
-
this.resizeObserver?.disconnect();
|
|
431
|
-
window.removeEventListener("resize", this.boundForceSyncDimensions);
|
|
432
|
-
window.removeEventListener("scroll", this.boundSyncDimensions);
|
|
433
|
-
this.zigRpc.send.webviewTagRemove({ id: this.webviewId });
|
|
434
|
-
}
|
|
435
|
-
static get observedAttributes() {
|
|
436
|
-
return ["src", "html", "preload", "class", "style"];
|
|
437
|
-
}
|
|
438
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
439
|
-
if (name === "src" && oldValue !== newValue) {
|
|
440
|
-
this.updateIFrameSrc(newValue);
|
|
441
|
-
} else if (name === "html" && oldValue !== newValue) {
|
|
442
|
-
this.updateIFrameHtml(newValue);
|
|
443
|
-
} else if (name === "preload" && oldValue !== newValue) {
|
|
444
|
-
this.updateIFramePreload(newValue);
|
|
445
|
-
} else {
|
|
446
|
-
this.syncDimensions();
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
updateIFrameSrc(src) {
|
|
450
|
-
if (!this.webviewId) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
this.zigRpc.send.webviewTagUpdateSrc({
|
|
454
|
-
id: this.webviewId,
|
|
455
|
-
url: src
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
updateIFrameHtml(html) {
|
|
459
|
-
if (!this.webviewId) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
this.zigRpc.send.webviewTagUpdateHtml({
|
|
463
|
-
id: this.webviewId,
|
|
464
|
-
html
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
updateIFramePreload(preload) {
|
|
468
|
-
if (!this.webviewId) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
this.zigRpc.send.webviewTagUpdatePreload({
|
|
472
|
-
id: this.webviewId,
|
|
473
|
-
preload
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
goBack() {
|
|
477
|
-
this.zigRpc.send.webviewTagGoBack({ id: this.webviewId });
|
|
478
|
-
}
|
|
479
|
-
goForward() {
|
|
480
|
-
this.zigRpc.send.webviewTagGoForward({ id: this.webviewId });
|
|
481
|
-
}
|
|
482
|
-
reload() {
|
|
483
|
-
this.zigRpc.send.webviewTagReload({ id: this.webviewId });
|
|
484
|
-
}
|
|
485
|
-
loadURL(url) {
|
|
486
|
-
this.setAttribute("src", url);
|
|
487
|
-
this.zigRpc.send.webviewTagUpdateSrc({
|
|
488
|
-
id: this.webviewId,
|
|
489
|
-
url
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
syncScreenshot(callback) {
|
|
493
|
-
const cacheBustString = `?${Date.now()}`;
|
|
494
|
-
const url = `views://screenshot/${this.webviewId}${cacheBustString}`;
|
|
495
|
-
const img = new Image;
|
|
496
|
-
img.src = url;
|
|
497
|
-
img.onload = () => {
|
|
498
|
-
this.style.backgroundImage = `url(${url})`;
|
|
499
|
-
if (callback) {
|
|
500
|
-
setTimeout(callback, 100);
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
DEFAULT_FRAME_RATE = Math.round(1000 / 30);
|
|
505
|
-
streamScreenInterval;
|
|
506
|
-
startMirroringToDom(frameRate = this.DEFAULT_FRAME_RATE) {
|
|
507
|
-
if (this.streamScreenInterval) {
|
|
508
|
-
clearInterval(this.streamScreenInterval);
|
|
509
|
-
}
|
|
510
|
-
this.streamScreenInterval = setInterval(() => {
|
|
511
|
-
this.syncScreenshot();
|
|
512
|
-
}, frameRate);
|
|
513
|
-
}
|
|
514
|
-
stopMirroringToDom() {
|
|
515
|
-
if (this.streamScreenInterval) {
|
|
516
|
-
clearInterval(this.streamScreenInterval);
|
|
517
|
-
this.streamScreenInterval = undefined;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
startMirroring() {
|
|
521
|
-
return;
|
|
522
|
-
if (this.isMirroring === false) {
|
|
523
|
-
this.isMirroring = true;
|
|
524
|
-
this.zigRpc.send.webviewTagToggleMirroring({
|
|
525
|
-
id: this.webviewId,
|
|
526
|
-
enable: true
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
stopMirroring() {
|
|
531
|
-
return;
|
|
532
|
-
if (this.isMirroring === true) {
|
|
533
|
-
this.isMirroring = false;
|
|
534
|
-
this.zigRpc.send.webviewTagToggleMirroring({
|
|
535
|
-
id: this.webviewId,
|
|
536
|
-
enable: false
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
clearScreenImage() {
|
|
541
|
-
this.style.backgroundImage = "";
|
|
542
|
-
}
|
|
543
|
-
tryClearScreenImage() {
|
|
544
|
-
if (!this.transparent && !this.hiddenMirrorMode && !this.delegateMode && !this.hidden) {
|
|
545
|
-
this.clearScreenImage();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
toggleTransparent(transparent, bypassState) {
|
|
549
|
-
if (!bypassState) {
|
|
550
|
-
if (typeof transparent === "undefined") {
|
|
551
|
-
this.transparent = !this.transparent;
|
|
552
|
-
} else {
|
|
553
|
-
this.transparent = transparent;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (!this.transparent && !transparent) {
|
|
557
|
-
this.tryClearScreenImage();
|
|
558
|
-
}
|
|
559
|
-
this.zigRpc.send.webviewTagSetTransparent({
|
|
560
|
-
id: this.webviewId,
|
|
561
|
-
transparent: this.transparent || Boolean(transparent)
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
togglePassthrough(enablePassthrough, bypassState) {
|
|
565
|
-
if (!bypassState) {
|
|
566
|
-
if (typeof enablePassthrough === "undefined") {
|
|
567
|
-
this.passthroughEnabled = !this.passthroughEnabled;
|
|
568
|
-
} else {
|
|
569
|
-
this.passthroughEnabled = enablePassthrough;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
this.zigRpc.send.webviewTagSetPassthrough({
|
|
573
|
-
id: this.webviewId,
|
|
574
|
-
enablePassthrough: this.passthroughEnabled || Boolean(enablePassthrough)
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
toggleHidden(hidden, bypassState) {
|
|
578
|
-
if (!bypassState) {
|
|
579
|
-
if (typeof hidden === "undefined") {
|
|
580
|
-
this.hidden = !this.hidden;
|
|
581
|
-
} else {
|
|
582
|
-
this.hidden = hidden;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
this.zigRpc.send.webviewTagSetHidden({
|
|
586
|
-
id: this.webviewId,
|
|
587
|
-
hidden: this.hidden || Boolean(hidden)
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
toggleDelegateMode(delegateMode) {
|
|
591
|
-
const _newDelegateMode = typeof delegateMode === "undefined" ? !this.delegateMode : delegateMode;
|
|
592
|
-
if (_newDelegateMode) {
|
|
593
|
-
this.syncScreenshot(() => {
|
|
594
|
-
this.delegateMode = true;
|
|
595
|
-
this.toggleTransparent(true, true);
|
|
596
|
-
this.startMirroringToDom();
|
|
597
|
-
});
|
|
598
|
-
} else {
|
|
599
|
-
this.delegateMode = false;
|
|
600
|
-
this.stopMirroringToDom();
|
|
601
|
-
this.toggleTransparent(this.transparent);
|
|
602
|
-
this.tryClearScreenImage();
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
toggleHiddenMirrorMode(force) {
|
|
606
|
-
const enable = typeof force === "undefined" ? !this.hiddenMirrorMode : force;
|
|
607
|
-
if (enable === true) {
|
|
608
|
-
this.syncScreenshot(() => {
|
|
609
|
-
this.hiddenMirrorMode = true;
|
|
610
|
-
this.toggleHidden(true, true);
|
|
611
|
-
this.togglePassthrough(true, true);
|
|
612
|
-
this.startMirroringToDom();
|
|
613
|
-
});
|
|
614
|
-
} else {
|
|
615
|
-
this.stopMirroringToDom();
|
|
616
|
-
this.toggleHidden(this.hidden);
|
|
617
|
-
this.togglePassthrough(this.passthroughEnabled);
|
|
618
|
-
this.tryClearScreenImage();
|
|
619
|
-
this.hiddenMirrorMode = false;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
customElements.define("electrobun-webview", WebviewTag);
|
|
624
|
-
insertWebviewTagNormalizationStyles();
|
|
625
|
-
};
|
|
626
|
-
var insertWebviewTagNormalizationStyles = () => {
|
|
627
|
-
var style = document.createElement("style");
|
|
628
|
-
style.type = "text/css";
|
|
629
|
-
var css = `
|
|
630
|
-
electrobun-webview {
|
|
631
|
-
display: block;
|
|
632
|
-
width: 800px;
|
|
633
|
-
height: 300px;
|
|
634
|
-
background: #fff;
|
|
635
|
-
background-repeat: no-repeat!important;
|
|
636
|
-
overflow: hidden;
|
|
637
|
-
}
|
|
638
|
-
`;
|
|
639
|
-
style.appendChild(document.createTextNode(css));
|
|
640
|
-
var head = document.getElementsByTagName("head")[0];
|
|
641
|
-
if (!head) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
if (head.firstChild) {
|
|
645
|
-
head.insertBefore(style, head.firstChild);
|
|
646
|
-
} else {
|
|
647
|
-
head.appendChild(style);
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
// src/browser/stylesAndElements.ts
|
|
652
|
-
var isAppRegionDrag = (e) => {
|
|
653
|
-
return e.target?.classList.contains("electrobun-webkit-app-region-drag");
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
// src/browser/index.ts
|
|
657
|
-
var WEBVIEW_ID = window.__electrobunWebviewId;
|
|
658
|
-
|
|
659
|
-
class Electroview {
|
|
660
|
-
rpc;
|
|
661
|
-
rpcHandler;
|
|
662
|
-
zigRpc;
|
|
663
|
-
zigRpcHandler;
|
|
664
|
-
syncRpc = () => {
|
|
665
|
-
console.log("syncRpc not initialized");
|
|
666
|
-
};
|
|
667
|
-
constructor(config) {
|
|
668
|
-
this.rpc = config.rpc;
|
|
669
|
-
this.init();
|
|
670
|
-
}
|
|
671
|
-
init() {
|
|
672
|
-
this.initZigRpc();
|
|
673
|
-
if (true) {
|
|
674
|
-
this.syncRpc = (msg) => {
|
|
675
|
-
try {
|
|
676
|
-
const messageString = JSON.stringify(msg);
|
|
677
|
-
return this.bunBridgeSync(messageString);
|
|
678
|
-
} catch (error) {
|
|
679
|
-
console.error("bun: failed to serialize message to webview syncRpc", error);
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
ConfigureWebviewTags(true, this.zigRpc, this.syncRpc);
|
|
684
|
-
this.initElectrobunListeners();
|
|
685
|
-
window.__electrobun = {
|
|
686
|
-
receiveMessageFromBun: this.receiveMessageFromBun.bind(this),
|
|
687
|
-
receiveMessageFromZig: this.receiveMessageFromZig.bind(this)
|
|
688
|
-
};
|
|
689
|
-
if (this.rpc) {
|
|
690
|
-
this.rpc.setTransport(this.createTransport());
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
initZigRpc() {
|
|
694
|
-
this.zigRpc = createRPC({
|
|
695
|
-
transport: this.createZigTransport(),
|
|
696
|
-
maxRequestTime: 1000
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
receiveMessageFromZig(msg) {
|
|
700
|
-
if (this.zigRpcHandler) {
|
|
701
|
-
this.zigRpcHandler(msg);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
sendToZig(message) {
|
|
705
|
-
window.webkit.messageHandlers.webviewTagBridge.postMessage(JSON.stringify(message));
|
|
706
|
-
}
|
|
707
|
-
initElectrobunListeners() {
|
|
708
|
-
document.addEventListener("mousedown", (e) => {
|
|
709
|
-
if (isAppRegionDrag(e)) {
|
|
710
|
-
this.zigRpc?.send.startWindowMove({ id: WEBVIEW_ID });
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
document.addEventListener("mouseup", (e) => {
|
|
714
|
-
if (isAppRegionDrag(e)) {
|
|
715
|
-
this.zigRpc?.send.stopWindowMove({ id: WEBVIEW_ID });
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
createTransport() {
|
|
720
|
-
const that = this;
|
|
721
|
-
return {
|
|
722
|
-
send(message) {
|
|
723
|
-
try {
|
|
724
|
-
const messageString = JSON.stringify(message);
|
|
725
|
-
that.bunBridge(messageString);
|
|
726
|
-
} catch (error) {
|
|
727
|
-
console.error("bun: failed to serialize message to webview", error);
|
|
728
|
-
}
|
|
729
|
-
},
|
|
730
|
-
registerHandler(handler) {
|
|
731
|
-
that.rpcHandler = handler;
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
createZigTransport() {
|
|
736
|
-
const that = this;
|
|
737
|
-
return {
|
|
738
|
-
send(message) {
|
|
739
|
-
window.webkit.messageHandlers.webviewTagBridge.postMessage(JSON.stringify(message));
|
|
740
|
-
},
|
|
741
|
-
registerHandler(handler) {
|
|
742
|
-
that.zigRpcHandler = handler;
|
|
743
|
-
}
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
bunBridgeSync(msg) {
|
|
747
|
-
var xhr = new XMLHttpRequest;
|
|
748
|
-
xhr.open("POST", "views://syncrpc", false);
|
|
749
|
-
xhr.send(msg);
|
|
750
|
-
if (!xhr.responseText) {
|
|
751
|
-
return xhr.responseText;
|
|
752
|
-
}
|
|
753
|
-
try {
|
|
754
|
-
return JSON.parse(xhr.responseText);
|
|
755
|
-
} catch {
|
|
756
|
-
return xhr.responseText;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
bunBridge(msg) {
|
|
760
|
-
if (true) {
|
|
761
|
-
window.webkit.messageHandlers.bunBridge.postMessage(msg);
|
|
762
|
-
} else {
|
|
763
|
-
var xhr;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
receiveMessageFromBun(msg) {
|
|
767
|
-
if (this.rpcHandler) {
|
|
768
|
-
this.rpcHandler(msg);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
static defineRPC(config) {
|
|
772
|
-
const builtinHandlers = {
|
|
773
|
-
requests: {
|
|
774
|
-
evaluateJavascriptWithResponse: ({ script }) => {
|
|
775
|
-
return new Promise((resolve) => {
|
|
776
|
-
try {
|
|
777
|
-
const resultFunction = new Function(script);
|
|
778
|
-
const result = resultFunction();
|
|
779
|
-
if (result instanceof Promise) {
|
|
780
|
-
result.then((resolvedResult) => {
|
|
781
|
-
resolve(resolvedResult);
|
|
782
|
-
}).catch((error) => {
|
|
783
|
-
console.error("bun: async script execution failed", error);
|
|
784
|
-
resolve(String(error));
|
|
785
|
-
});
|
|
786
|
-
} else {
|
|
787
|
-
resolve(result);
|
|
788
|
-
}
|
|
789
|
-
} catch (error) {
|
|
790
|
-
console.error("bun: failed to eval script", error);
|
|
791
|
-
resolve(String(error));
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
const rpcOptions = {
|
|
798
|
-
maxRequestTime: config.maxRequestTime,
|
|
799
|
-
requestHandler: {
|
|
800
|
-
...config.handlers.requests,
|
|
801
|
-
...builtinHandlers.requests
|
|
802
|
-
},
|
|
803
|
-
transport: {
|
|
804
|
-
registerHandler: () => {
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
const rpc = createRPC(rpcOptions);
|
|
809
|
-
const messageHandlers = config.handlers.messages;
|
|
810
|
-
if (messageHandlers) {
|
|
811
|
-
rpc.addMessageListener("*", (messageName, payload) => {
|
|
812
|
-
const globalHandler = messageHandlers["*"];
|
|
813
|
-
if (globalHandler) {
|
|
814
|
-
globalHandler(messageName, payload);
|
|
815
|
-
}
|
|
816
|
-
const messageHandler = messageHandlers[messageName];
|
|
817
|
-
if (messageHandler) {
|
|
818
|
-
messageHandler(payload);
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
return rpc;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
var Electrobun = {
|
|
826
|
-
Electroview
|
|
827
|
-
};
|
|
828
|
-
var browser_default = Electrobun;
|
|
829
|
-
export {
|
|
830
|
-
browser_default as default,
|
|
831
|
-
createRPC,
|
|
832
|
-
Electroview
|
|
833
|
-
};
|