@patodo/localapp 0.2.1 → 0.2.6

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 (77) hide show
  1. package/.localapp-artifact.json +109 -109
  2. package/README.md +12 -2
  3. package/bin/localapp.mjs +645 -184
  4. package/package.json +1 -1
  5. package/runtime/native/adapter-manifest.json +10 -10
  6. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  7. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +57 -5
  8. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +2 -2
  9. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  10. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +57 -5
  11. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +2 -2
  12. package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +57 -5
  13. package/runtime/native/linux-x64/localapp-notifications +0 -0
  14. package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +57 -5
  15. package/runtime/native/win32-x64/localapp-native.exe +0 -0
  16. package/runtime/server/.localapp-server-runtime.json +59 -59
  17. package/runtime/server/bin/worker.cjs +110 -2
  18. package/runtime/server/web/404.html +1 -1
  19. package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-3252f21360e42fa1.js +1 -0
  20. package/runtime/server/web/_next/static/css/b8973d29c0d3fd9b.css +3 -0
  21. package/runtime/server/web/inbox.html +1 -1
  22. package/runtime/server/web/inbox.txt +2 -2
  23. package/runtime/server/web/index.html +1 -1
  24. package/runtime/server/web/index.txt +3 -3
  25. package/runtime/server/web/my/analytics.html +1 -1
  26. package/runtime/server/web/my/analytics.txt +2 -2
  27. package/runtime/server/web/my/apps/placeholder/settings.html +1 -1
  28. package/runtime/server/web/my/apps/placeholder/settings.txt +2 -2
  29. package/runtime/server/web/my/apps.html +1 -1
  30. package/runtime/server/web/my/apps.txt +2 -2
  31. package/runtime/server/web/my/dashboard.html +1 -1
  32. package/runtime/server/web/my/dashboard.txt +2 -2
  33. package/runtime/server/web/my/device-actions.html +1 -1
  34. package/runtime/server/web/my/device-actions.txt +2 -2
  35. package/runtime/server/web/my/device-notifications.html +1 -1
  36. package/runtime/server/web/my/device-notifications.txt +2 -2
  37. package/runtime/server/web/my/favorites.html +1 -1
  38. package/runtime/server/web/my/favorites.txt +2 -2
  39. package/runtime/server/web/my/groups.html +1 -1
  40. package/runtime/server/web/my/groups.txt +2 -2
  41. package/runtime/server/web/my/info.html +1 -1
  42. package/runtime/server/web/my/info.txt +2 -2
  43. package/runtime/server/web/my/keys.html +1 -1
  44. package/runtime/server/web/my/keys.txt +2 -2
  45. package/runtime/server/web/my/orgs.html +1 -1
  46. package/runtime/server/web/my/orgs.txt +2 -2
  47. package/runtime/server/web/my/pages.html +1 -1
  48. package/runtime/server/web/my/pages.txt +2 -2
  49. package/runtime/server/web/my/peers.html +1 -1
  50. package/runtime/server/web/my/peers.txt +2 -2
  51. package/runtime/server/web/my/recent.html +1 -1
  52. package/runtime/server/web/my/recent.txt +2 -2
  53. package/runtime/server/web/my/settings.html +1 -1
  54. package/runtime/server/web/my/settings.txt +2 -2
  55. package/runtime/server/web/my/studio.html +1 -1
  56. package/runtime/server/web/my/studio.txt +2 -2
  57. package/runtime/server/web/my/subscriptions.html +1 -1
  58. package/runtime/server/web/my/subscriptions.txt +2 -2
  59. package/runtime/server/web/my/system.html +1 -1
  60. package/runtime/server/web/my/system.txt +2 -2
  61. package/runtime/server/web/my/tasks.html +1 -1
  62. package/runtime/server/web/my/tasks.txt +2 -2
  63. package/runtime/server/web/my/users.html +1 -1
  64. package/runtime/server/web/my/users.txt +2 -2
  65. package/runtime/server/web/my.html +1 -1
  66. package/runtime/server/web/my.txt +2 -2
  67. package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -1
  68. package/runtime/server/web/platform-shell/placeholder/placeholder.txt +2 -2
  69. package/runtime/server/web/platform-shell-preview.html +1 -1
  70. package/runtime/server/web/platform-shell-preview.txt +2 -2
  71. package/runtime/server/web/setup.html +1 -1
  72. package/runtime/server/web/setup.txt +2 -2
  73. package/template/runtime/version.json +1 -1
  74. package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +0 -1
  75. package/runtime/server/web/_next/static/css/7618766dbe836b27.css +0 -3
  76. /package/runtime/server/web/_next/static/{GyUKT-hZbRN2iexOBXTTr → qBns-ZRUDtxsd4XX5SLLK}/_buildManifest.js +0 -0
  77. /package/runtime/server/web/_next/static/{GyUKT-hZbRN2iexOBXTTr → qBns-ZRUDtxsd4XX5SLLK}/_ssgManifest.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patodo/localapp",
