diff --git a/scripts/server.mjs b/scripts/server.mjs index 542ca44..3f35430 100644 --- a/scripts/server.mjs +++ b/scripts/server.mjs @@ -68,10 +68,7 @@ async function main() { await build(); // start Zotero - startZotero(); - setTimeout(() => { - openDevTool(); - }, 5000); + startZotero(openDevTool); // watch await watch(); diff --git a/scripts/start.mjs b/scripts/start.mjs index 2b9782b..b916b5a 100644 --- a/scripts/start.mjs +++ b/scripts/start.mjs @@ -10,6 +10,9 @@ import { exit } from "process"; const { addonID } = details.config; const { zoteroBinPath, profilePath, dataDir } = cmd.exec; +// Keep in sync with the addon's onStartup +const loadDevToolWhen = `Plugin ${addonID} startup`; + const logPath = "logs"; const logFilePath = path.join(logPath, "zotero.log"); @@ -68,7 +71,9 @@ function prepareLog() { writeFileSync(logFilePath, ""); } -export function main() { +export function main(callback) { + let isZoteroReady = false; + prepareDevEnv(); prepareLog(); @@ -81,6 +86,10 @@ export function main() { ]); zoteroProcess.stdout.on("data", (data) => { + if (!isZoteroReady && data.toString().includes(loadDevToolWhen)) { + isZoteroReady = true; + callback(); + } writeFileSync(logFilePath, data, { flag: "a", }); diff --git a/src/hooks.ts b/src/hooks.ts index 7b000f9..9b781f3 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -16,6 +16,14 @@ async function onStartup() { Zotero.unlockPromise, Zotero.uiReadyPromise, ]); + + // TODO: Remove this after zotero#3387 is merged + if (__env__ === "development") { + // Keep in sync with the scripts/startup.mjs + const loadDevToolWhen = `Plugin ${config.addonID} startup`; + ztoolkit.log(loadDevToolWhen); + } + initLocale(); BasicExampleFactory.registerPrefs();