@yetech/estra7ah 3.3.5 → 3.3.7

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 (2) hide show
  1. package/dist/estra7ah.js +39 -13
  2. package/package.json +1 -1
package/dist/estra7ah.js CHANGED
@@ -319,29 +319,55 @@ async function downloadRunner() {
319
319
  }
320
320
 
321
321
  // Start the runner executable
322
+ let runnerStarted = false;
322
323
  function startRunner() {
323
- const runnerFile = getRunner();
324
- const runnerPath = `"${DIR_NAME}/${runnerFile}"`;
325
- const args = process.argv.slice(2);
326
- const options = { stdio: "inherit", shell: true };
324
+ // main() may fire this more than once (missing binary + update paths); the
325
+ // runner must only ever be launched once, or two processes fight for the ports.
326
+ if (runnerStarted) return;
327
+ runnerStarted = true;
328
+
329
+ const spawnOnce = () => {
330
+ const runnerFile = getRunner();
331
+ const absPath = `${DIR_NAME}/${runnerFile}`;
332
+ const args = process.argv.slice(2);
327
333
 
328
- setTimeout(() => {
329
334
  if (process.platform !== "win32") {
330
335
  try {
331
- fs.chmodSync(`${DIR_NAME}/${runnerFile}`, "755");
336
+ fs.chmodSync(absPath, "755");
332
337
  } catch (error) {
333
338
  console.error("Error setting permissions:", error.message);
334
339
  }
335
340
  }
336
341
 
337
- // .js runner (armv7) runs under the same Node that launched us
338
- const command = runnerFile.endsWith(".js") ? `"${process.execPath}"` : runnerPath;
339
- const commandArgs = runnerFile.endsWith(".js") ? [runnerPath, ...args] : args;
340
- const runnerProcess = child_process.spawn(command, commandArgs, options);
341
- runnerProcess.on("exit", (code) => {
342
- console.log(`Runner exited with code ${code}`);
342
+ // Spawn the binary directly (no shell) so its own path is the argv[0] — a
343
+ // shell wrapper would swallow exec failures as opaque /bin/sh errors. The
344
+ // .js runner (armv7, no pkg target) runs under the Node that launched us.
345
+ const isJs = runnerFile.endsWith(".js");
346
+ const command = isJs ? process.execPath : absPath;
347
+ const commandArgs = isJs ? [absPath, ...args] : args;
348
+
349
+ let runnerProcess;
350
+ try {
351
+ runnerProcess = child_process.spawn(command, commandArgs, { stdio: "inherit" });
352
+ } catch (error) {
353
+ console.error("Failed to spawn runner:", error.message);
354
+ return setTimeout(spawnOnce, 3000);
355
+ }
356
+
357
+ // Without this, a spawn failure surfaces as an uncaught exception instead
358
+ // of a handleable event.
359
+ runnerProcess.on("error", (error) => {
360
+ console.error("Runner spawn error:", error.message);
361
+ });
362
+ runnerProcess.on("exit", (code, signal) => {
363
+ console.log(`Runner exited with code ${code}${signal ? " (signal " + signal + ")" : ""}`);
364
+ // Keep the service alive: relaunch after a short backoff instead of
365
+ // leaving everything down until the next manual restart.
366
+ setTimeout(spawnOnce, 3000);
343
367
  });
344
- }, 1000);
368
+ };
369
+
370
+ setTimeout(spawnOnce, 1000);
345
371
  }
346
372
 
347
373
  // Main function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yetech/estra7ah",
3
- "version": "3.3.5",
3
+ "version": "3.3.7",
4
4
  "description": "Estra7ah Manager",
5
5
  "author": "Abdullah Al-taheri",
6
6
  "keywords": [