bunite-core 0.0.1 → 0.0.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.
Files changed (39) hide show
  1. package/package.json +2 -2
  2. package/src/bun/core/App.ts +155 -15
  3. package/src/bun/core/BrowserView.ts +124 -44
  4. package/src/bun/core/BrowserWindow.ts +94 -47
  5. package/src/bun/core/Socket.ts +2 -1
  6. package/src/bun/core/SurfaceBrowserIPC.ts +65 -0
  7. package/src/bun/core/SurfaceManager.ts +201 -0
  8. package/src/bun/core/SurfaceRegistry.ts +60 -0
  9. package/src/bun/core/Utils.ts +275 -46
  10. package/src/bun/events/appEvents.ts +2 -1
  11. package/src/bun/events/webviewEvents.ts +1 -3
  12. package/src/bun/events/windowEvents.ts +2 -0
  13. package/src/bun/index.ts +4 -3
  14. package/src/bun/preload/inline.ts +19 -25
  15. package/src/bun/proc/native.ts +158 -122
  16. package/src/native/shared/callbacks.h +6 -6
  17. package/src/native/shared/ffi_exports.h +123 -119
  18. package/src/native/shared/log.h +24 -0
  19. package/src/native/shared/webview_storage.h +5 -5
  20. package/src/native/win/native_host_appres.cpp +258 -0
  21. package/src/native/win/native_host_cef.cpp +834 -0
  22. package/src/native/win/native_host_ffi.cpp +935 -0
  23. package/src/native/win/native_host_internal.h +285 -0
  24. package/src/native/win/native_host_runtime.cpp +286 -0
  25. package/src/native/win/native_host_utils.cpp +314 -0
  26. package/src/native/win/process_helper_win.cpp +126 -26
  27. package/src/preload/runtime.built.js +1 -1
  28. package/src/preload/runtime.ts +65 -42
  29. package/src/preload/tsconfig.json +2 -1
  30. package/src/preload/tsconfig.tsbuildinfo +1 -0
  31. package/src/preload/webviewElement.ts +307 -0
  32. package/src/shared/cefVersion.ts +2 -0
  33. package/src/shared/log.ts +40 -0
  34. package/src/shared/paths.ts +122 -52
  35. package/src/shared/rpc.ts +7 -1
  36. package/src/view/index.ts +8 -5
  37. package/src/native/shared/cef_response_filter.h +0 -116
  38. package/src/native/win/native_host.cpp +0 -2453
  39. package/src/types/config.ts +0 -29
package/src/view/index.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  type RPCWithTransport
9
9
  } from "../shared/rpc";
10
10
  import { decodeRPCPacket, encodeRPCPacket } from "../shared/rpcWire";
11
+ import { log } from "../shared/log";
11
12
 
12
13
  type BuniteWindowGlobals = Window &