3
- "version": "0.2.1",
3
+ "version": "0.2.6",
4
4
  "description": "LocalApp command-line interface",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  "assets": [
10
10
  {
11
11
  "path": "darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources",
12
- "sha256": "468fe8ef7e83d50e8c560ba645258933129c915074c43023ba933654a46f0c84"
12
+ "sha256": "7958c97b6933923ac7b2197e198b520ad4a4774aaa7989af9c67e58929bc161a"
13
13
  },
14
14
  {
15
15
  "path": "darwin-arm64/LocalAppBridge.app/Contents/Info.plist",
@@ -17,11 +17,11 @@
17
17
  },
18
18
  {
19
19
  "path": "darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge",
20
- "sha256": "e5b9c15347b42b51649881955de0dceb38b23bd0db44d3728fb9137d5d62a46a"
20
+ "sha256": "60733b88860386037af60573d5cb0740aea0db55080bd44ef9f000ab7c792eda"
21
21
  },
22
22
  {
23
23
  "path": "darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs",
24
- "sha256": "6b42a930a08c66ab7845704d61fbc48e5c569822618a0e6d5f20271c07bf3834"
24
+ "sha256": "0db7f7797997aadd4da471681d1cba98033339d30fab3aad60ae3f5f2c55d84c"
25
25
  }
26
26
  ]
27
27
  },
@@ -33,7 +33,7 @@
33
33
  "assets": [
34
34
  {
35
35
  "path": "darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources",
36
- "sha256": "468fe8ef7e83d50e8c560ba645258933129c915074c43023ba933654a46f0c84"
36
+ "sha256": "7958c97b6933923ac7b2197e198b520ad4a4774aaa7989af9c67e58929bc161a"
37
37
  },
38
38
  {
39
39
  "path": "darwin-x64/LocalAppBridge.app/Contents/Info.plist",
@@ -41,11 +41,11 @@
41
41
  },
42
42
  {
43
43
  "path": "darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge",
44
- "sha256": "abb2a436434f0bc6bee3a07e2da7962a511cfdf959ada21fa569e553c38aea2f"
44
+ "sha256": "8b0496eee465fd28fa0486574b40719870147124eb510b2aaabde773039770b8"
45
45
  },
46
46
  {
47
47
  "path": "darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs",
48
- "sha256": "6b42a930a08c66ab7845704d61fbc48e5c569822618a0e6d5f20271c07bf3834"
48
+ "sha256": "0db7f7797997aadd4da471681d1cba98033339d30fab3aad60ae3f5f2c55d84c"
49
49
  }
50
50
  ]
51
51
  },
@@ -57,11 +57,11 @@
57
57
  "assets": [
58
58
  {
59
59
  "path": "linux-x64/localapp-native-ipc-client.mjs",
60
- "sha256": "6b42a930a08c66ab7845704d61fbc48e5c569822618a0e6d5f20271c07bf3834"
60
+ "sha256": "0db7f7797997aadd4da471681d1cba98033339d30fab3aad60ae3f5f2c55d84c"
61
61
  },
62
62
  {
63
63
  "path": "linux-x64/localapp-notifications",
64
- "sha256": "a6f863506455b11f44df27dc77648aa09fe1ad9f0e4b0db6a0af8b97b8b530b5"
64
+ "sha256": "eb725b966be0302924402096278992dd449ca8707cdfdee086ba191eeadb3d2f"
65
65
  }
66
66
  ]
67
67
  },
