新增了一个消息推送

This commit is contained in:
xuncha
2026-03-17 23:29:21 +08:00
parent d0457a2782
commit e0b2f152b0
8 changed files with 621 additions and 15 deletions

View File

@@ -171,6 +171,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const [httpApiMediaExportPath, setHttpApiMediaExportPath] = useState('')
const [isTogglingApi, setIsTogglingApi] = useState(false)
const [showApiWarning, setShowApiWarning] = useState(false)
const [messagePushEnabled, setMessagePushEnabled] = useState(false)
const isClearingCache = isClearingAnalyticsCache || isClearingImageCache || isClearingAllCache
@@ -296,6 +297,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const savedNotificationPosition = await configService.getNotificationPosition()
const savedNotificationFilterMode = await configService.getNotificationFilterMode()
const savedNotificationFilterList = await configService.getNotificationFilterList()
const savedMessagePushEnabled = await configService.getMessagePushEnabled()
const savedWindowCloseBehavior = await configService.getWindowCloseBehavior()
const savedAuthEnabled = await window.electronAPI.auth.verifyEnabled()
@@ -332,6 +334,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
setNotificationPosition(savedNotificationPosition)
setNotificationFilterMode(savedNotificationFilterMode)
setNotificationFilterList(savedNotificationFilterList)
setMessagePushEnabled(savedMessagePushEnabled)
setWindowCloseBehavior(savedWindowCloseBehavior)
const savedExcludeWords = await configService.getWordCloudExcludeWords()
@@ -1746,6 +1749,12 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
showMessage('已复制 API 地址', true)
}
const handleToggleMessagePush = async (enabled: boolean) => {
setMessagePushEnabled(enabled)
await configService.setMessagePushEnabled(enabled)
showMessage(enabled ? '已开启主动推送' : '已关闭主动推送', true)
}
const renderApiTab = () => (
<div className="tab-content">
<div className="form-group">
@@ -1812,6 +1821,70 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
/>
</div>
<div className="divider" />
<div className="form-group">
<label></label>
<span className="form-hint"> API SSE </span>
<div className="log-toggle-line">
<span className="log-status">
{messagePushEnabled ? '已开启' : '已关闭'}
</span>
<label className="switch">
<input
type="checkbox"
checked={messagePushEnabled}
onChange={(e) => { void handleToggleMessagePush(e.target.checked) }}
/>
<span className="switch-slider" />
</label>
</div>
</div>
<div className="form-group">
<label></label>
<span className="form-hint"> SSE `HTTP API 服务`</span>
<div className="api-url-display">
<input
type="text"
className="field-input"
value={`http://127.0.0.1:${httpApiPort}/api/v1/push/messages`}
readOnly
/>
<button
className="btn btn-secondary"
onClick={() => {
navigator.clipboard.writeText(`http://127.0.0.1:${httpApiPort}/api/v1/push/messages`)
showMessage('已复制推送地址', true)
}}
title="复制"
>
<Copy size={16} />
</button>
</div>
</div>
<div className="form-group">
<label></label>
<span className="form-hint">SSE `message.new` `avatarUrl/sourceName/content` `groupName`</span>
<div className="api-docs">
<div className="api-item">
<div className="api-endpoint">
<span className="method get">GET</span>
<code>{`http://127.0.0.1:${httpApiPort}/api/v1/push/messages`}</code>
</div>
<p className="api-desc"> SSE `messageKey` </p>
<div className="api-params">
{['event', 'sessionId', 'messageKey', 'avatarUrl', 'sourceName', 'groupName?', 'content'].map((param) => (
<span key={param} className="param">
<code>{param}</code>
</span>
))}
</div>
</div>
</div>
</div>
{showApiWarning && (
<div className="modal-overlay" onClick={() => setShowApiWarning(false)}>
<div className="api-warning-modal" onClick={(e) => e.stopPropagation()}>

View File

@@ -63,6 +63,7 @@ export const CONFIG_KEYS = {
NOTIFICATION_POSITION: 'notificationPosition',
NOTIFICATION_FILTER_MODE: 'notificationFilterMode',
NOTIFICATION_FILTER_LIST: 'notificationFilterList',
MESSAGE_PUSH_ENABLED: 'messagePushEnabled',
WINDOW_CLOSE_BEHAVIOR: 'windowCloseBehavior',
// 词云
@@ -1362,6 +1363,15 @@ export async function setNotificationFilterList(list: string[]): Promise<void> {
await config.set(CONFIG_KEYS.NOTIFICATION_FILTER_LIST, list)
}
export async function getMessagePushEnabled(): Promise<boolean> {
const value = await config.get(CONFIG_KEYS.MESSAGE_PUSH_ENABLED)
return value === true
}
export async function setMessagePushEnabled(enabled: boolean): Promise<void> {
await config.set(CONFIG_KEYS.MESSAGE_PUSH_ENABLED, enabled)
}
export async function getWindowCloseBehavior(): Promise<WindowCloseBehavior> {
const value = await config.get(CONFIG_KEYS.WINDOW_CLOSE_BEHAVIOR)
if (value === 'tray' || value === 'quit') return value