cwm-assistant 0.3.8 → 0.3.9

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.
@@ -2619,7 +2619,7 @@ var Type = type_exports2;
2619
2619
 
2620
2620
  // ../../packages/contracts/src/assistant.ts
2621
2621
  var ASSISTANT_PROTOCOL = 1;
2622
- var ASSISTANT_VERSION = "0.3.8";
2622
+ var ASSISTANT_VERSION = "0.3.9";
2623
2623
  var ASSISTANT_PORT = 46322;
2624
2624
 
2625
2625
  // ../../packages/contracts/src/index.ts
@@ -2754,6 +2754,33 @@ import path from "node:path";
2754
2754
  import { promisify } from "node:util";
2755
2755
  var execute = promisify(execFile);
2756
2756
  var xml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
2757
+ var vbs = (value) => '"' + value.replaceAll('"', '""') + '"';
2758
+ function writeWindowsLauncher(file, script) {
2759
+ fs.writeFileSync(file, "\uFEFF" + script, { encoding: "utf16le" });
2760
+ }
2761
+ function windowsLauncherScript(nodePath, entry, directory) {
2762
+ const quote = (value) => '"' + value + '"';
2763
+ const command = [quote(nodePath), quote(entry), "serve", "--state-dir", quote(directory)].join(
2764
+ " "
2765
+ );
2766
+ return [
2767
+ "' Starts the Workspace assistant with no console window. Written by cwm-assistant.",
2768
+ 'Set shell = CreateObject("WScript.Shell")',
2769
+ // The state directory, never the package: a live cwd inside the package blocks npm's rename.
2770
+ "shell.CurrentDirectory = " + vbs(directory),
2771
+ "code = shell.Run(" + vbs(command) + ", 0, True)",
2772
+ "WScript.Quit code",
2773
+ ""
2774
+ ].join("\r\n");
2775
+ }
2776
+ function windowsTaskXml(options) {
2777
+ return `\uFEFF<?xml version="1.0" encoding="UTF-16"?>
2778
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(options.user)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(options.user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(options.wscript)}</Command><Arguments>${xml(vbs(options.launcher))}</Arguments></Exec></Actions></Task>`;
2779
+ }
2780
+ function wscriptPath(env = process.env) {
2781
+ const systemRoot = (env.SystemRoot || env.windir || "C:\\Windows").replace(/[\\/]+$/, "");
2782
+ return systemRoot + "\\System32\\wscript.exe";
2783
+ }
2757
2784
  async function startAutostart() {
2758
2785
  if (process.platform === "darwin")
2759
2786
  await execute("launchctl", ["kickstart", `gui/${process.getuid()}/com.cwm.assistant`]);
@@ -2796,13 +2823,12 @@ async function configureAutostart(enable, directory, entry) {
2796
2823
  return;
2797
2824
  }
2798
2825
  const user = os.userInfo().username;
2826
+ const launcher = path.join(directory, "assistant-start.vbs");
2827
+ writeWindowsLauncher(launcher, windowsLauncherScript(process.execPath, entry, directory));
2799
2828
  const file = path.join(directory, "autostart.xml");
2800
- fs.writeFileSync(
2801
- file,
2802
- `\uFEFF<?xml version="1.0" encoding="UTF-16"?>
2803
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(user)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(process.execPath)}</Command><Arguments>&quot;${xml(entry)}&quot; serve --state-dir &quot;${xml(directory)}&quot;</Arguments></Exec></Actions></Task>`,
2804
- { encoding: "utf16le" }
2805
- );
2829
+ fs.writeFileSync(file, windowsTaskXml({ user, launcher, wscript: wscriptPath() }), {
2830
+ encoding: "utf16le"
2831
+ });
2806
2832
  await execute("schtasks.exe", ["/Create", "/TN", task, "/XML", file, "/F"]);
2807
2833
  await execute("schtasks.exe", ["/Run", "/TN", task]);
2808
2834
  } else throw new Error("\u81EA\u542F\u52A8\u4EC5\u652F\u6301 Windows \u548C macOS");
@@ -6595,4 +6621,4 @@ async function cli(args, entry) {
6595
6621
  export {
6596
6622
  cli
6597
6623
  };
6598
- //# sourceMappingURL=cli-TPXAFK3D.js.map
6624
+ //# sourceMappingURL=cli-SBBYCWZE.js.map