fix: scripts/stop wait for process exit

This commit is contained in:
windingwind 2023-06-11 15:34:45 +08:00
parent d9680008d5
commit 2c3f6d1d7f

View File

@ -3,11 +3,33 @@ import { execSync } from "child_process";
import cmd from "./zotero-cmd.json" assert { type: "json" };
const { killZoteroWindows, killZoteroUnix } = cmd;
const MAX_WAIT_TIME = 10000;
const startTime = new Date().getTime();
try {
if (process.platform === "win32") {
execSync(killZoteroWindows);
// wait until zotero.exe is fully stopped. maximum wait for 10 seconds
while (new Date().getTime() - startTime <= MAX_WAIT_TIME) {
try {
execSync('tasklist | find /i "zotero.exe"');
} catch (e) {
break;
}
}
} else {
execSync(killZoteroUnix);
// wait until zotero is fully stopped. maximum wait for 10 seconds
while (new Date().getTime() - startTime <= MAX_WAIT_TIME) {
try {
execSync("ps aux | grep -i zotero");
} catch (e) {
break;
}
}
}
} catch (e) {
console.error(e);