mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(release): v1.4.0 cloud pricing sync, one-click plugin update, and UI copy refresh
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
|
||||
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
|
||||
import { fetchTelemetry, telemetryStore } from '../../store/telemetryStore.js';
|
||||
import { fetchTelemetry, telemetryStore, triggerPluginUpdate } from '../../store/telemetryStore.js';
|
||||
import { uiStore } from '../../store/uiStore.js';
|
||||
import { CustomSelect } from '../ui/CustomSelect.js';
|
||||
|
||||
export const TopSessionHeader = defineComponent({
|
||||
@@ -16,14 +17,50 @@ export const TopSessionHeader = defineComponent({
|
||||
const convSelect = CustomSelect({
|
||||
modelValue: telemetryStore.getState().selectedConversationId,
|
||||
icon: 'bolt',
|
||||
placeholder: '自动跟随最新会话',
|
||||
options: [{ value: '', label: '自动跟随最新会话' }],
|
||||
placeholder: '跟随最新会话',
|
||||
options: [{ value: '', label: '跟随最新会话' }],
|
||||
onUpdateModelValue: (nextConvId) => {
|
||||
telemetryStore.setState({ selectedConversationId: nextConvId });
|
||||
fetchTelemetry({ force: false });
|
||||
},
|
||||
});
|
||||
|
||||
const updateBtnIcon = createSvgIcon('arrow-down', { size: 11 });
|
||||
const updateBtnText = h('span', { text: '有新版本' });
|
||||
let isHeaderUpdating = false;
|
||||
const updateBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'update-badge-btn',
|
||||
hidden: true,
|
||||
'aria-label': '发现新版本,点击升级',
|
||||
onClick: async () => {
|
||||
if (isHeaderUpdating) return;
|
||||
isHeaderUpdating = true;
|
||||
patchText(updateBtnText, '升级中…');
|
||||
patchAttr(updateBtn, 'disabled', true);
|
||||
try {
|
||||
const res = await triggerPluginUpdate();
|
||||
if (!res?.ok) {
|
||||
uiStore.setState({ activeView: 'settings' });
|
||||
}
|
||||
} catch {
|
||||
uiStore.setState({ activeView: 'settings' });
|
||||
} finally {
|
||||
isHeaderUpdating = false;
|
||||
patchAttr(updateBtn, 'disabled', false);
|
||||
const cs = telemetryStore.getState().telemetry?.cloudStatus;
|
||||
patchText(
|
||||
updateBtnText,
|
||||
cs?.latestPluginVersion ? `升级 v${cs.latestPluginVersion}` : '有新版本'
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
[updateBtnIcon, updateBtnText]
|
||||
);
|
||||
|
||||
const statusIcon = createSvgIcon('pulse', { size: 12 });
|
||||
const statusText = h('span', { text: '实时 2s' });
|
||||
const statusTag = h('span', { className: 'status-tag' }, [statusIcon, statusText]);
|
||||
@@ -33,7 +70,7 @@ export const TopSessionHeader = defineComponent({
|
||||
{
|
||||
type: 'button',
|
||||
className: 'icon-btn',
|
||||
'aria-label': '立即刷新额度与测速数据',
|
||||
'aria-label': '刷新数据',
|
||||
onClick: () => fetchTelemetry({ force: true }),
|
||||
},
|
||||
[createSvgIcon('refresh', { size: 13 })]
|
||||
@@ -41,7 +78,7 @@ export const TopSessionHeader = defineComponent({
|
||||
|
||||
const headerEl = h('header', { className: 'session-header' }, [
|
||||
h('div', { className: 'session-left' }, [convSelect.el]),
|
||||
h('div', { className: 'session-right' }, [statusTag, refreshBtn]),
|
||||
h('div', { className: 'session-right' }, [updateBtn, statusTag, refreshBtn]),
|
||||
]);
|
||||
|
||||
const unsubTelemetry = telemetryStore.subscribe(
|
||||
@@ -51,10 +88,11 @@ export const TopSessionHeader = defineComponent({
|
||||
conversations: st.telemetry?.conversations,
|
||||
isRunning: st.telemetry?.activeConversation?.isRunning,
|
||||
quotaMeta: st.telemetry?.quotas?.meta,
|
||||
cloudStatus: st.telemetry?.cloudStatus,
|
||||
}),
|
||||
(slice) => {
|
||||
const convs = slice.conversations || [];
|
||||
const latestTitle = convs[0]?.title ? `自动跟随 (${convs[0].title})` : '自动跟随最新会话';
|
||||
const latestTitle = convs[0]?.title ? `最新 (${convs[0].title})` : '跟随最新会话';
|
||||
const options = [
|
||||
{ value: '', label: latestTitle, meta: convs[0] ? `${convs[0].stepCount}步` : '' },
|
||||
...convs.map((c) => ({
|
||||
@@ -68,6 +106,17 @@ export const TopSessionHeader = defineComponent({
|
||||
options,
|
||||
});
|
||||
|
||||
const hasUpdate = Boolean(slice.cloudStatus?.updateAvailable);
|
||||
patchAttr(updateBtn, 'hidden', !hasUpdate);
|
||||
if (hasUpdate && !isHeaderUpdating) {
|
||||
patchText(
|
||||
updateBtnText,
|
||||
slice.cloudStatus?.latestPluginVersion
|
||||
? `升级 v${slice.cloudStatus.latestPluginVersion}`
|
||||
: '有新版本'
|
||||
);
|
||||
}
|
||||
|
||||
const isSyncing = slice.syncState === 'syncing';
|
||||
const isSynced = slice.syncState === 'synced';
|
||||
const isError = slice.syncState === 'error';
|
||||
|
||||
Reference in New Issue
Block a user