@@ -73,11 +73,11 @@
73
73
  "assets": [
74
74
  {
75
75
  "path": "win32-x64/localapp-native-ipc-client.mjs",
76
- "sha256": "6b42a930a08c66ab7845704d61fbc48e5c569822618a0e6d5f20271c07bf3834"
76
+ "sha256": "0db7f7797997aadd4da471681d1cba98033339d30fab3aad60ae3f5f2c55d84c"
77
77
  },
78
78
  {
79
79
  "path": "win32-x64/localapp-native.exe",
80
- "sha256": "2c025476c800ebcece0a5cc158928c67a30b2b6529ccd1c3508a475f9fce12d1"
80
+ "sha256": "d29c4866352613507ea0ae127d72a7806e7ffa3258a73018eaeb19d0301a20cf"
81
81
  }
82
82
  ]
83
83
  }
@@ -586,7 +586,7 @@ function createLinuxSystemdUserService(options) {
586
586
  return { mode: "service", installed };
587
587
  },
588
588
  async start(signal) {
589
- await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "start", UNIT_NAME] }, signal));
589
+ await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "restart", UNIT_NAME] }, signal));
590
590
  },
591
591
  async stop() {
592
592
  const result = await options.run({ command: systemctl, args: ["--user", "stop", UNIT_NAME] });
@@ -627,8 +627,8 @@ Type=simple
627
627
  ExecStart=${systemdQuote(options.nodePath)} ${systemdQuote(options.layout.launcherPath)}
628
628
  Restart=on-failure
629
629
  RestartSec=2
630
- StandardOutput=append:${systemdQuote(options.layout.daemonLogPath)}
631
- StandardError=append:${systemdQuote(options.layout.daemonLogPath)}
630
+ StandardOutput=append:${options.layout.daemonLogPath}
631
+ StandardError=append:${options.layout.daemonLogPath}
632
632
  ${environment ? `${environment}
633
633
  ` : ""}
634
634
  [Install]
@@ -763,18 +763,25 @@ function createWindowsUserTask(options) {
763
763
  registrationPath,
764
764
  async install() {
765
765
  const installed = await writeServiceFile(registrationPath, metadata);
766
+ const definitionPath = path5.join(path5.dirname(registrationPath), "windows-user-task.xml");
767
+ await fs4.mkdir(path5.dirname(definitionPath), { recursive: true });
768
+ await fs4.writeFile(definitionPath, taskDefinition(options.nodePath, options.layout.launcherPath));
766
769
  await runServiceCommand(options.run, {
767
770
  command: scheduler,
768
- args: ["/Create", "/TN", TASK_NAME, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", taskCommand, "/F"]
771
+ args: ["/Create", "/TN", TASK_NAME, "/XML", definitionPath, "/F"]
769
772
  });
770
773
  return { mode: "service", installed };
771
774
  },
772
775
  async start(signal) {
776
+ const ended = await options.run(withAbortSignal({ command: scheduler, args: ["/End", "/TN", TASK_NAME] }, signal));
777
+ if (ended.code !== 0 && !isNotRunningTask(ended.stderr)) {
778
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
+ }
773
780
  await runServiceCommand(options.run, withAbortSignal({ command: scheduler, args: ["/Run", "/TN", TASK_NAME] }, signal));
774
781
  },
775
782
  async stop() {
776
783
  const result = await options.run({ command: scheduler, args: ["/End", "/TN", TASK_NAME] });
777
- if (result.code !== 0 && !/cannot find|does not exist|not currently running/i.test(result.stderr)) {
784
+ if (result.code !== 0 && !isNotRunningTask(result.stderr)) {
778
785
  throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
786
  }
780
787
  },
@@ -795,6 +802,51 @@ function createWindowsUserTask(options) {
795
802
  }
796
803
  };
797
804
  }
805
+ function isNotRunningTask(stderr) {
806
+ return /cannot find|does not exist|not currently running/i.test(stderr);
807
+ }
808
+ function taskDefinition(nodePath, launcherPath) {
809
+ const xml = `<?xml version="1.0" encoding="UTF-16"?>
810
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
811
+ <RegistrationInfo>
812
+ <Description>LocalApp per-user daemon</Description>
813
+ </RegistrationInfo>
814
+ <Triggers>
815
+ <LogonTrigger>
816
+ <Enabled>true</Enabled>
817
+ </LogonTrigger>
818
+ </Triggers>
819
+ <Principals>
820
+ <Principal id="Author">
821
+ <LogonType>InteractiveToken</LogonType>
822
+ <RunLevel>LeastPrivilege</RunLevel>
823
+ </Principal>
824
+ </Principals>
825
+ <Settings>
826
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
827
+ <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
828
+ <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
829
+ <AllowStartOnDemand>true</AllowStartOnDemand>
830
+ <Enabled>true</Enabled>
831
+ <Hidden>false</Hidden>
832
+ <RunOnlyIfIdle>false</RunOnlyIfIdle>
833
+ <WakeToRun>false</WakeToRun>
834
+ <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
835
+ <Priority>7</Priority>
836
+ </Settings>
837
+ <Actions Context="Author">
838
+ <Exec>
839
+ <Command>${xmlEscape2(nodePath)}</Command>
840
+ <Arguments>${xmlEscape2(launcherPath)}</Arguments>
841
+ </Exec>
842
+ </Actions>
843
+ </Task>
844
+ `;
845
+ return Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
846
+ }
847
+ function xmlEscape2(value) {
848
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
849
+ }
798
850
  function quoteWindowsArgument(value) {
799
851
  if (value.includes("\0") || /[\r\n]/.test(value)) {
800
852
  throw lifecycleError("user_service_configuration_invalid", "The Windows service command path is invalid");
@@ -6,7 +6,7 @@
6
6
  <dict>
7
7
  <key>Resources/localapp-native-ipc-client.mjs</key>
8
8
  <data>
9
- NJd5GyKX/uYptBvMMUBrZK4uU2U=
9
+ kMr4ZJrEOEuEbyR5oQSWrNYzkUU=
10
10
  </data>
11
11
  </dict>
12
12
  <key>files2</key>
@@ -15,7 +15,7 @@
15
15
  <dict>
16
16
  <key>hash2</key>
17
17
  <data>
18
- a0KpMKCMZqt4RXBNYfvEjlxWmCJhig5tXyAnHAe/ODQ=
18
+ Dbf3eXmXqt1NpHFoHRy6mAMzOdMPqzqtYK4/XyxV2Ew=
19
19
  </data>
20
20
  </dict>
21
21
  </dict>
@@ -586,7 +586,7 @@ function createLinuxSystemdUserService(options) {
586
586
  return { mode: "service", installed };
587
587
  },
588
588
  async start(signal) {
589
- await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "start", UNIT_NAME] }, signal));
589
+ await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "restart", UNIT_NAME] }, signal));
590
590
  },
