unity-hub-cli 0.7.0 → 0.8.0

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/index.js +43 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -72,9 +72,10 @@ var LaunchProjectUseCase = class {
72
72
  }
73
73
  };
74
74
  var TerminateProjectUseCase = class {
75
- constructor(unityProcessReader, unityProcessTerminator) {
75
+ constructor(unityProcessReader, unityProcessTerminator, unityTempDirectoryCleaner) {
76
76
  this.unityProcessReader = unityProcessReader;
77
77
  this.unityProcessTerminator = unityProcessTerminator;
78
+ this.unityTempDirectoryCleaner = unityTempDirectoryCleaner;
78
79
  }
79
80
  async execute(project) {
80
81
  const unityProcess = await this.unityProcessReader.findByProjectPath(project.path);
@@ -84,13 +85,21 @@ var TerminateProjectUseCase = class {
84
85
  message: "No Unity process is running for this project."
85
86
  };
86
87
  }
87
- const terminated = await this.unityProcessTerminator.terminate(unityProcess);
88
- if (!terminated) {
88
+ const termination = await this.unityProcessTerminator.terminate(unityProcess);
89
+ if (!termination.terminated) {
89
90
  return {
90
91
  terminated: false,
91
92
  message: "Failed to terminate the Unity process."
92
93
  };
93
94
  }
95
+ if (termination.stage === "sigterm" || termination.stage === "sigkill") {
96
+ try {
97
+ await this.unityTempDirectoryCleaner.clean(project.path);
98
+ } catch (error) {
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ console.error(`Failed to clean Temp directory after termination: ${message}`);
101
+ }
102
+ }
94
103
  return {
95
104
  terminated: true
96
105
  };
@@ -436,6 +445,8 @@ var PROCESS_LIST_ARGS = ["-axo", "pid=,command=", "-ww"];
436
445
  var PROCESS_LIST_COMMAND = "ps";
437
446
  var TERMINATE_TIMEOUT_MILLIS = 5e3;
438
447
  var TERMINATE_POLL_INTERVAL_MILLIS = 200;
448
+ var GRACEFUL_QUIT_TIMEOUT_MILLIS = 3e3;
449
+ var GRACEFUL_QUIT_POLL_INTERVAL_MILLIS = 200;
439
450
  var delay = async (duration) => {
440
451
  await new Promise((resolveDelay) => {
441
452
  setTimeout(() => {
@@ -535,11 +546,33 @@ var MacUnityProcessReader = class {
535
546
  };
536
547
  var MacUnityProcessTerminator = class {
537
548
  async terminate(unityProcess) {
549
+ let attemptedGraceful = false;
550
+ if (process.platform === "darwin") {
551
+ attemptedGraceful = true;
552
+ try {
553
+ const script = [
554
+ 'tell application "System Events"',
555
+ ` set frontmost of (first process whose unix id is ${unityProcess.pid}) to true`,
556
+ ' keystroke "q" using {command down}',
557
+ "end tell"
558
+ ].join("\n");
559
+ await execFileAsync2("osascript", ["-e", script]);
560
+ const deadlineGraceful = Date.now() + GRACEFUL_QUIT_TIMEOUT_MILLIS;
561
+ while (Date.now() < deadlineGraceful) {
562
+ await delay(GRACEFUL_QUIT_POLL_INTERVAL_MILLIS);
563
+ const alive = ensureProcessAlive(unityProcess.pid);
564
+ if (!alive) {
565
+ return { terminated: true, stage: "graceful" };
566
+ }
567
+ }
568
+ } catch {
569
+ }
570
+ }
538
571
  try {
539
572
  process.kill(unityProcess.pid, "SIGTERM");
540
573
  } catch (error) {
541
574
  if (isProcessMissingError(error)) {
542
- return false;
575
+ return { terminated: true, stage: attemptedGraceful ? "graceful" : "sigterm" };
543
576
  }
544
577
  throw new Error(
545
578
  `Failed to terminate the Unity process (PID: ${unityProcess.pid}): ${error instanceof Error ? error.message : String(error)}`
@@ -550,21 +583,22 @@ var MacUnityProcessTerminator = class {
550
583
  await delay(TERMINATE_POLL_INTERVAL_MILLIS);
551
584
  const alive = ensureProcessAlive(unityProcess.pid);
552
585
  if (!alive) {
553
- return true;
586
+ return { terminated: true, stage: "sigterm" };
554
587
  }
555
588
  }
556
589
  try {
557
590
  process.kill(unityProcess.pid, "SIGKILL");
558
591
  } catch (error) {
559
592
  if (isProcessMissingError(error)) {
560
- return true;
593
+ return { terminated: true, stage: "sigkill" };
561
594
  }
562
595
  throw new Error(
563
596
  `Failed to forcefully terminate the Unity process (PID: ${unityProcess.pid}): ${error instanceof Error ? error.message : String(error)}`
564
597
  );
565
598
  }
566
599
  await delay(TERMINATE_POLL_INTERVAL_MILLIS);
567
- return !ensureProcessAlive(unityProcess.pid);
600
+ const aliveAfterKill = ensureProcessAlive(unityProcess.pid);
601
+ return aliveAfterKill ? { terminated: false } : { terminated: true, stage: "sigkill" };
568
602
  }
569
603
  };
570
604
 
@@ -1194,7 +1228,8 @@ var bootstrap = async () => {
1194
1228
  );
1195
1229
  const terminateProjectUseCase = new TerminateProjectUseCase(
1196
1230
  unityProcessReader,
1197
- unityProcessTerminator
1231
+ unityProcessTerminator,
1232
+ unityTempDirectoryCleaner
1198
1233
  );
1199
1234
  const useGitRootName = !process2.argv.includes("--no-git-root-name");
1200
1235
  const showBranch = !process2.argv.includes("--hide-branch");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unity-hub-cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "A CLI tool that reads Unity Hub's projects and launches Unity Editor with an interactive TUI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {