diff --git a/addon/content/icons/date.svg b/addon/content/icons/date.svg index b6258ae..8dfb5d3 100644 --- a/addon/content/icons/date.svg +++ b/addon/content/icons/date.svg @@ -1,3 +1,6 @@ - \ No newline at end of file + + + + \ No newline at end of file diff --git a/addon/content/icons/group.svg b/addon/content/icons/group.svg index 7b04774..9120a06 100644 --- a/addon/content/icons/group.svg +++ b/addon/content/icons/group.svg @@ -1,7 +1,7 @@ + p-id="21994" xmlns:xlink="http://www.w3.org/1999/xlink" fill="context-fill"> diff --git a/addon/content/icons/page.svg b/addon/content/icons/page.svg index a055bfc..e146c46 100644 --- a/addon/content/icons/page.svg +++ b/addon/content/icons/page.svg @@ -1,3 +1,6 @@ - \ No newline at end of file + + + + \ No newline at end of file diff --git a/addon/content/icons/progress.svg b/addon/content/icons/progress.svg index db67a75..49d5e36 100644 --- a/addon/content/icons/progress.svg +++ b/addon/content/icons/progress.svg @@ -3,9 +3,11 @@ \ No newline at end of file diff --git a/addon/content/icons/relation.svg b/addon/content/icons/relation.svg index 08ddcc3..b7c6a63 100644 --- a/addon/content/icons/relation.svg +++ b/addon/content/icons/relation.svg @@ -1,3 +1,9 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/addon/content/icons/timeline.svg b/addon/content/icons/timeline.svg index d85fe45..b220f16 100644 --- a/addon/content/icons/timeline.svg +++ b/addon/content/icons/timeline.svg @@ -4,5 +4,5 @@ p-id="19324" xmlns:xlink="http://www.w3.org/1999/xlink"> + fill="context-fill" p-id="19325"> \ No newline at end of file diff --git a/addon/locale/en-US/chartero.ftl b/addon/locale/en-US/chartero.ftl index 50c8eba..eacdf34 100644 --- a/addon/locale/en-US/chartero.ftl +++ b/addon/locale/en-US/chartero.ftl @@ -29,3 +29,15 @@ completeThreshold = Complete threshold for progress (seconds): dashboardSection = .label = Dashboard .tooltiptext = Chartero Dashboard +dashboard-progress = + .tooltiptext = Reading Progress +dashboard-page = + .tooltiptext = Page-Time Chart +dashboard-date = + .tooltiptext = Date-Time Chart +dashboard-group = + .tooltiptext = User-Time Chart +dashboard-relation = + .tooltiptext = Relation Network Graph +dashboard-timeline = + .tooltiptext = Timeline diff --git a/addon/locale/it-IT/chartero.ftl b/addon/locale/it-IT/chartero.ftl index 7a8e1db..d0ec16b 100644 --- a/addon/locale/it-IT/chartero.ftl +++ b/addon/locale/it-IT/chartero.ftl @@ -29,3 +29,15 @@ completeThreshold = Limite di avanzamento completo (secondi): dashboardSection = .label = Cruscotto .tooltiptext = Chartero Cruscotto +dashboard-progress = + .tooltiptext = Ha letto +dashboard-page = + .tooltiptext = Tempo di lettura per pagina +dashboard-date = + .tooltiptext = Tempo di lettura giornaliero +dashboard-group = + .tooltiptext = Lettura dagli utenti +dashboard-relation = + .tooltiptext = Network delle relazioni +dashboard-timeline = + .tooltiptext = Linea temporale diff --git a/addon/locale/ja-JP/chartero.ftl b/addon/locale/ja-JP/chartero.ftl index 3d3ab9e..31ca40d 100644 --- a/addon/locale/ja-JP/chartero.ftl +++ b/addon/locale/ja-JP/chartero.ftl @@ -29,3 +29,15 @@ completeThreshold = 完了進捗閾値(秒): dashboardSection = .label = ダッシュボード .tooltiptext = Charteroダッシュボード +dashboard-progress = + .tooltiptext = 阅读进度 +dashboard-page = + .tooltiptext = 毎ページの読み時間 +dashboard-date = + .tooltiptext = 毎日の読み時間 +dashboard-group = + .tooltiptext = ユーザー統計 +dashboard-relation = + .tooltiptext = 文献関連ネットワーク +dashboard-timeline = + .tooltiptext = タイムライン diff --git a/addon/locale/zh-CN/chartero.ftl b/addon/locale/zh-CN/chartero.ftl index 1253693..c310775 100644 --- a/addon/locale/zh-CN/chartero.ftl +++ b/addon/locale/zh-CN/chartero.ftl @@ -29,3 +29,15 @@ completeThreshold = 页均阅读阈值(用于进度统计): dashboardSection = .label = 仪表盘 .tooltiptext = Chartero仪表盘 +dashboard-progress = + .tooltiptext = 阅读进度 +dashboard-page = + .tooltiptext = 每页阅读时长 +dashboard-date = + .tooltiptext = 每日阅读时长 +dashboard-group = + .tooltiptext = 用户阅读时长 +dashboard-relation = + .tooltiptext = 关联条目图 +dashboard-timeline = + .tooltiptext = 时间线 diff --git a/src/bootstrap/modules/sidebar.ts b/src/bootstrap/modules/sidebar.ts index 0d2ec08..d55b75f 100644 --- a/src/bootstrap/modules/sidebar.ts +++ b/src/bootstrap/modules/sidebar.ts @@ -12,6 +12,19 @@ export function updateDashboard(id?: number) { * 初始化侧边栏TabPanel */ export function registerPanels() { + function post(body: HTMLDivElement, message: any) { + const iframe = body.getElementsByTagName('iframe')[0]; + if (!iframe?.contentWindow) + addon.log(new Error('Dashboard iframe not found')); + else if (iframe.contentDocument?.readyState === 'complete') + iframe.contentWindow.postMessage(message, '*'); + else + iframe.addEventListener('load', ({ target }) => + (target as Document).defaultView!.postMessage(message, '*'), true); + addon.log(message, iframe.contentDocument?.readyState); + } + const tabs = ['progress', 'page', 'date', 'group', 'relation', 'timeline']; + if (!Zotero.ItemPaneManager?.registerSection) addon.log(new Error('ItemPaneManager not found')); Zotero.ItemPaneManager?.registerSection({ @@ -25,12 +38,14 @@ export function registerPanels() { l10nID: 'chartero-dashboardSection', icon: `resource://${config.addonName}/icons/sidebar.svg`, }, - sectionButtons: ['progress', 'page', 'date', 'group', 'relation', 'timeline'].map(tab => ({ + sectionButtons: tabs.map(tab => ({ type: tab, + l10nID: `chartero-dashboard-${tab}`, icon: `resource://${config.addonName}/icons/${tab}.svg`, onClick(e) { - const iframe = e.body.getElementsByTagName('iframe')[0]; - iframe.contentWindow!.postMessage({ tab }, '*'); + post(e.body, { tab }); + for (const t of tabs) + e.setSectionButtonStatus(t, { disabled: t === tab }); } })), onInit: args => { @@ -44,15 +59,8 @@ export function registerPanels() { (iframe.contentWindow as any).wrappedJSObject.addon = addon; args.body.style.height = '600px'; }, - onRender: args => { - }, - onItemChange: args => { - addon.log(args); - const iframe = args.body.getElementsByTagName('iframe')[0], - id = Number(args.item.id); - iframe.contentWindow!.postMessage({ id }, '*'); - }, - onDestroy: args => addon.log(args), + onRender: args => post(args.body, 'render'), + onItemChange: args => post(args.body, { id: args.item.id }), }); } diff --git a/src/vue/dashboard/index.html b/src/vue/dashboard/index.html index 715da8c..f2c1652 100644 --- a/src/vue/dashboard/index.html +++ b/src/vue/dashboard/index.html @@ -63,11 +63,24 @@ import { createApp } from 'vue'; import App from './main.vue'; import 'tdesign-vue-next/es/style/index.css'; - try { - createApp(App).mount('#app'); - } catch (error) { - addon.log('dashboard app', error) + + function switchTheme(e) { + document.documentElement.setAttribute('theme-mode', e.matches ? 'dark' : 'light'); + } + const darkQuery = matchMedia('(prefers-color-scheme: dark)'); + darkQuery.addListener(switchTheme); + switchTheme(darkQuery); + + function onMsg({ data }) { + if (data == 'render') + try { + createApp(App).mount('#app'); + removeEventListener('message', onMsg); + } catch (error) { + console.error('dashboard app', error) + } } + addEventListener('message', onMsg); diff --git a/src/vue/dashboard/main.vue b/src/vue/dashboard/main.vue index d430edd..5823d06 100644 --- a/src/vue/dashboard/main.vue +++ b/src/vue/dashboard/main.vue @@ -27,10 +27,10 @@ - + /> --> @@ -121,6 +121,7 @@ export default { }, }, mounted() { + addon.log('Dashboard mounted'); addEventListener('message', e => { if (typeof e.data.tab == 'string') { this.activeTab = e.data.tab;