591
591
  async stop() {
592
592
  const result = await options.run({ command: systemctl, args: ["--user", "stop", UNIT_NAME] });
@@ -627,8 +627,8 @@ Type=simple
627
627
  ExecStart=${systemdQuote(options.nodePath)} ${systemdQuote(options.layout.launcherPath)}
628
628
  Restart=on-failure
629
629
  RestartSec=2
630
- StandardOutput=append:${systemdQuote(options.layout.daemonLogPath)}
631
- StandardError=append:${systemdQuote(options.layout.daemonLogPath)}
630
+ StandardOutput=append:${options.layout.daemonLogPath}
631
+ StandardError=append:${options.layout.daemonLogPath}
632
632
  ${environment ? `${environment}
633
633
  ` : ""}
634
634
  [Install]
@@ -763,18 +763,25 @@ function createWindowsUserTask(options) {
763
763
  registrationPath,
764
764
  async install() {
765
765
  const installed = await writeServiceFile(registrationPath, metadata);
766
+ const definitionPath = path5.join(path5.dirname(registrationPath), "windows-user-task.xml");
767
+ await fs4.mkdir(path5.dirname(definitionPath), { recursive: true });
768
+ await fs4.writeFile(definitionPath, taskDefinition(options.nodePath, options.layout.launcherPath));
766
769
  await runServiceCommand(options.run, {
767
770
  command: scheduler,
768
- args: ["/Create", "/TN", TASK_NAME, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", taskCommand, "/F"]
771
+ args: ["/Create", "/TN", TASK_NAME, "/XML", definitionPath, "/F"]
769
772
  });
770
773
  return { mode: "service", installed };
771
774
  },
772
775
  async start(signal) {
776
+ const ended = await options.run(withAbortSignal({ command: scheduler, args: ["/End", "/TN", TASK_NAME] }, signal));
777
+ if (ended.code !== 0 && !isNotRunningTask(ended.stderr)) {
778
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
+ }
773
780
  await runServiceCommand(options.run, withAbortSignal({ command: scheduler, args: ["/Run", "/TN", TASK_NAME] }, signal));
774
781
  },
775
782
  async stop() {
776
783
  const result = await options.run({ command: scheduler, args: ["/End", "/TN", TASK_NAME] });
777
- if (result.code !== 0 && !/cannot find|does not exist|not currently running/i.test(result.stderr)) {
784
+ if (result.code !== 0 && !isNotRunningTask(result.stderr)) {
778
785
  throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
786
  }
780
787
  },
@@ -795,6 +802,51 @@ function createWindowsUserTask(options) {
795
802
  }
796
803
  };
797
804
  }
805
+ function isNotRunningTask(stderr) {
806
+ return /cannot find|does not exist|not currently running/i.test(stderr);
807
+ }
808
+ function taskDefinition(nodePath, launcherPath) {
809
+ const xml = `<?xml version="1.0" encoding="UTF-16"?>
810
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
811
+ <RegistrationInfo>
812
+ <Description>LocalApp per-user daemon</Description>
813
+ </RegistrationInfo>
814
+ <Triggers>
815
+ <LogonTrigger>
816
+ <Enabled>true</Enabled>
817
+ </LogonTrigger>
818
+ </Triggers>
819
+ <Principals>
820
+ <Principal id="Author">
821
+ <LogonType>InteractiveToken</LogonType>
822
+ <RunLevel>LeastPrivilege</RunLevel>
823
+ </Principal>
824
+ </Principals>
825
+ <Settings>
826
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
827
+ <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
828
+ <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
829
+ <AllowStartOnDemand>true</AllowStartOnDemand>
830
+ <Enabled>true</Enabled>
831
+ <Hidden>false</Hidden>
832
+ <RunOnlyIfIdle>false</RunOnlyIfIdle>
833
+ <WakeToRun>false</WakeToRun>
834
+ <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
835
+ <Priority>7</Priority>
836
+ </Settings>
837
+ <Actions Context="Author">
838
+ <Exec>
839
+ <Command>${xmlEscape2(nodePath)}</Command>
840
+ <Arguments>${xmlEscape2(launcherPath)}</Arguments>
841
+ </Exec>
842
+ </Actions>
843
+ </Task>
844
+ `;
845
+ return Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
846
+ }
847
+ function xmlEscape2(value) {
848
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
849
+ }
798
850
  function quoteWindowsArgument(value) {
799
851
  if (value.includes("\0") || /[\r\n]/.test(value)) {
800
852
  throw lifecycleError("user_service_configuration_invalid", "The Windows service command path is invalid");
@@ -6,7 +6,7 @@
6
6
  <dict>
7
7
  <key>Resources/localapp-native-ipc-client.mjs</key>
8
8
  <data>
9
- NJd5GyKX/uYptBvMMUBrZK4uU2U=
9
+ kMr4ZJrEOEuEbyR5oQSWrNYzkUU=
10
10
  </data>
11
11
  </dict>
12
12
  <key>files2</key>
@@ -15,7 +15,7 @@
15
15
  <dict>
16
16
  <key>hash2</key>
17
17
  <data>
18
- a0KpMKCMZqt4RXBNYfvEjlxWmCJhig5tXyAnHAe/ODQ=
18
+ Dbf3eXmXqt1NpHFoHRy6mAMzOdMPqzqtYK4/XyxV2Ew=
19
19
  </data>
20
20
  </dict>
21
21
  </dict>
@@ -586,7 +586,7 @@ function createLinuxSystemdUserService(options) {
586
586
  return { mode: "service", installed };
587
587
  },
588
588
  async start(signal) {
589
- await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "start", UNIT_NAME] }, signal));
589
+ await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "restart", UNIT_NAME] }, signal));
590
590
  },
