优化一些bug

This commit is contained in:
24kycj
2026-05-27 00:17:13 +08:00
parent 79174e7e03
commit 22b17aed35
48 changed files with 1529 additions and 388 deletions
+4 -3
View File
@@ -5,17 +5,18 @@ import path from 'path'
interface AppConfig {
sharedDir: string
templateDir: string
/** 开发默认 true:不调用 SAPI_Init,避免无打印机时 DLL 刷错 */
/** G2 门禁 false:启动即 SAPI_Init;仅调试可改 true */
skipDllInit: boolean
}
const defaultShared = path.join(app.getPath('userData'), 'Cardsoon', 'tasks')
const defaultShared = path.join('C:', 'PrintTasks')
export const configStore = new Store<AppConfig>({
name: 'cardsoon-config',
defaults: {
sharedDir: defaultShared,
templateDir: path.join(app.getPath('userData'), 'Cardsoon', 'templates'),
skipDllInit: !app.isPackaged
// 正式版始终 Init;仅开发时可通过 --skip-dll-init 临时跳过
skipDllInit: false
}
})
+6 -2
View File
@@ -83,6 +83,10 @@ export function setupNativeWorkingDir(): void {
}
ensureBundledConfig(nativeDir)
deployRuntimeConfigs(nativeDir)
process.chdir(nativeDir)
log.debug(`Native working directory: ${nativeDir}`)
const execDir = getProcessExecDir()
const pathHead = [nativeDir, execDir].join(path.delimiter)
if (!process.env.PATH?.toLowerCase().includes(nativeDir.toLowerCase())) {
process.env.PATH = `${pathHead}${path.delimiter}${process.env.PATH || ''}`
}
log.debug(`Native DLL search path: ${nativeDir}; cwd kept at ${process.cwd()}`)
}
+14 -7
View File
@@ -13,17 +13,25 @@ export function setPollMainWindow(win: BrowserWindow): void {
mainWindow = win
}
export function getPollMainWindow(): BrowserWindow | null {
return mainWindow && !mainWindow.isDestroyed() ? mainWindow : null
}
function send(channel: string, payload: unknown): void {
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send(channel, payload)
}
}
export function stopJobPoll(): void {
export function stopJobPoll(resetMode = false): void {
if (jobTimer) {
clearInterval(jobTimer)
jobTimer = null
}
if (resetMode && mainAppState.mode === 'distributing') {
mainAppState.mode = 'ready'
mainAppState.activeJobId = ''
}
}
export function stopUsbPoll(): void {
@@ -34,12 +42,12 @@ export function stopUsbPoll(): void {
}
export function stopAllPolls(): void {
stopJobPoll()
stopJobPoll(true)
stopUsbPoll()
}
export function startJobPoll(id: string): void {
stopJobPoll()
stopJobPoll(false)
jobId = id
jobTimer = setInterval(() => {
try {
@@ -60,16 +68,15 @@ export function startJobPoll(id: string): void {
})
if (r.queryErrorCode !== 0) {
log.warn('GetJobStateById query failed', r.queryErrorCode)
stopJobPoll()
stopJobPoll(true)
return
}
if (failed || cancelled) {
stopJobPoll()
if (cancelled) mainAppState.mode = 'ready'
stopJobPoll(true)
}
} catch (e) {
log.error('job poll error', e)
stopJobPoll()
stopJobPoll(true)
}
}, POLL_INTERVAL_MS)
}
+1 -1
View File
@@ -100,7 +100,7 @@ export function dllInit(params: InitParams): number {
params.stopOnFailure ?? false,
params.cleanTaskFile ?? true,
params.autoRetryTimes ?? 0,
params.rejectConfig ?? true,
params.rejectConfig ?? false,
params.logLevel ?? LOG_FATAL_FLAG,
params.outBack ?? false
) as number