amaprice 1.0.13 → 1.0.14
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/package.json +1 -1
- package/src/background/service.js +13 -3
package/package.json
CHANGED
|
@@ -263,6 +263,7 @@ async function enableLaunchdService({
|
|
|
263
263
|
const plistPath = getLaunchdPlistPath(label);
|
|
264
264
|
const logPath = getDaemonLogPath();
|
|
265
265
|
const daemonEntry = getDaemonEntryPath();
|
|
266
|
+
const target = buildServiceTarget(label);
|
|
266
267
|
|
|
267
268
|
await fs.mkdir(path.dirname(plistPath), { recursive: true });
|
|
268
269
|
await fs.mkdir(path.dirname(logPath), { recursive: true });
|
|
@@ -283,13 +284,22 @@ async function enableLaunchdService({
|
|
|
283
284
|
});
|
|
284
285
|
await fs.writeFile(plistPath, plist, 'utf8');
|
|
285
286
|
|
|
286
|
-
|
|
287
|
+
// If service was previously disabled via `background off`, re-enable first.
|
|
288
|
+
await runLaunchctl(['enable', target], { allowFailure: true });
|
|
289
|
+
|
|
290
|
+
let bootstrap = await runLaunchctl(['bootstrap', getLaunchdDomain(), plistPath], { allowFailure: true });
|
|
291
|
+
if (!bootstrap.ok && !isAlreadyLoadedError(bootstrap)) {
|
|
292
|
+
// Recover from stale loaded/disabled state by clearing then bootstrapping once more.
|
|
293
|
+
await runLaunchctl(['bootout', target], { allowFailure: true });
|
|
294
|
+
await runLaunchctl(['enable', target], { allowFailure: true });
|
|
295
|
+
bootstrap = await runLaunchctl(['bootstrap', getLaunchdDomain(), plistPath], { allowFailure: true });
|
|
296
|
+
}
|
|
287
297
|
if (!bootstrap.ok && !isAlreadyLoadedError(bootstrap)) {
|
|
288
298
|
throw new Error(`Could not bootstrap launchd service: ${bootstrap.stderr || bootstrap.stdout || 'unknown error'}`);
|
|
289
299
|
}
|
|
290
300
|
|
|
291
|
-
await runLaunchctl(['enable',
|
|
292
|
-
const kick = await runLaunchctl(['kickstart', '-k',
|
|
301
|
+
await runLaunchctl(['enable', target], { allowFailure: true });
|
|
302
|
+
const kick = await runLaunchctl(['kickstart', '-k', target], { allowFailure: true });
|
|
293
303
|
if (!kick.ok) {
|
|
294
304
|
await runLaunchctl(['start', label], { allowFailure: true });
|
|
295
305
|
}
|