fix desktop tray icon telegram topics and checkin intervals

This commit is contained in:
cita
2026-03-20 12:16:00 +08:00
parent 2de5eebf29
commit 220f786204
23 changed files with 808 additions and 42 deletions
+11 -1
View File
@@ -42,6 +42,7 @@ describe('NotificationSettings', () => {
telegramEnabled: true,
telegramApiBaseUrl: 'https://tg-proxy.example.com',
telegramChatId: '-1001234567890',
telegramMessageThreadId: '77',
telegramBotTokenMasked: '1234****token',
telegramUseSystemProxy: false,
smtpEnabled: false,
@@ -56,6 +57,7 @@ describe('NotificationSettings', () => {
apiMock.updateRuntimeSettings.mockResolvedValue({
success: true,
telegramApiBaseUrl: 'https://proxy.example.com/custom',
telegramMessageThreadId: '88',
telegramBotTokenMasked: '1234****token',
});
apiMock.testNotification.mockResolvedValue({ success: true });
@@ -65,7 +67,7 @@ describe('NotificationSettings', () => {
vi.clearAllMocks();
});
it('loads and saves telegram api base url', async () => {
it('loads and saves telegram api base url and topic id', async () => {
let root: ReturnType<typeof create> | null = null;
try {
await act(async () => {
@@ -85,8 +87,15 @@ describe('NotificationSettings', () => {
));
expect(proxyInput.props.value).toBe('https://tg-proxy.example.com');
const topicInput = root.root.find((node) => (
node.type === 'input'
&& node.props.placeholder === '例如: 77'
));
expect(topicInput.props.value).toBe('77');
await act(async () => {
proxyInput.props.onChange({ target: { value: 'https://proxy.example.com/custom/' } });
topicInput.props.onChange({ target: { value: '88' } });
});
const saveButton = root.root.find((node) => (
@@ -101,6 +110,7 @@ describe('NotificationSettings', () => {
expect(apiMock.updateRuntimeSettings).toHaveBeenCalledWith(expect.objectContaining({
telegramApiBaseUrl: 'https://proxy.example.com/custom/',
telegramMessageThreadId: '88',
}));
} finally {
root?.unmount();
+14
View File
@@ -13,6 +13,7 @@ type RuntimeSettings = {
telegramApiBaseUrl: string;
telegramChatId: string;
telegramUseSystemProxy: boolean;
telegramMessageThreadId: string;
smtpEnabled: boolean;
smtpHost: string;
smtpPort: number;
@@ -37,6 +38,7 @@ export default function NotificationSettings() {
telegramApiBaseUrl: 'https://api.telegram.org',
telegramChatId: '',
telegramUseSystemProxy: false,
telegramMessageThreadId: '',
smtpEnabled: false,
smtpHost: '',
smtpPort: 587,
@@ -81,6 +83,7 @@ export default function NotificationSettings() {
telegramApiBaseUrl: runtimeInfo.telegramApiBaseUrl || 'https://api.telegram.org',
telegramChatId: runtimeInfo.telegramChatId || '',
telegramUseSystemProxy: !!runtimeInfo.telegramUseSystemProxy,
telegramMessageThreadId: runtimeInfo.telegramMessageThreadId || '',
smtpEnabled: !!runtimeInfo.smtpEnabled,
smtpHost: runtimeInfo.smtpHost || '',
smtpPort: Number(runtimeInfo.smtpPort) || 587,
@@ -119,6 +122,7 @@ export default function NotificationSettings() {
telegramApiBaseUrl: runtime.telegramApiBaseUrl,
telegramChatId: runtime.telegramChatId,
telegramUseSystemProxy: runtime.telegramUseSystemProxy,
telegramMessageThreadId: runtime.telegramMessageThreadId,
smtpEnabled: runtime.smtpEnabled,
smtpHost: runtime.smtpHost,
smtpPort: runtime.smtpPort,
@@ -367,6 +371,16 @@ export default function NotificationSettings() {
disabled={!runtime.telegramEnabled}
/>
</div>
<div>
<div style={{ fontSize: 13, fontWeight: 500, marginBottom: 8, color: 'var(--color-text-secondary)' }}>Telegram Topic ID</div>
<input
value={runtime.telegramMessageThreadId}
onChange={(e) => setRuntime((prev) => ({ ...prev, telegramMessageThreadId: e.target.value }))}
placeholder="例如: 77"
style={inputStyle}
disabled={!runtime.telegramEnabled}
/>
</div>
<div>
<div style={{ fontSize: 13, fontWeight: 500, marginBottom: 8, color: 'var(--color-text-secondary)' }}>
Telegram Bot Token
+60
View File
@@ -26,6 +26,8 @@ type DbDialect = 'sqlite' | 'mysql' | 'postgres';
type RuntimeSettings = {
checkinCron: string;
checkinScheduleMode: 'cron' | 'interval';
checkinIntervalHours: number;
balanceRefreshCron: string;
logCleanupCron: string;
logCleanupUsageLogsEnabled: boolean;
@@ -187,6 +189,8 @@ export default function Settings() {
const navigate = useNavigate();
const [runtime, setRuntime] = useState<RuntimeSettings>({
checkinCron: '0 8 * * *',
checkinScheduleMode: 'cron',
checkinIntervalHours: 6,
balanceRefreshCron: '0 * * * *',
logCleanupCron: '0 6 * * *',
logCleanupUsageLogsEnabled: false,
@@ -203,6 +207,7 @@ export default function Settings() {
const [maskedToken, setMaskedToken] = useState('');
const [loading, setLoading] = useState(true);
const [savingSchedule, setSavingSchedule] = useState(false);
const [testingCheckin, setTestingCheckin] = useState(false);
const [savingToken, setSavingToken] = useState(false);
const [savingSystemProxy, setSavingSystemProxy] = useState(false);
const [savingProxyFailureRules, setSavingProxyFailureRules] = useState(false);
@@ -397,6 +402,10 @@ export default function Settings() {
setMaskedToken(authInfo.masked || '****');
setRuntime({
checkinCron: runtimeInfo.checkinCron || '0 8 * * *',
checkinScheduleMode: runtimeInfo.checkinScheduleMode === 'interval' ? 'interval' : 'cron',
checkinIntervalHours: Number(runtimeInfo.checkinIntervalHours) >= 1
? Math.min(24, Math.trunc(Number(runtimeInfo.checkinIntervalHours)))
: 6,
balanceRefreshCron: runtimeInfo.balanceRefreshCron || '0 * * * *',
logCleanupCron: runtimeInfo.logCleanupCron || '0 6 * * *',
logCleanupUsageLogsEnabled: !!runtimeInfo.logCleanupUsageLogsEnabled,
@@ -488,6 +497,8 @@ export default function Settings() {
try {
await api.updateRuntimeSettings({
checkinCron: runtime.checkinCron,
checkinScheduleMode: runtime.checkinScheduleMode,
checkinIntervalHours: runtime.checkinIntervalHours,
balanceRefreshCron: runtime.balanceRefreshCron,
logCleanupCron: runtime.logCleanupCron,
logCleanupUsageLogsEnabled: runtime.logCleanupUsageLogsEnabled,
@@ -502,6 +513,18 @@ export default function Settings() {
}
};
const triggerScheduleCheckin = async () => {
setTestingCheckin(true);
try {
await api.triggerCheckinAll();
toast.success('已开始全部签到,请稍后查看签到日志');
} catch (err: any) {
toast.error(err?.message || '触发签到失败');
} finally {
setTestingCheckin(false);
}
};
const saveProxyToken = async () => {
const suffix = proxyTokenSuffix.trim();
if (!suffix) {
@@ -953,6 +976,42 @@ export default function Settings() {
<div className="card animate-slide-up stagger-2" style={{ padding: 20 }}>
<div style={{ fontWeight: 600, fontSize: 14, marginBottom: 12 }}>定时任务</div>
<div style={{ display: 'grid', gridTemplateColumns: '180px 180px auto', gap: 12, alignItems: 'end', marginBottom: 12 }}>
<div>
<div style={{ fontSize: 12, color: 'var(--color-text-muted)', marginBottom: 6 }}>签到方式</div>
<select
value={runtime.checkinScheduleMode}
onChange={(e) => setRuntime((prev) => ({
...prev,
checkinScheduleMode: e.target.value === 'interval' ? 'interval' : 'cron',
}))}
style={inputStyle}
>
<option value="cron">Cron</option>
<option value="interval">间隔签到</option>
</select>
</div>
<div>
<div style={{ fontSize: 12, color: 'var(--color-text-muted)', marginBottom: 6 }}>签到间隔</div>
<select
value={String(runtime.checkinIntervalHours)}
onChange={(e) => setRuntime((prev) => ({
...prev,
checkinIntervalHours: Math.min(24, Math.max(1, Math.trunc(Number(e.target.value) || 1))),
}))}
style={inputStyle}
disabled={runtime.checkinScheduleMode !== 'interval'}
>
{Array.from({ length: 24 }, (_, index) => {
const hour = index + 1;
return <option key={hour} value={hour}>{hour} 小时</option>;
})}
</select>
</div>
<button onClick={triggerScheduleCheckin} disabled={testingCheckin} className="btn btn-secondary">
{testingCheckin ? '触发中...' : '测试一次签到'}
</button>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
<div>
<div style={{ fontSize: 12, color: 'var(--color-text-muted)', marginBottom: 6 }}>签到 Cron</div>
@@ -960,6 +1019,7 @@ export default function Settings() {
value={runtime.checkinCron}
onChange={(e) => setRuntime((prev) => ({ ...prev, checkinCron: e.target.value }))}
style={{ ...inputStyle, fontFamily: 'var(--font-mono)' }}
disabled={runtime.checkinScheduleMode !== 'cron'}
/>
</div>
<div>
@@ -12,6 +12,7 @@ const { apiMock } = vi.hoisted(() => ({
getRoutesLite: vi.fn(),
getRuntimeDatabaseConfig: vi.fn(),
updateRuntimeSettings: vi.fn(),
triggerCheckinAll: vi.fn(),
},
}));
@@ -46,6 +47,8 @@ describe('Settings log cleanup schedule', () => {
apiMock.getAuthInfo.mockResolvedValue({ masked: 'sk-****' });
apiMock.getRuntimeSettings.mockResolvedValue({
checkinCron: '0 8 * * *',
checkinScheduleMode: 'interval',
checkinIntervalHours: 6,
balanceRefreshCron: '0 * * * *',
logCleanupCron: '15 4 * * *',
logCleanupUsageLogsEnabled: true,
@@ -70,7 +73,7 @@ describe('Settings log cleanup schedule', () => {
vi.clearAllMocks();
});
it('saves log cleanup fields together with other schedule settings', async () => {
it('saves schedule mode and interval fields together with other schedule settings', async () => {
let root: ReturnType<typeof create> | null = null;
try {
await act(async () => {
@@ -97,6 +100,8 @@ describe('Settings log cleanup schedule', () => {
expect(apiMock.updateRuntimeSettings).toHaveBeenCalledWith({
checkinCron: '0 8 * * *',
checkinScheduleMode: 'interval',
checkinIntervalHours: 6,
balanceRefreshCron: '0 * * * *',
logCleanupCron: '15 4 * * *',
logCleanupUsageLogsEnabled: true,
@@ -107,4 +112,37 @@ describe('Settings log cleanup schedule', () => {
root?.unmount();
}
});
it('triggers a one-off checkin from the schedule card', async () => {
apiMock.triggerCheckinAll.mockResolvedValue({ success: true });
let root: ReturnType<typeof create> | null = null;
try {
await act(async () => {
root = create(
<MemoryRouter>
<ToastProvider>
<Settings />
</ToastProvider>
</MemoryRouter>,
);
});
await flushMicrotasks();
const triggerButton = root.root.find((node) => (
node.type === 'button'
&& typeof node.props.onClick === 'function'
&& collectText(node).trim() === '测试一次签到'
));
await act(async () => {
await triggerButton.props.onClick();
});
await flushMicrotasks();
expect(apiMock.triggerCheckinAll).toHaveBeenCalledTimes(1);
} finally {
root?.unmount();
}
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB