mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-25 07:16:51 +00:00
feat: 保存api服务的配置,实现随weflow静默启动
This commit is contained in:
@@ -2825,6 +2825,8 @@ app.whenReady().then(async () => {
|
||||
// 启动时检测更新(不阻塞启动)
|
||||
checkForUpdatesOnStartup()
|
||||
|
||||
await httpService.autoStart()
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
mainWindow = createWindow()
|
||||
|
||||
@@ -52,6 +52,8 @@ interface ConfigSchema {
|
||||
notificationFilterMode: 'all' | 'whitelist' | 'blacklist'
|
||||
notificationFilterList: string[]
|
||||
messagePushEnabled: boolean
|
||||
httpApiEnabled: boolean
|
||||
httpApiPort: number
|
||||
httpApiToken: string
|
||||
windowCloseBehavior: 'ask' | 'tray' | 'quit'
|
||||
quoteLayout: 'quote-top' | 'quote-bottom'
|
||||
@@ -121,6 +123,8 @@ export class ConfigService {
|
||||
notificationFilterMode: 'all',
|
||||
notificationFilterList: [],
|
||||
httpApiToken: '',
|
||||
httpApiEnabled: false,
|
||||
httpApiPort: 5031,
|
||||
messagePushEnabled: false,
|
||||
windowCloseBehavior: 'ask',
|
||||
quoteLayout: 'quote-top',
|
||||
@@ -664,11 +668,9 @@ export class ConfigService {
|
||||
|
||||
// 即使 authEnabled 被删除/篡改,如果密钥是 lock: 格式,说明曾开启过应用锁
|
||||
const rawDecryptKey: any = this.store.get('decryptKey')
|
||||
if (typeof rawDecryptKey === 'string' && rawDecryptKey.startsWith(LOCK_PREFIX)) {
|
||||
return true
|
||||
}
|
||||
return typeof rawDecryptKey === 'string' && rawDecryptKey.startsWith(LOCK_PREFIX);
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// === 工具方法 ===
|
||||
|
||||
@@ -246,6 +246,19 @@ class HttpService {
|
||||
}
|
||||
}
|
||||
|
||||
async autoStart(): Promise<void> {
|
||||
const enabled = this.configService.get('httpApiEnabled')
|
||||
if (enabled) {
|
||||
const port = Number(this.configService.get('httpApiPort')) || 5031
|
||||
try {
|
||||
await this.start(port)
|
||||
console.log(`[HttpService] Auto-started on port ${port}`)
|
||||
} catch (err) {
|
||||
console.error('[HttpService] Auto-start failed:', err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 POST 请求的 JSON Body
|
||||
*/
|
||||
@@ -282,9 +295,9 @@ class HttpService {
|
||||
if (queryToken && queryToken.trim() === expectedToken) return true
|
||||
|
||||
const bodyToken = body['access_token']
|
||||
if (bodyToken && String(bodyToken).trim() === expectedToken) return true
|
||||
return !!(bodyToken && String(bodyToken).trim() === expectedToken);
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user