增加语音对话功能
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { config } from "../../../../package.json";
|
||||
import { getLocaleID, getString } from "../../../utils/locale";
|
||||
import { findPdfAttachment } from "../../pdf/extractor";
|
||||
import { ensureChatPapersStyles } from "../../ui/readerPane";
|
||||
import { LecturePaneView } from "./lecturePane";
|
||||
|
||||
const views = new WeakMap<HTMLElement, LecturePaneView>();
|
||||
|
||||
function iconURL(file: string) {
|
||||
return `chrome://${config.addonRef}/content/icons/${file}`;
|
||||
}
|
||||
|
||||
export function registerLecturePane() {
|
||||
Zotero.ItemPaneManager.registerSection({
|
||||
paneID: "chatpapers-lecture",
|
||||
pluginID: config.addonID,
|
||||
header: {
|
||||
l10nID: getLocaleID("item-section-lecture-head"),
|
||||
icon: iconURL("lecture.svg"),
|
||||
},
|
||||
sidenav: {
|
||||
l10nID: getLocaleID("item-section-lecture-sidenav"),
|
||||
icon: iconURL("lecture.svg"),
|
||||
},
|
||||
onInit: ({ body }) => {
|
||||
const doc = body.ownerDocument;
|
||||
if (doc) ensureChatPapersStyles(doc);
|
||||
},
|
||||
onDestroy: ({ body }) => {
|
||||
views.get(body)?.destroy();
|
||||
views.delete(body);
|
||||
},
|
||||
onItemChange: ({ item, setEnabled }) => {
|
||||
setEnabled(Boolean(item && findPdfAttachment(item)));
|
||||
return true;
|
||||
},
|
||||
onRender: ({ body }) => {
|
||||
body.replaceChildren();
|
||||
const doc = body.ownerDocument;
|
||||
if (!doc) return;
|
||||
const loading = doc.createElement("div");
|
||||
loading.className = "chatpapers-loading";
|
||||
loading.textContent = getString("lecture-loading");
|
||||
body.append(loading);
|
||||
},
|
||||
onAsyncRender: async ({ body, item }) => {
|
||||
if (!item) return;
|
||||
const doc = body.ownerDocument;
|
||||
if (!doc) return;
|
||||
views.get(body)?.destroy();
|
||||
const view = new LecturePaneView(doc, body, item);
|
||||
views.set(body, view);
|
||||
try {
|
||||
await view.mount();
|
||||
} catch (e) {
|
||||
ztoolkit.log("[ChatPapers:Lecture] mount failed", e);
|
||||
body.replaceChildren();
|
||||
const err = doc.createElement("div");
|
||||
err.className = "chatpapers-lecture-error";
|
||||
err.textContent = getString("lecture-mount-error");
|
||||
body.append(err);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user