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/dist/main.js CHANGED
@@ -7,8 +7,9 @@ import { dlopen, suffix, ptr, toArrayBuffer } from "bun:ffi";
7
7
  import { existsSync, writeFileSync } from "fs";
8
8
  import { tmpdir } from "os";
9
9
  var pathToMacOS = dirname(process.argv0);
10
- var libPath = join(pathToMacOS, `libNativeWrapper.${suffix}`);
11
- var absoluteLibPath = resolve(libPath);
10
+ var coreLibFileName = process.platform === "win32" ? "ElectrobunCore.dll" : `libElectrobunCore.${suffix}`;
11
+ var coreLibPath = join(pathToMacOS, coreLibFileName);
12
+ var absoluteCoreLibPath = resolve(coreLibPath);
12
13
  function main() {
13
14
  let channel = "";
14
15
  let identifier = "";
@@ -58,31 +59,31 @@ function main() {
58
59
  if (!process.env["LD_LIBRARY_PATH"]?.includes(".")) {
59
60
  process.env["LD_LIBRARY_PATH"] = `.${process.env["LD_LIBRARY_PATH"] ? ":" + process.env["LD_LIBRARY_PATH"] : ""}`;
60
61
  }
61
- lib = dlopen(libPath, {
62
- startEventLoop: {
63
- args: ["cstring", "cstring", "cstring"],
64
- returns: "void"
62
+ lib = dlopen(coreLibPath, {
63
+ electrobun_core_run_main_thread: {
64
+ args: ["cstring", "cstring", "cstring", "i32"],
65
+ returns: "i32"
65
66
  },
66
- forceExit: {
67
- args: ["i32"],
68
- returns: "void"
67
+ electrobun_core_last_error: {
68
+ args: [],
69
+ returns: "cstring"
69
70
  }
70
71
  });
71
72
  } catch (error) {
72
- console.error(`[LAUNCHER] Failed to load library: ${error.message}`);
73
+ console.error(`[LAUNCHER] Failed to load ElectrobunCore: ${error.message}`);
73
74
  try {
74
- lib = dlopen(absoluteLibPath, {
75
- startEventLoop: {
76
- args: ["cstring", "cstring", "cstring"],
77
- returns: "void"
75
+ lib = dlopen(absoluteCoreLibPath, {
76
+ electrobun_core_run_main_thread: {
77
+ args: ["cstring", "cstring", "cstring", "i32"],
78
+ returns: "i32"
78
79
  },
79
- forceExit: {
80
- args: ["i32"],
81
- returns: "void"
80
+ electrobun_core_last_error: {
81
+ args: [],
82
+ returns: "cstring"
82
83
  }
83
84
  });
84
85
  } catch (absError) {
85
- console.error(`[LAUNCHER] Library loading failed. Try running: ldd ${libPath}`);
86
+ console.error(`[LAUNCHER] Core library loading failed. Try running: ldd ${coreLibPath}`);
86
87
  throw error;
87
88
  }
88
89
  }
@@ -97,8 +98,7 @@ function main() {
97
98
  let asarLibPath;
98
99
  let asarLib;
99
100
  if (process.platform === "win32") {
100
- asarLibPath = libPath;
101
- console.log(`[LAUNCHER] Using native wrapper's ASAR reader: ${asarLibPath}`);
101
+ asarLibPath = join(pathToMacOS, "libasar.dll");
102
102
  } else {
103
103
  asarLibPath = join(pathToMacOS, `libasar.${suffix}`);
104
104
  }
@@ -158,7 +158,11 @@ ${fileData.toString("utf8")}
158
158
  process.on("SIGINT", () => {});
159
159
  process.on("SIGTERM", () => {});
160
160
  new Worker(appEntrypointPath, {});
161
- lib.symbols.startEventLoop(ptr(new Uint8Array(Buffer.from(identifier + "\x00", "utf8"))), ptr(new Uint8Array(Buffer.from(name + "\x00", "utf8"))), ptr(new Uint8Array(Buffer.from(channel + "\x00", "utf8"))));
162
- lib.symbols.forceExit(0);
161
+ const runStatus = lib.symbols.electrobun_core_run_main_thread(ptr(new Uint8Array(Buffer.from(identifier + "\x00", "utf8"))), ptr(new Uint8Array(Buffer.from(name + "\x00", "utf8"))), ptr(new Uint8Array(Buffer.from(channel + "\x00", "utf8"))), 0);
162
+ if (runStatus !== 0) {
163
+ const coreError = lib.symbols.electrobun_core_last_error();
164
+ console.error(`[LAUNCHER] ElectrobunCore failed: ${coreError ? coreError.toString() : "Unknown error"}`);
165
+ process.exit(runStatus);
166
+ }
163
167
  }
164
168
  main();