fix: devtool startup

This commit is contained in:
windingwind 2023-12-13 22:21:26 +08:00
parent 57028c7ba8
commit 032aa74f6e
3 changed files with 19 additions and 5 deletions

View File

@ -68,10 +68,7 @@ async function main() {
await build(); await build();
// start Zotero // start Zotero
startZotero(); startZotero(openDevTool);
setTimeout(() => {
openDevTool();
}, 5000);
// watch // watch
await watch(); await watch();

View File

@ -10,6 +10,9 @@ import { exit } from "process";
const { addonID } = details.config; const { addonID } = details.config;
const { zoteroBinPath, profilePath, dataDir } = cmd.exec; const { zoteroBinPath, profilePath, dataDir } = cmd.exec;
// Keep in sync with the addon's onStartup
const loadDevToolWhen = `Plugin ${addonID} startup`;
const logPath = "logs"; const logPath = "logs";
const logFilePath = path.join(logPath, "zotero.log"); const logFilePath = path.join(logPath, "zotero.log");
@ -68,7 +71,9 @@ function prepareLog() {
writeFileSync(logFilePath, ""); writeFileSync(logFilePath, "");
} }
export function main() { export function main(callback) {
let isZoteroReady = false;
prepareDevEnv(); prepareDevEnv();
prepareLog(); prepareLog();
@ -81,6 +86,10 @@ export function main() {
]); ]);
zoteroProcess.stdout.on("data", (data) => { zoteroProcess.stdout.on("data", (data) => {
if (!isZoteroReady && data.toString().includes(loadDevToolWhen)) {
isZoteroReady = true;
callback();
}
writeFileSync(logFilePath, data, { writeFileSync(logFilePath, data, {
flag: "a", flag: "a",
}); });

View File

@ -16,6 +16,14 @@ async function onStartup() {
Zotero.unlockPromise, Zotero.unlockPromise,
Zotero.uiReadyPromise, 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(); initLocale();
BasicExampleFactory.registerPrefs(); BasicExampleFactory.registerPrefs();