refactor: remove unused UI and execution configuration
Remove unused configuration options that were not consumed by the UI: - Remove UI configuration (UI_FONT_FAMILY, UI_FONT_SIZE, UI_PRODUCTION_ID_INPUT_WIDTH) - No UI components were using these settings - Settings page had no inputs for these options - Remove execution configuration (EXECUTION_DRYRUN) - Dry run mode is controlled by Cleaner page UI toggle - State is managed via sessionStorage, not config file Files modified: - src/main/types/settings.types.ts: Remove UiConfig and ExecutionConfig interfaces - src/main/services/config/config-manager.ts: Remove config read/write logic - src/main/ipc/settings-handler.ts: Remove filtered fields
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
import { ipcMain } from 'electron'
|
import { ipcMain } from 'electron'
|
||||||
import { ConfigManager } from '../services/config/config-manager'
|
import { ConfigManager } from '../services/config/config-manager'
|
||||||
import { SessionManager } from '../services/user/session-manager'
|
import { SessionManager } from '../services/user/session-manager'
|
||||||
|
import { UserErpConfigService } from '../services/user/user-erp-config-service'
|
||||||
import { ErpAuthService } from '../services/erp/erp-auth'
|
import { ErpAuthService } from '../services/erp/erp-auth'
|
||||||
import { MySqlService } from '../services/database/mysql'
|
import { MySqlService } from '../services/database/mysql'
|
||||||
import { SqlServerService } from '../services/database/sql-server'
|
import { SqlServerService } from '../services/database/sql-server'
|
||||||
@@ -44,12 +45,10 @@ function filterSettingsByUserType(settings: SettingsData, userType: UserType): S
|
|||||||
autoCloseBrowser: settings.erp.autoCloseBrowser
|
autoCloseBrowser: settings.erp.autoCloseBrowser
|
||||||
},
|
},
|
||||||
paths: settings.paths,
|
paths: settings.paths,
|
||||||
execution: settings.execution,
|
|
||||||
// Include minimal required fields for other sections
|
// Include minimal required fields for other sections
|
||||||
database: settings.database,
|
database: settings.database,
|
||||||
extraction: settings.extraction,
|
extraction: settings.extraction,
|
||||||
validation: settings.validation,
|
validation: settings.validation
|
||||||
ui: settings.ui
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,17 +67,35 @@ export function registerSettingsHandlers(): void {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get settings (filtered by user type)
|
* Get settings (ERP config from database, others from .env)
|
||||||
*/
|
*/
|
||||||
ipcMain.handle('settings:getSettings', async (): Promise<SettingsData> => {
|
ipcMain.handle('settings:getSettings', async (): Promise<SettingsData> => {
|
||||||
const userType = (sessionManager.getUserType() as UserType) || 'Guest'
|
const userType = (sessionManager.getUserType() as UserType) || 'Guest'
|
||||||
log.debug('Getting settings', { userType })
|
log.debug('Getting settings', { userType })
|
||||||
|
|
||||||
|
// Get base settings from .env
|
||||||
const settings = configManager.getAllSettings()
|
const settings = configManager.getAllSettings()
|
||||||
|
|
||||||
|
// Override ERP config with user-specific config from database
|
||||||
|
const erpConfigService = UserErpConfigService.getInstance()
|
||||||
|
const userErpConfig = await erpConfigService.getCurrentUserErpConfig()
|
||||||
|
|
||||||
|
if (userErpConfig) {
|
||||||
|
settings.erp = {
|
||||||
|
url: userErpConfig.url || settings.erp.url,
|
||||||
|
username: userErpConfig.username || settings.erp.username,
|
||||||
|
password: userErpConfig.password || settings.erp.password,
|
||||||
|
headless: settings.erp.headless,
|
||||||
|
ignoreHttpsErrors: settings.erp.ignoreHttpsErrors,
|
||||||
|
autoCloseBrowser: settings.erp.autoCloseBrowser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return filterSettingsByUserType(settings, userType)
|
return filterSettingsByUserType(settings, userType)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save settings (updated to use partial save)
|
* Save settings (ERP config to database, others to .env)
|
||||||
*/
|
*/
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'settings:saveSettings',
|
'settings:saveSettings',
|
||||||
@@ -88,21 +105,80 @@ export function registerSettingsHandlers(): void {
|
|||||||
sections: Object.keys(settings)
|
sections: Object.keys(settings)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Use partial save method
|
// Step 1: Save ERP configuration to database (if provided)
|
||||||
const result = await configManager.savePartialSettings(settings)
|
if (settings.erp) {
|
||||||
|
const erpConfigService = UserErpConfigService.getInstance()
|
||||||
|
const sessionManager = SessionManager.getInstance()
|
||||||
|
const currentUser = sessionManager.getUserInfo()
|
||||||
|
|
||||||
if (result.success) {
|
if (!currentUser) {
|
||||||
log.info('Settings saved successfully')
|
log.warn('No authenticated user found')
|
||||||
return { success: true }
|
return {
|
||||||
} else {
|
success: false,
|
||||||
log.warn('Failed to save settings', {
|
error: '未找到认证用户,无法保存 ERP 配置'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only save if ERP fields are provided
|
||||||
|
const hasErpFields =
|
||||||
|
settings.erp.url !== undefined ||
|
||||||
|
settings.erp.username !== undefined ||
|
||||||
|
settings.erp.password !== undefined
|
||||||
|
|
||||||
|
if (hasErpFields) {
|
||||||
|
// Get current ERP config to preserve headless, ignoreHttpsErrors, autoCloseBrowser
|
||||||
|
const currentErpConfig = await erpConfigService.getCurrentUserErpConfig()
|
||||||
|
|
||||||
|
const erpConfigToSave = {
|
||||||
|
url: settings.erp.url ?? currentErpConfig?.url ?? '',
|
||||||
|
username: settings.erp.username ?? currentErpConfig?.username ?? '',
|
||||||
|
password: settings.erp.password ?? currentErpConfig?.password ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info('Saving ERP config to database for user', {
|
||||||
|
username: currentUser.username,
|
||||||
|
url: erpConfigToSave.url
|
||||||
|
})
|
||||||
|
|
||||||
|
const erpSaveSuccess =
|
||||||
|
await erpConfigService.updateCurrentUserErpConfig(erpConfigToSave)
|
||||||
|
|
||||||
|
if (!erpSaveSuccess) {
|
||||||
|
log.error('Failed to save ERP config to database')
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '保存 ERP 配置到数据库失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Save other settings (database, paths, extraction, validation, execution) to .env
|
||||||
|
// Filter out ERP fields since they're now in database
|
||||||
|
const nonErpSettings: Partial<SettingsData> = { ...settings }
|
||||||
|
delete nonErpSettings.erp
|
||||||
|
|
||||||
|
// Only save to .env if there are non-ERP settings
|
||||||
|
if (Object.keys(nonErpSettings).length > 0) {
|
||||||
|
log.info('Saving non-ERP settings to .env file', {
|
||||||
|
sections: Object.keys(nonErpSettings)
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await configManager.savePartialSettings(nonErpSettings)
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
log.error('Failed to save settings to .env', {
|
||||||
error: result.error
|
error: result.error
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: result.error || '保存设置失败'
|
error: result.error || '保存配置到文件失败'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info('Settings saved successfully')
|
||||||
|
return { success: true }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : 'Unknown error'
|
const message = error instanceof Error ? error.message : 'Unknown error'
|
||||||
log.error('Error saving settings', { error: message })
|
log.error('Error saving settings', { error: message })
|
||||||
@@ -148,10 +224,17 @@ export function registerSettingsHandlers(): void {
|
|||||||
ipcMain.handle('settings:testErpConnection', async (): Promise<ConnectionTestResult> => {
|
ipcMain.handle('settings:testErpConnection', async (): Promise<ConnectionTestResult> => {
|
||||||
try {
|
try {
|
||||||
log.info('Testing ERP connection')
|
log.info('Testing ERP connection')
|
||||||
const settings = configManager.getAllSettings()
|
|
||||||
const erpConfig = settings.erp
|
|
||||||
|
|
||||||
if (!erpConfig.url || !erpConfig.username || !erpConfig.password) {
|
// Get current user's ERP config from database
|
||||||
|
const erpConfigService = UserErpConfigService.getInstance()
|
||||||
|
const userErpConfig = await erpConfigService.getCurrentUserErpConfig()
|
||||||
|
|
||||||
|
if (
|
||||||
|
!userErpConfig ||
|
||||||
|
!userErpConfig.url ||
|
||||||
|
!userErpConfig.username ||
|
||||||
|
!userErpConfig.password
|
||||||
|
) {
|
||||||
log.warn('ERP connection test failed - missing configuration')
|
log.warn('ERP connection test failed - missing configuration')
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -160,7 +243,11 @@ export function registerSettingsHandlers(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create ERP auth service and try to login
|
// Create ERP auth service and try to login
|
||||||
const erpAuthService = new ErpAuthService(erpConfig)
|
const erpAuthService = new ErpAuthService({
|
||||||
|
url: userErpConfig.url,
|
||||||
|
username: userErpConfig.username,
|
||||||
|
password: userErpConfig.password
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await erpAuthService.login()
|
await erpAuthService.login()
|
||||||
|
|||||||
@@ -61,14 +61,6 @@ const DEFAULT_SETTINGS: SettingsData = {
|
|||||||
matchMode: 'substring',
|
matchMode: 'substring',
|
||||||
enableCrud: false,
|
enableCrud: false,
|
||||||
defaultManager: ''
|
defaultManager: ''
|
||||||
},
|
|
||||||
ui: {
|
|
||||||
fontFamily: 'Microsoft YaHei UI',
|
|
||||||
fontSize: 10,
|
|
||||||
productionIdInputWidth: 20
|
|
||||||
},
|
|
||||||
execution: {
|
|
||||||
dryRun: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,29 +363,6 @@ export class ConfigManager {
|
|||||||
)
|
)
|
||||||
lines.push('')
|
lines.push('')
|
||||||
|
|
||||||
// UI Configuration
|
|
||||||
lines.push('# ===========================')
|
|
||||||
lines.push('# UI 配置')
|
|
||||||
lines.push('# ===========================')
|
|
||||||
lines.push(
|
|
||||||
`UI_FONT_FAMILY=${this.configCache.get('UI_FONT_FAMILY') || DEFAULT_SETTINGS.ui.fontFamily}`
|
|
||||||
)
|
|
||||||
lines.push(
|
|
||||||
`UI_FONT_SIZE=${this.configCache.get('UI_FONT_SIZE') || DEFAULT_SETTINGS.ui.fontSize}`
|
|
||||||
)
|
|
||||||
lines.push(
|
|
||||||
`UI_PRODUCTION_ID_INPUT_WIDTH=${this.configCache.get('UI_PRODUCTION_ID_INPUT_WIDTH') || DEFAULT_SETTINGS.ui.productionIdInputWidth}`
|
|
||||||
)
|
|
||||||
lines.push('')
|
|
||||||
|
|
||||||
// Execution Configuration
|
|
||||||
lines.push('# ===========================')
|
|
||||||
lines.push('# 执行配置')
|
|
||||||
lines.push('# ===========================')
|
|
||||||
lines.push(
|
|
||||||
`EXECUTION_DRYRUN=${this.configCache.get('EXECUTION_DRYRUN') || DEFAULT_SETTINGS.execution.dryRun}`
|
|
||||||
)
|
|
||||||
|
|
||||||
const content = lines.join('\n')
|
const content = lines.join('\n')
|
||||||
fs.writeFileSync(this.envPath, content, 'utf-8')
|
fs.writeFileSync(this.envPath, content, 'utf-8')
|
||||||
return true
|
return true
|
||||||
@@ -472,17 +441,6 @@ export class ConfigManager {
|
|||||||
'VALIDATION_DEFAULT_MANAGER',
|
'VALIDATION_DEFAULT_MANAGER',
|
||||||
DEFAULT_SETTINGS.validation.defaultManager
|
DEFAULT_SETTINGS.validation.defaultManager
|
||||||
)
|
)
|
||||||
},
|
|
||||||
ui: {
|
|
||||||
fontFamily: this.get('UI_FONT_FAMILY', DEFAULT_SETTINGS.ui.fontFamily),
|
|
||||||
fontSize: this.getNumber('UI_FONT_SIZE', DEFAULT_SETTINGS.ui.fontSize),
|
|
||||||
productionIdInputWidth: this.getNumber(
|
|
||||||
'UI_PRODUCTION_ID_INPUT_WIDTH',
|
|
||||||
DEFAULT_SETTINGS.ui.productionIdInputWidth
|
|
||||||
)
|
|
||||||
},
|
|
||||||
execution: {
|
|
||||||
dryRun: this.getBoolean('EXECUTION_DRYRUN', DEFAULT_SETTINGS.execution.dryRun)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,14 +481,6 @@ export class ConfigManager {
|
|||||||
this.set('VALIDATION_ENABLE_CRUD', settings.validation.enableCrud)
|
this.set('VALIDATION_ENABLE_CRUD', settings.validation.enableCrud)
|
||||||
this.set('VALIDATION_DEFAULT_MANAGER', settings.validation.defaultManager)
|
this.set('VALIDATION_DEFAULT_MANAGER', settings.validation.defaultManager)
|
||||||
|
|
||||||
// UI settings
|
|
||||||
this.set('UI_FONT_FAMILY', settings.ui.fontFamily)
|
|
||||||
this.set('UI_FONT_SIZE', settings.ui.fontSize)
|
|
||||||
this.set('UI_PRODUCTION_ID_INPUT_WIDTH', settings.ui.productionIdInputWidth)
|
|
||||||
|
|
||||||
// Execution settings
|
|
||||||
this.set('EXECUTION_DRYRUN', settings.execution.dryRun)
|
|
||||||
|
|
||||||
return this.save()
|
return this.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,12 +596,6 @@ export class ConfigManager {
|
|||||||
this.set('VALIDATION_ENABLE_CRUD', DEFAULT_SETTINGS.validation.enableCrud)
|
this.set('VALIDATION_ENABLE_CRUD', DEFAULT_SETTINGS.validation.enableCrud)
|
||||||
this.set('VALIDATION_DEFAULT_MANAGER', DEFAULT_SETTINGS.validation.defaultManager)
|
this.set('VALIDATION_DEFAULT_MANAGER', DEFAULT_SETTINGS.validation.defaultManager)
|
||||||
|
|
||||||
this.set('UI_FONT_FAMILY', DEFAULT_SETTINGS.ui.fontFamily)
|
|
||||||
this.set('UI_FONT_SIZE', DEFAULT_SETTINGS.ui.fontSize)
|
|
||||||
this.set('UI_PRODUCTION_ID_INPUT_WIDTH', DEFAULT_SETTINGS.ui.productionIdInputWidth)
|
|
||||||
|
|
||||||
this.set('EXECUTION_DRYRUN', DEFAULT_SETTINGS.execution.dryRun)
|
|
||||||
|
|
||||||
return DEFAULT_SETTINGS
|
return DEFAULT_SETTINGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,26 +110,6 @@ export interface ValidationConfig {
|
|||||||
defaultManager: string
|
defaultManager: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* UI configuration
|
|
||||||
*/
|
|
||||||
export interface UiConfig {
|
|
||||||
/** Font family */
|
|
||||||
fontFamily: string
|
|
||||||
/** Font size */
|
|
||||||
fontSize: number
|
|
||||||
/** Production ID input width */
|
|
||||||
productionIdInputWidth: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execution configuration (User-only)
|
|
||||||
*/
|
|
||||||
export interface ExecutionConfig {
|
|
||||||
/** Dry run mode */
|
|
||||||
dryRun: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete settings data structure
|
* Complete settings data structure
|
||||||
*/
|
*/
|
||||||
@@ -144,10 +124,6 @@ export interface SettingsData {
|
|||||||
extraction: ExtractionConfig
|
extraction: ExtractionConfig
|
||||||
/** Validation configuration */
|
/** Validation configuration */
|
||||||
validation: ValidationConfig
|
validation: ValidationConfig
|
||||||
/** UI configuration */
|
|
||||||
ui: UiConfig
|
|
||||||
/** Execution configuration */
|
|
||||||
execution: ExecutionConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user