Skip to content

Commit

Permalink
fix #126
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Sep 18, 2024
1 parent 66f0372 commit 5fc7d70
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default class Addon extends toolBase.BasicTool {
const pref = Zotero.Prefs.get(`${packageName}.${key}`) ?? JSON.stringify(
config.defaultSettings[key]
);
if (__dev__)
this.log(`Getting pref ${key}:`, pref);
// if (__dev__)
// this.log(`Getting pref ${key}:`, pref);
switch (typeof config.defaultSettings[key]) {
case 'object':
return JSON.parse(pref as string) as DefaultPrefs[K];
Expand Down
9 changes: 3 additions & 6 deletions src/bootstrap/modules/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function updateDashboard(id?: number) {
* 初始化侧边栏TabPanel
*/
export function registerPanels() {
function post(body: HTMLDivElement, message: any) {
function post(body: HTMLDivElement, message: object | string) {
const iframe = body.getElementsByTagName('iframe')[0];
if (!iframe?.contentWindow)
addon.log(new Error('Dashboard iframe not found'));
Expand All @@ -26,9 +26,7 @@ export function registerPanels() {
}
const tabs = ['progress', 'page', 'date', 'group', /*'relation',*/ 'timeline'];

if (!Zotero.ItemPaneManager?.registerSection)
addon.log(new Error('ItemPaneManager not found'));
Zotero.ItemPaneManager?.registerSection({
Zotero.ItemPaneManager.registerSection({
paneID: 'chartero-dashboard',
pluginID: config.addonID,
header: {
Expand Down Expand Up @@ -62,12 +60,11 @@ export function registerPanels() {
([entry]) => args.body.style.height = `${entry.contentRect.height}px`
);
(iframe.contentWindow as any).wrappedJSObject.addon = addon;
iframe.addEventListener('load', ({target}) => {
iframe.addEventListener('load', ({ target }) => {
observer.observe((target as Document).documentElement);
}, true);
},
onRender: args => {
post(args.body, 'render');
if (args.item.libraryID == Zotero.Libraries.userLibraryID)
args.setSectionButtonStatus('group', { hidden: true });
args.setSectionButtonStatus('progress', { disabled: true });
Expand Down
12 changes: 1 addition & 11 deletions src/vue/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,7 @@
import { createApp } from 'vue';
import App from './main.vue';
import 'tdesign-vue-next/es/style/index.css';

function onMsg({ data }) {
if (data == 'render')
try {
createApp(App).mount('#app');
removeEventListener('message', onMsg);
} catch (error) {
console.error('dashboard app', error)
}
}
addEventListener('message', onMsg);
createApp(App).mount('#app');
</script>
<script>Zotero = addon.getGlobal('Zotero');</script>
</body>
Expand Down

0 comments on commit 5fc7d70

Please sign in to comment.