diff --git a/scripts/stop.mjs b/scripts/stop.mjs index 197ef04..c861a6b 100644 --- a/scripts/stop.mjs +++ b/scripts/stop.mjs @@ -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);