13
14
  typeof globalThis & {
@@ -49,7 +50,7 @@ export class BuniteView<T extends RPCWithTransport> {
49
50
 
50
51
  initSocketToBun() {
51
52
  if (WEBVIEW_ID == null || RPC_SOCKET_PORT == null) {
52
- console.warn("[bunite] Preload globals are missing. BuniteView will stay disconnected until native preload wiring is implemented.");
53
+ log.warn("Preload globals are missing. BuniteView will stay disconnected until native preload wiring is implemented.");
53
54
  return;
54
55
  }
55
56
 
@@ -79,7 +80,7 @@ export class BuniteView<T extends RPCWithTransport> {
79
80
  try {
80
81
  const decrypt = buniteWindow.__bunite_decrypt;
81
82
  if (!decrypt) {
82
- console.error("[bunite] No decrypt function available in preload globals");
83
+ log.error("No decrypt function available in preload globals");
83
84
  return;
84
85
  }
85
86
  const decrypted = await decrypt(binaryMessage);
@@ -90,7 +91,7 @@ export class BuniteView<T extends RPCWithTransport> {
90
91
  }
91
92
  this.rpcHandler?.(packet);
92
93
  } catch (error) {
93
- console.error("[bunite] Failed to parse message from Bun", error);
94
+ log.error("Failed to parse message from Bun", error);
94
95
  }
95
96
  });
96
97
  }
@@ -113,7 +114,7 @@ export class BuniteView<T extends RPCWithTransport> {
113
114
  send: (message) => {
114
115
  if (this.bunSocket?.readyState === WebSocket.OPEN) {
115
116
  void this.bunBridge(message).catch((error) => {
116
- console.error("[bunite] Failed to send RPC packet", error);
117
+ log.error("Failed to send RPC packet", error);
117
118
  });
118
119
  }
119
120
  },
@@ -137,7 +138,7 @@ export class BuniteView<T extends RPCWithTransport> {
137
138
 
138
139
  const encrypt = buniteWindow.__bunite_encrypt;
139
140
  if (!encrypt) {
140
- console.error("[bunite] No encrypt function available in preload globals");
141
+ log.error("No encrypt function available in preload globals");
141
142
  return;
142
143
  }
143
144
 
@@ -152,6 +153,8 @@ export class BuniteView<T extends RPCWithTransport> {
152
153
  }
153
154
  }
154
155
 
156
+ export { log, type LogLevel } from "../shared/log";
157
+
155
158
  export type {
156
159
  BuniteRPCConfig,
157
160
  BuniteRPCSchema,
@@ -1,116 +0,0 @@
1
- #pragma once
2
-
3
- #include <algorithm>
4
- #include <cctype>
5
- #include <cstring>
6
- #include <string>
7
-
8
- class BuniteResponseFilter : public CefResponseFilter {
9
- public:
10
- explicit BuniteResponseFilter(std::string script)
11
- : script_(std::move(script)) {}
12
-
13
- bool InitFilter() override {
14
- buffer_.clear();
15
- output_offset_ = 0;
16
- injected_ = false;
17
- return true;
18
- }
19
-
20
- FilterStatus Filter(
21
- void* data_in,
22
- size_t data_in_size,
23
- size_t& data_in_read,
24
- void* data_out,
25
- size_t data_out_size,
26
- size_t& data_out_written
27
- ) override {
28
- if (data_in_size > 0) {
29
- buffer_.append(static_cast<const char*>(data_in), data_in_size);
30
- data_in_read = data_in_size;
31
- } else {
32
- data_in_read = 0;
33
- }
34
-
35
- if (!injected_) {
36
- tryInject();
37
- if (!injected_ && data_in_size == 0 && !script_.empty() && output_offset_ == 0) {
38
- buffer_.insert(0, "<script>\n" + escapeInlineScript(script_) + "\n</script>\n");
39
- injected_ = true;
40
- }
41
- }
42
-
43
- const size_t remaining = buffer_.size() - output_offset_;
44
- const size_t copy_size = std::min(remaining, data_out_size);
45
- if (copy_size > 0) {
46
- std::memcpy(data_out, buffer_.data() + output_offset_, copy_size);
47
- output_offset_ += copy_size;
48
- }
49
- data_out_written = copy_size;
50
-
51
- if (data_in_size == 0 && output_offset_ >= buffer_.size()) {
52
- return RESPONSE_FILTER_DONE;
53
- }
54
- return RESPONSE_FILTER_NEED_MORE_DATA;
55
- }
56
-
57
- private:
58
- static std::string lowercase(std::string value) {
59
- std::transform(
60
- value.begin(),
61
- value.end(),
62
- value.begin(),
63
- [](unsigned char ch) { return static_cast<char>(std::tolower(ch)); }
64
- );
65
- return value;
66
- }
67
-
68
- static std::string escapeInlineScript(const std::string& script) {
69
- std::string escaped = script;
70
- std::string::size_type offset = 0;
71
- while ((offset = escaped.find("</script", offset)) != std::string::npos) {
72
- escaped.replace(offset, 8, "<\\/script");
73
- offset += 9;
74
- }
75
- return escaped;
76
- }
77
-
78
- void tryInject() {
79
- if (injected_ || script_.empty()) {
80
- return;
81
- }
82
-
83
- const std::string lowered = lowercase(buffer_);
84
- std::string tag = "<script>\n" + escapeInlineScript(script_) + "\n</script>\n";
85
-
86
- auto inject_after = [&](const std::string& token) -> bool {
87
- const auto start = lowered.find(token);
88
- if (start == std::string::npos) {
89
- return false;
90
- }
91
- const auto end = buffer_.find('>', start);
92
- if (end == std::string::npos) {
93
- return false;
94
- }
95
- buffer_.insert(end + 1, tag);
96
- injected_ = true;
97
- return true;
98
- };
99
-
100
- if (inject_after("<head") || inject_after("<html")) {
101
- return;
102
- }
103
-
104
- if (buffer_.size() > 1024 && output_offset_ == 0) {
105
- buffer_.insert(0, tag);
106
- injected_ = true;
107
- }
108
- }
109
-
110
- std::string script_;
111
- std::string buffer_;
112
- size_t output_offset_ = 0;
113
- bool injected_ = false;
114
-
115
- IMPLEMENT_REFCOUNTING(BuniteResponseFilter);
116
- };