591
591
  async stop() {
592
592
  const result = await options.run({ command: systemctl, args: ["--user", "stop", UNIT_NAME] });
@@ -627,8 +627,8 @@ Type=simple
627
627
  ExecStart=${systemdQuote(options.nodePath)} ${systemdQuote(options.layout.launcherPath)}
628
628
  Restart=on-failure
629
629
  RestartSec=2
630
- StandardOutput=append:${systemdQuote(options.layout.daemonLogPath)}
631
- StandardError=append:${systemdQuote(options.layout.daemonLogPath)}
630
+ StandardOutput=append:${options.layout.daemonLogPath}
631
+ StandardError=append:${options.layout.daemonLogPath}
632
632
  ${environment ? `${environment}
633
633
  ` : ""}
634
634
  [Install]
@@ -763,18 +763,25 @@ function createWindowsUserTask(options) {
763
763
  registrationPath,
764
764
  async install() {
765
765
  const installed = await writeServiceFile(registrationPath, metadata);
766
+ const definitionPath = path5.join(path5.dirname(registrationPath), "windows-user-task.xml");
767
+ await fs4.mkdir(path5.dirname(definitionPath), { recursive: true });
768
+ await fs4.writeFile(definitionPath, taskDefinition(options.nodePath, options.layout.launcherPath));
766
769
  await runServiceCommand(options.run, {
767
770
  command: scheduler,
768
- args: ["/Create", "/TN", TASK_NAME, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", taskCommand, "/F"]
771
+ args: ["/Create", "/TN", TASK_NAME, "/XML", definitionPath, "/F"]
769
772
  });
770
773
  return { mode: "service", installed };
771
774
  },
772
775
  async start(signal) {
776
+ const ended = await options.run(withAbortSignal({ command: scheduler, args: ["/End", "/TN", TASK_NAME] }, signal));
777
+ if (ended.code !== 0 && !isNotRunningTask(ended.stderr)) {
778
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
+ }
773
780
  await runServiceCommand(options.run, withAbortSignal({ command: scheduler, args: ["/Run", "/TN", TASK_NAME] }, signal));
774
781
  },
775
782
  async stop() {
776
783
  const result = await options.run({ command: scheduler, args: ["/End", "/TN", TASK_NAME] });
777
- if (result.code !== 0 && !/cannot find|does not exist|not currently running/i.test(result.stderr)) {
784
+ if (result.code !== 0 && !isNotRunningTask(result.stderr)) {
778
785
  throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
786
  }
780
787
  },
@@ -795,6 +802,51 @@ function createWindowsUserTask(options) {
795
802
  }
796
803
  };
797
804
  }
805
+ function isNotRunningTask(stderr) {
806
+ return /cannot find|does not exist|not currently running/i.test(stderr);
807
+ }
808
+ function taskDefinition(nodePath, launcherPath) {
809
+ const xml = `<?xml version="1.0" encoding="UTF-16"?>
810
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
811
+ <RegistrationInfo>
812
+ <Description>LocalApp per-user daemon</Description>
813
+ </RegistrationInfo>
814
+ <Triggers>
815
+ <LogonTrigger>
816
+ <Enabled>true</Enabled>
817
+ </LogonTrigger>
818
+ </Triggers>
819
+ <Principals>
820
+ <Principal id="Author">
821
+ <LogonType>InteractiveToken</LogonType>
822
+ <RunLevel>LeastPrivilege</RunLevel>
823
+ </Principal>
824
+ </Principals>
825
+ <Settings>
826
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
827
+ <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
828
+ <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
829
+ <AllowStartOnDemand>true</AllowStartOnDemand>
830
+ <Enabled>true</Enabled>
831
+ <Hidden>false</Hidden>
832
+ <RunOnlyIfIdle>false</RunOnlyIfIdle>
833
+ <WakeToRun>false</WakeToRun>
834
+ <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
835
+ <Priority>7</Priority>
836
+ </Settings>
837
+ <Actions Context="Author">
838
+ <Exec>
839
+ <Command>${xmlEscape2(nodePath)}</Command>
840
+ <Arguments>${xmlEscape2(launcherPath)}</Arguments>
841
+ </Exec>
842
+ </Actions>
843
+ </Task>
844
+ `;
845
+ return Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
846
+ }
847
+ function xmlEscape2(value) {
848
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
849
+ }
798
850
  function quoteWindowsArgument(value) {
799
851
  if (value.includes("\0") || /[\r\n]/.test(value)) {
800
852
  throw lifecycleError("user_service_configuration_invalid", "The Windows service command path is invalid");
@@ -586,7 +586,7 @@ function createLinuxSystemdUserService(options) {
586
586
  return { mode: "service", installed };
587
587
  },
588
588
  async start(signal) {
589
- await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "start", UNIT_NAME] }, signal));
589
+ await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "restart", UNIT_NAME] }, signal));
590
590
  },
