mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-28 07:25:53 +00:00
feat: 保存api服务的配置,实现随weflow静默启动
This commit is contained in:
@@ -130,6 +130,8 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
showMessage('已清除 Access Token,API 将允许无鉴权访问', true)
|
||||
}
|
||||
|
||||
|
||||
|
||||
const [autoTranscribeVoice, setAutoTranscribeVoice] = useState(false)
|
||||
const [transcribeLanguages, setTranscribeLanguages] = useState<string[]>(['zh'])
|
||||
|
||||
@@ -344,6 +346,9 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
const savedHttpApiToken = await configService.getHttpApiToken()
|
||||
if (savedHttpApiToken) setHttpApiToken(savedHttpApiToken)
|
||||
|
||||
const savedApiPort = await configService.getHttpApiPort()
|
||||
if (savedApiPort) setHttpApiPort(savedApiPort)
|
||||
|
||||
setAuthEnabled(savedAuthEnabled)
|
||||
setAuthUseHello(savedAuthUseHello)
|
||||
setIsLockMode(savedIsLockMode)
|
||||
@@ -386,6 +391,8 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
const savedAnalyticsConsent = await configService.getAnalyticsConsent()
|
||||
setAnalyticsConsent(savedAnalyticsConsent ?? false)
|
||||
|
||||
|
||||
|
||||
// 如果语言列表为空,保存默认值
|
||||
if (!savedTranscribeLanguages || savedTranscribeLanguages.length === 0) {
|
||||
const defaultLanguages = ['zh']
|
||||
@@ -1850,6 +1857,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
try {
|
||||
await window.electronAPI.http.stop()
|
||||
setHttpApiRunning(false)
|
||||
await configService.setHttpApiEnabled(false)
|
||||
showMessage('API 服务已停止', true)
|
||||
} catch (e: any) {
|
||||
showMessage(`操作失败: ${e}`, false)
|
||||
@@ -1867,6 +1875,10 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
if (result.success) {
|
||||
setHttpApiRunning(true)
|
||||
if (result.port) setHttpApiPort(result.port)
|
||||
|
||||
await configService.setHttpApiEnabled(true)
|
||||
await configService.setHttpApiPort(result.port || httpApiPort)
|
||||
|
||||
showMessage(`API 服务已启动,端口 ${result.port}`, true)
|
||||
} else {
|
||||
showMessage(`启动失败: ${result.error}`, false)
|
||||
@@ -1915,14 +1927,18 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
||||
<label>服务端口</label>
|
||||
<span className="form-hint">API 服务监听的端口号(1024-65535)</span>
|
||||
<input
|
||||
type="number"
|
||||
className="field-input"
|
||||
value={httpApiPort}
|
||||
onChange={(e) => setHttpApiPort(parseInt(e.target.value, 10) || 5031)}
|
||||
disabled={httpApiRunning}
|
||||
style={{ width: 120 }}
|
||||
min={1024}
|
||||
max={65535}
|
||||
type="number"
|
||||
className="field-input"
|
||||
value={httpApiPort}
|
||||
onChange={(e) => {
|
||||
const port = parseInt(e.target.value, 10) || 5031
|
||||
setHttpApiPort(port)
|
||||
scheduleConfigSave('httpApiPort', () => configService.setHttpApiPort(port))
|
||||
}}
|
||||
disabled={httpApiRunning}
|
||||
style={{ width: 120 }}
|
||||
min={1024}
|
||||
max={65535}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ export const CONFIG_KEYS = {
|
||||
NOTIFICATION_FILTER_MODE: 'notificationFilterMode',
|
||||
NOTIFICATION_FILTER_LIST: 'notificationFilterList',
|
||||
HTTP_API_TOKEN: 'httpApiToken',
|
||||
HTTP_API_ENABLED: 'httpApiEnabled',
|
||||
HTTP_API_PORT: 'httpApiPort',
|
||||
MESSAGE_PUSH_ENABLED: 'messagePushEnabled',
|
||||
WINDOW_CLOSE_BEHAVIOR: 'windowCloseBehavior',
|
||||
QUOTE_LAYOUT: 'quoteLayout',
|
||||
@@ -1484,3 +1486,26 @@ export async function getAnalyticsDenyCount(): Promise<number> {
|
||||
export async function setAnalyticsDenyCount(count: number): Promise<void> {
|
||||
await config.set(CONFIG_KEYS.ANALYTICS_DENY_COUNT, count)
|
||||
}
|
||||
|
||||
|
||||
// 获取 HTTP API 自动启动状态
|
||||
export async function getHttpApiEnabled(): Promise<boolean> {
|
||||
const value = await config.get(CONFIG_KEYS.HTTP_API_ENABLED)
|
||||
return value === true
|
||||
}
|
||||
|
||||
// 设置 HTTP API 自动启动状态
|
||||
export async function setHttpApiEnabled(enabled: boolean): Promise<void> {
|
||||
await config.set(CONFIG_KEYS.HTTP_API_ENABLED, enabled)
|
||||
}
|
||||
|
||||
// 获取 HTTP API 端口
|
||||
export async function getHttpApiPort(): Promise<number> {
|
||||
const value = await config.get(CONFIG_KEYS.HTTP_API_PORT)
|
||||
return typeof value === 'number' ? value : 5031
|
||||
}
|
||||
|
||||
// 设置 HTTP API 端口
|
||||
export async function setHttpApiPort(port: number): Promise<void> {
|
||||
await config.set(CONFIG_KEYS.HTTP_API_PORT, port)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user