修复底层配置服务混乱的问题

This commit is contained in:
cc
2026-04-29 23:59:56 +08:00
parent 7469337aeb
commit 1fc710ccef
10 changed files with 131 additions and 196 deletions

View File

@@ -8,6 +8,77 @@ const handleElectronOnStart = (options: { reload: () => void }) => {
options.reload()
}
const exportWorkerElectronShimPlugin = () => {
const virtualId = 'virtual:weflow-export-worker-electron'
const resolvedVirtualId = `\0${virtualId}`
return {
name: 'weflow-export-worker-electron-shim',
enforce: 'pre' as const,
resolveId(id: string) {
if (id === virtualId) return resolvedVirtualId
return null
},
load(id: string) {
if (id !== resolvedVirtualId) return null
return `
import { homedir, tmpdir } from 'os'
import { join } from 'path'
const workerUserDataPath = () => String(process.env.WEFLOW_USER_DATA_PATH || process.env.WEFLOW_CONFIG_CWD || '').trim()
const appDataPath = () => {
if (process.platform === 'win32' && process.env.APPDATA) return process.env.APPDATA
if (process.platform === 'darwin') return join(homedir(), 'Library', 'Application Support')
return process.env.XDG_CONFIG_HOME || join(homedir(), '.config')
}
const getPath = (name) => {
if (name === 'userData') return workerUserDataPath() || join(appDataPath(), 'WeFlow')
if (name === 'documents') return join(homedir(), 'Documents')
if (name === 'desktop') return join(homedir(), 'Desktop')
if (name === 'downloads') return join(homedir(), 'Downloads')
if (name === 'temp') return tmpdir()
if (name === 'appData') return appDataPath()
return process.cwd()
}
export const app = {
isPackaged: Boolean(process.resourcesPath && process.env.NODE_ENV !== 'development'),
getPath,
getAppPath: () => process.cwd(),
getName: () => 'WeFlow',
getVersion: () => process.env.npm_package_version || '0.0.0'
}
export const BrowserWindow = { getAllWindows: () => [] }
export const dialog = { showMessageBox: async () => ({ response: 0, checkboxChecked: false }) }
export const shell = { openExternal: async () => false, showItemInFolder: () => {} }
export const ipcMain = { on: () => {}, handle: () => {}, removeHandler: () => {} }
export const ipcRenderer = { sendSync: () => ({}) }
export const safeStorage = {
isEncryptionAvailable: () => false,
encryptString: (value) => Buffer.from(String(value || ''), 'utf8'),
decryptString: (value) => Buffer.isBuffer(value) ? value.toString('utf8') : Buffer.from(value).toString('utf8')
}
export const Notification = class {
static isSupported() { return false }
on() { return this }
show() {}
close() {}
}
export default { app, BrowserWindow, dialog, shell, ipcMain, ipcRenderer, safeStorage, Notification }
`
},
transform(code: string, id: string) {
if (!/\.[cm]?[jt]s$/.test(id)) return null
if (!code.includes("'electron'") && !code.includes('"electron"')) return null
const next = code
.replace(/from\s+(['"])electron\1/g, `from '${virtualId}'`)
.replace(/import\s*\(\s*(['"])electron\1\s*\)/g, `import('${virtualId}')`)
.replace(/require\s*\(\s*(['"])electron\1\s*\)/g, `require('${virtualId}')`)
return next === code ? null : { code: next, map: null }
}
}
}
export default defineConfig({
base: './',
server: {
@@ -142,6 +213,7 @@ export default defineConfig({
entry: 'electron/exportWorker.ts',
onstart: handleElectronOnStart,
vite: {
plugins: [exportWorkerElectronShimPlugin()],
build: {
outDir: 'dist-electron',
rollupOptions: {