Skip to content

Commit 000d567

Browse files
committed
feat: 在侧边栏显示插件载入情况
1 parent b2f8955 commit 000d567

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

src/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class App {
8686

8787
logger.debug('开始加载插件', this.plugins);
8888
let retryTimes = 0;
89+
8990
do {
9091
for (const slug in this.plugins) {
9192
const plugin = this.plugins[slug];
@@ -161,6 +162,14 @@ class App {
161162
// 进行插件加载
162163
await plugin.load(pluginContext);
163164
plugin.loaded = true;
165+
166+
logger.debug(panel.pushLoadedPlugin);
167+
panel.pushLoadedPlugin({
168+
slug: plugin.slug,
169+
name: plugin.name,
170+
namespace: plugin.namespace ? globalContext.namespace : null,
171+
description: plugin.description,
172+
});
164173
}
165174
}
166175

src/panel.jsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import '@ui5/webcomponents/dist/Card.js';
22
import '@ui5/webcomponents/dist/CardHeader.js';
3+
import '@ui5/webcomponents/dist/Tag.js';
4+
5+
import { app } from 'hyperapp';
36

47
import { createElement } from './utils/dom';
58

@@ -56,11 +59,63 @@ export function initializePanel(plugins) {
5659
pluginInitializers[slug] = initializer;
5760
});
5861

62+
const $panelHeader = createElement(<div></div>);
63+
$panel.appendChild($panelHeader);
64+
function getPluginColorScheme(plugin) {
65+
if (plugin.slug.startsWith('builtin-')) {
66+
return 8;
67+
}
68+
if (plugin.namespace === '学在浙大') {
69+
return 4;
70+
}
71+
if (plugin.namespace === '智云课堂') {
72+
return 5;
73+
}
74+
if (plugin.namespace === 'PTA') {
75+
return 6;
76+
}
77+
return 10;
78+
}
79+
const panelHeaderActions = {
80+
pushLoadedPlugin:
81+
(newPlugin) =>
82+
({ loadedPlugins }) => {
83+
console.debug('[zju-helper] push loaded plugin', newPlugin);
84+
loadedPlugins.push(newPlugin);
85+
return { loadedPlugins };
86+
},
87+
};
88+
app({
89+
node: $panelHeader,
90+
init: { loadedPlugins: [] },
91+
actions: panelHeaderActions,
92+
view: ({ loadedPlugins }) => (
93+
<ui5-card>
94+
<div class="zju-helper-panel-header">
95+
<div class="zju-helper-panel-header-title">学在浙大/智云课堂小助手</div>
96+
<div class="zju-helper-loaded-plugins-slogen">
97+
当前共加载 {loadedPlugins.length} 个插件{JSON.stringify(loadedPlugins)}
98+
</div>
99+
<div class="zju-helper-loaded-plugins">
100+
{loadedPlugins.map((plugin) => (
101+
<span class="zju-helper-loaded-plugin-tag">
102+
<ui5-tag design="Set2" color-scheme={getPluginColorScheme(plugin)}>
103+
{plugin.slug}
104+
</ui5-tag>
105+
</span>
106+
))}
107+
</div>
108+
</div>
109+
</ui5-card>
110+
),
111+
});
112+
59113
return {
60114
element: $panel,
61115
show: showPanel,
62116
hide: hidePanel,
63117
toggle: togglePanel,
64118
pluginInitializers,
119+
pushLoadedPlugin: panelHeaderActions.pushLoadedPlugin,
65120
};
66121
}

src/panel.less

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
@panel-width: 260px;
22
@duration: 0.25s;
33

4+
html {
5+
font-size: 16px;
6+
}
7+
48
.zju-helper {
9+
&,
10+
& * {
11+
box-sizing: border-box;
12+
}
13+
514
position: fixed;
615
top: 0;
716
left: -@panel-width; // 初始状态隐藏在左侧
@@ -12,7 +21,7 @@
1221
opacity: 0;
1322
z-index: 9999;
1423

15-
padding: 30px 15px;
24+
padding: 1.5rem 1rem;
1625

1726
// 毛玻璃效果
1827
backdrop-filter: blur(4px);
@@ -56,10 +65,33 @@
5665
z-index: 9998;
5766
}
5867

68+
// 侧边栏 header
69+
.zju-helper-panel-header {
70+
padding: 1rem;
71+
72+
.zju-helper-panel-header-title {
73+
margin-top: 0.15rem;
74+
font-weight: bold;
75+
font-size: 1.025rem;
76+
}
77+
78+
.zju-helper-loaded-plugins-slogen {
79+
margin-top: 0.5rem;
80+
font-size: 0.8rem;
81+
color: #666;
82+
}
83+
84+
.zju-helper-loaded-plugins {
85+
margin-top: 0.5rem;
86+
}
87+
}
88+
5989
// 插件卡片
6090
.zju-helper-plugin {
91+
margin-top: 0.75rem;
92+
6193
.zju-helper-plugin-content {
62-
margin-top: -0.75rem;
94+
margin-top: -1rem;
6395
max-height: 400px;
6496
overflow-y: hidden;
6597
transition: max-height (@duration * 2) cubic-bezier(0, 1, 0, 1);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.score-finder-item-content {
22
word-break: break-all;
3-
margin-top: -5px;
4-
font-size: 0.9em;
3+
margin-top: -0.375rem;
4+
font-size: 0.675rem;
55
}

0 commit comments

Comments
 (0)