electrobun 1.18.1 → 1.18.4-beta.3
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/README.md +1 -0
- package/dist/api/bun/ElectrobunConfig.ts +20 -0
- package/dist/api/bun/core/BrowserView.ts +29 -47
- package/dist/api/bun/core/BrowserWindow.ts +14 -7
- package/dist/api/bun/core/BuildConfig.ts +31 -4
- package/dist/api/bun/core/GpuWindow.ts +13 -6
- package/dist/api/bun/core/Tray.ts +33 -32
- package/dist/api/bun/proc/native.ts +682 -655
- package/dist/main.js +26 -22
- package/dist/preload-full.js +885 -0
- package/dist/preload-sandboxed.js +111 -0
- package/dist/zig-sdk/electrobun.zig +1979 -0
- package/package.json +2 -3
- package/src/cli/index.ts +313 -135
- package/dist/api/bun/core/windowIds.ts +0 -5
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
(function(){// src/bun/preload/events.ts
|
|
2
|
+
function emitWebviewEvent(eventName, detail) {
|
|
3
|
+
setTimeout(() => {
|
|
4
|
+
const bridge = window.__electrobunEventBridge || window.__electrobunInternalBridge;
|
|
5
|
+
bridge?.postMessage(JSON.stringify({
|
|
6
|
+
id: "webviewEvent",
|
|
7
|
+
type: "message",
|
|
8
|
+
payload: {
|
|
9
|
+
id: window.__electrobunWebviewId,
|
|
10
|
+
eventName,
|
|
11
|
+
detail
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function initLifecycleEvents() {
|
|
17
|
+
window.addEventListener("load", () => {
|
|
18
|
+
if (window === window.top) {
|
|
19
|
+
emitWebviewEvent("dom-ready", document.location.href);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
window.addEventListener("popstate", () => {
|
|
23
|
+
emitWebviewEvent("did-navigate-in-page", window.location.href);
|
|
24
|
+
});
|
|
25
|
+
window.addEventListener("hashchange", () => {
|
|
26
|
+
emitWebviewEvent("did-navigate-in-page", window.location.href);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var cmdKeyHeld = false;
|
|
30
|
+
var cmdKeyTimestamp = 0;
|
|
31
|
+
var CMD_KEY_THRESHOLD_MS = 500;
|
|
32
|
+
function isCmdHeld() {
|
|
33
|
+
if (cmdKeyHeld)
|
|
34
|
+
return true;
|
|
35
|
+
return Date.now() - cmdKeyTimestamp < CMD_KEY_THRESHOLD_MS && cmdKeyTimestamp > 0;
|
|
36
|
+
}
|
|
37
|
+
function initCmdClickHandling() {
|
|
38
|
+
window.addEventListener("keydown", (event) => {
|
|
39
|
+
if (event.key === "Meta" || event.metaKey) {
|
|
40
|
+
cmdKeyHeld = true;
|
|
41
|
+
cmdKeyTimestamp = Date.now();
|
|
42
|
+
}
|
|
43
|
+
}, true);
|
|
44
|
+
window.addEventListener("keyup", (event) => {
|
|
45
|
+
if (event.key === "Meta") {
|
|
46
|
+
cmdKeyHeld = false;
|
|
47
|
+
cmdKeyTimestamp = Date.now();
|
|
48
|
+
}
|
|
49
|
+
}, true);
|
|
50
|
+
window.addEventListener("blur", () => {
|
|
51
|
+
cmdKeyHeld = false;
|
|
52
|
+
});
|
|
53
|
+
window.addEventListener("click", (event) => {
|
|
54
|
+
if (event.metaKey || event.ctrlKey) {
|
|
55
|
+
const anchor = event.target?.closest?.("a");
|
|
56
|
+
if (anchor && anchor.href) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
event.stopPropagation();
|
|
59
|
+
event.stopImmediatePropagation();
|
|
60
|
+
emitWebviewEvent("new-window-open", JSON.stringify({
|
|
61
|
+
url: anchor.href,
|
|
62
|
+
isCmdClick: true,
|
|
63
|
+
isSPANavigation: false
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, true);
|
|
68
|
+
}
|
|
69
|
+
function initSPANavigationInterception() {
|
|
70
|
+
const originalPushState = history.pushState;
|
|
71
|
+
const originalReplaceState = history.replaceState;
|
|
72
|
+
history.pushState = function(state, title, url) {
|
|
73
|
+
if (isCmdHeld() && url) {
|
|
74
|
+
const resolvedUrl = new URL(String(url), window.location.href).href;
|
|
75
|
+
emitWebviewEvent("new-window-open", JSON.stringify({
|
|
76
|
+
url: resolvedUrl,
|
|
77
|
+
isCmdClick: true,
|
|
78
|
+
isSPANavigation: true
|
|
79
|
+
}));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return originalPushState.apply(this, [state, title, url]);
|
|
83
|
+
};
|
|
84
|
+
history.replaceState = function(state, title, url) {
|
|
85
|
+
if (isCmdHeld() && url) {
|
|
86
|
+
const resolvedUrl = new URL(String(url), window.location.href).href;
|
|
87
|
+
emitWebviewEvent("new-window-open", JSON.stringify({
|
|
88
|
+
url: resolvedUrl,
|
|
89
|
+
isCmdClick: true,
|
|
90
|
+
isSPANavigation: true
|
|
91
|
+
}));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return originalReplaceState.apply(this, [state, title, url]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function initOverscrollPrevention() {
|
|
98
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
99
|
+
const style = document.createElement("style");
|
|
100
|
+
style.type = "text/css";
|
|
101
|
+
style.appendChild(document.createTextNode("html, body { overscroll-behavior: none; }"));
|
|
102
|
+
document.head.appendChild(style);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/bun/preload/index-sandboxed.ts
|
|
107
|
+
initLifecycleEvents();
|
|
108
|
+
initCmdClickHandling();
|
|
109
|
+
initSPANavigationInterception();
|
|
110
|
+
initOverscrollPrevention();
|
|
111
|
+
})();
|