mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-28 15:09:19 +00:00
fix: support service runtime fallbacks
This commit is contained in:
@@ -6,7 +6,6 @@ import * as https from 'https'
|
||||
import * as http from 'http'
|
||||
import * as fzstd from 'fzstd'
|
||||
import * as crypto from 'crypto'
|
||||
import { app, BrowserWindow, dialog } from 'electron'
|
||||
import { ConfigService } from './config'
|
||||
import { wcdbService } from './wcdbService'
|
||||
import { MessageCacheService } from './messageCacheService'
|
||||
@@ -18,6 +17,7 @@ import { voiceTranscribeService } from './voiceTranscribeService'
|
||||
import { ImageDecryptService } from './imageDecryptService'
|
||||
import { CONTACT_REGION_LOOKUP_DATA } from './contactRegionLookupData'
|
||||
import { LRUCache } from '../utils/LRUCache.js'
|
||||
import { getAppPathFallback, getElectronBrowserWindow, getElectronDialog, getPathFallback, isElectronAppPackaged } from './electronRuntime'
|
||||
|
||||
export interface ChatSession {
|
||||
username: string
|
||||
@@ -498,7 +498,7 @@ class ChatService {
|
||||
}
|
||||
|
||||
private async maybeShowInitFailureDialog(errorMessage: string): Promise<void> {
|
||||
if (!app.isPackaged) return
|
||||
if (!isElectronAppPackaged()) return
|
||||
if (this.initFailureDialogShown) return
|
||||
|
||||
const code = this.extractErrorCode(errorMessage)
|
||||
@@ -519,6 +519,8 @@ class ChatService {
|
||||
].join('\n')
|
||||
|
||||
try {
|
||||
const dialog = getElectronDialog()
|
||||
if (!dialog?.showMessageBox) return
|
||||
await dialog.showMessageBox({
|
||||
type: 'error',
|
||||
title: 'WeFlow 启动失败',
|
||||
@@ -600,7 +602,7 @@ class ChatService {
|
||||
console.error('[ChatService] 数据库监听回调失败:', error)
|
||||
}
|
||||
}
|
||||
const windows = BrowserWindow.getAllWindows()
|
||||
const windows = getElectronBrowserWindow()?.getAllWindows?.() || []
|
||||
// 广播给所有渲染进程窗口
|
||||
windows.forEach((win) => {
|
||||
if (!win.isDestroyed()) {
|
||||
@@ -7180,7 +7182,7 @@ class ChatService {
|
||||
return join(cachePath, 'Voices')
|
||||
}
|
||||
// 回退到默认目录
|
||||
const documentsPath = app.getPath('documents')
|
||||
const documentsPath = getPathFallback('documents')
|
||||
return join(documentsPath, 'WeFlow', 'Voices')
|
||||
}
|
||||
|
||||
@@ -7190,7 +7192,7 @@ class ChatService {
|
||||
return join(cachePath, 'Emojis')
|
||||
}
|
||||
// 回退到默认目录
|
||||
const documentsPath = app.getPath('documents')
|
||||
const documentsPath = getPathFallback('documents')
|
||||
return join(documentsPath, 'WeFlow', 'Emojis')
|
||||
}
|
||||
|
||||
@@ -8435,13 +8437,13 @@ class ChatService {
|
||||
private async decodeSilkToPcm(silkData: Buffer, sampleRate: number): Promise<Buffer | null> {
|
||||
try {
|
||||
let wasmPath: string
|
||||
if (app.isPackaged) {
|
||||
if (isElectronAppPackaged()) {
|
||||
wasmPath = join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
|
||||
if (!existsSync(wasmPath)) {
|
||||
wasmPath = join(process.resourcesPath, 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
|
||||
}
|
||||
} else {
|
||||
wasmPath = join(app.getAppPath(), 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
|
||||
wasmPath = join(getAppPathFallback(), 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
|
||||
}
|
||||
|
||||
if (!existsSync(wasmPath)) {
|
||||
@@ -8629,7 +8631,7 @@ class ChatService {
|
||||
/** 获取持久化转写缓存文件路径 */
|
||||
private getTranscriptCachePath(): string {
|
||||
const cachePath = this.configService.get('cachePath')
|
||||
const base = cachePath || join(app.getPath('documents'), 'WeFlow')
|
||||
const base = cachePath || join(getPathFallback('documents'), 'WeFlow')
|
||||
return join(base, 'Voices', 'transcripts.json')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user