591
591
  async stop() {
592
592
  const result = await options.run({ command: systemctl, args: ["--user", "stop", UNIT_NAME] });
@@ -627,8 +627,8 @@ Type=simple
627
627
  ExecStart=${systemdQuote(options.nodePath)} ${systemdQuote(options.layout.launcherPath)}
628
628
  Restart=on-failure
629
629
  RestartSec=2
630
- StandardOutput=append:${systemdQuote(options.layout.daemonLogPath)}
631
- StandardError=append:${systemdQuote(options.layout.daemonLogPath)}
630
+ StandardOutput=append:${options.layout.daemonLogPath}
631
+ StandardError=append:${options.layout.daemonLogPath}
632
632
  ${environment ? `${environment}
633
633
  ` : ""}
634
634
  [Install]
@@ -763,18 +763,25 @@ function createWindowsUserTask(options) {
763
763
  registrationPath,
764
764
  async install() {
765
765
  const installed = await writeServiceFile(registrationPath, metadata);
766
+ const definitionPath = path5.join(path5.dirname(registrationPath), "windows-user-task.xml");
767
+ await fs4.mkdir(path5.dirname(definitionPath), { recursive: true });
768
+ await fs4.writeFile(definitionPath, taskDefinition(options.nodePath, options.layout.launcherPath));
766
769
  await runServiceCommand(options.run, {
767
770
  command: scheduler,
768
- args: ["/Create", "/TN", TASK_NAME, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", taskCommand, "/F"]
771
+ args: ["/Create", "/TN", TASK_NAME, "/XML", definitionPath, "/F"]
769
772
  });
770
773
  return { mode: "service", installed };
771
774
  },
772
775
  async start(signal) {
776
+ const ended = await options.run(withAbortSignal({ command: scheduler, args: ["/End", "/TN", TASK_NAME] }, signal));
777
+ if (ended.code !== 0 && !isNotRunningTask(ended.stderr)) {
778
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
+ }
773
780
  await runServiceCommand(options.run, withAbortSignal({ command: scheduler, args: ["/Run", "/TN", TASK_NAME] }, signal));
774
781
  },
775
782
  async stop() {
776
783
  const result = await options.run({ command: scheduler, args: ["/End", "/TN", TASK_NAME] });
777
- if (result.code !== 0 && !/cannot find|does not exist|not currently running/i.test(result.stderr)) {
784
+ if (result.code !== 0 && !isNotRunningTask(result.stderr)) {
778
785
  throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
786
  }
780
787
  },
@@ -795,6 +802,51 @@ function createWindowsUserTask(options) {
795
802
  }
796
803
  };
797
804
  }
805
+ function isNotRunningTask(stderr) {
806
+ return /cannot find|does not exist|not currently running/i.test(stderr);
807
+ }
808
+ function taskDefinition(nodePath, launcherPath) {
809
+ const xml = `<?xml version="1.0" encoding="UTF-16"?>
810
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
811
+ <RegistrationInfo>
812
+ <Description>LocalApp per-user daemon</Description>
813
+ </RegistrationInfo>
814
+ <Triggers>
815
+ <LogonTrigger>
816
+ <Enabled>true</Enabled>
817
+ </LogonTrigger>
818
+ </Triggers>
819
+ <Principals>
820
+ <Principal id="Author">
821
+ <LogonType>InteractiveToken</LogonType>
822
+ <RunLevel>LeastPrivilege</RunLevel>
823
+ </Principal>
824
+ </Principals>
825
+ <Settings>
826
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
827
+ <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
828
+ <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
829
+ <AllowStartOnDemand>true</AllowStartOnDemand>
830
+ <Enabled>true</Enabled>
831
+ <Hidden>false</Hidden>
832
+ <RunOnlyIfIdle>false</RunOnlyIfIdle>
833
+ <WakeToRun>false</WakeToRun>
834
+ <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
835
+ <Priority>7</Priority>
836
+ </Settings>
837
+ <Actions Context="Author">
838
+ <Exec>
839
+ <Command>${xmlEscape2(nodePath)}</Command>
840
+ <Arguments>${xmlEscape2(launcherPath)}</Arguments>
841
+ </Exec>
842
+ </Actions>
843
+ </Task>
844
+ `;
845
+ return Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
846
+ }
847
+ function xmlEscape2(value) {
848
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
849
+ }
798
850
  function quoteWindowsArgument(value) {
799
851
  if (value.includes("\0") || /[\r\n]/.test(value)) {
800
852
  throw lifecycleError("user_service_configuration_invalid", "The Windows service command path is invalid");