fix(print): auto-start capture and surface listener state
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
This commit is contained in:
parent
af231cebec
commit
16d3fe0b58
44
src/main.ts
44
src/main.ts
@ -90,6 +90,7 @@ let bundleType: BundleType | null = null
|
||||
let availableUpdate: Update | null = null
|
||||
let availableManualUpdate: ManualUpdate | null = null
|
||||
let updateBusy = false
|
||||
let captureError: string | null = null
|
||||
let systemPrinters: SystemPrinter[] = []
|
||||
let virtualPrinterStatus: VirtualPrinterStatus | null = null
|
||||
|
||||
@ -286,12 +287,22 @@ async function refreshPrinters() {
|
||||
|
||||
function render() {
|
||||
const pill = el<HTMLDivElement>('status-pill')
|
||||
pill.classList.toggle('live', status?.running ?? false)
|
||||
pill.querySelector('span:last-child')!.textContent = status?.running ? `Capturing · ${status.mode}` : 'Stopped'
|
||||
pill.classList.toggle('live', (status?.running ?? false) && !captureError)
|
||||
pill.querySelector('span:last-child')!.textContent = captureError
|
||||
? 'Capture error'
|
||||
: status?.running
|
||||
? `Capturing · ${status.mode}`
|
||||
: 'Stopped'
|
||||
el('job-count').textContent = String(status?.jobs ?? jobs.length)
|
||||
el('code-count').textContent = String(jobs.reduce((sum, job) => sum + job.barcodes.length, 0))
|
||||
el('pending-count').textContent = String(status?.pending ?? 0)
|
||||
el('job-hint').textContent = jobs.length ? `${jobs.length} retained locally` : 'Waiting for capture'
|
||||
el('job-hint').textContent = captureError
|
||||
? `Capture unavailable: ${captureError}`
|
||||
: jobs.length
|
||||
? `${jobs.length} retained locally`
|
||||
: status?.running
|
||||
? 'Ready for print jobs'
|
||||
: 'Capture stopped'
|
||||
|
||||
el('jobs').innerHTML = jobs.length ? jobs.map((job) => `
|
||||
<article class="job">
|
||||
@ -313,6 +324,22 @@ async function refreshStatus() {
|
||||
render()
|
||||
}
|
||||
|
||||
async function ensureCaptureStarted() {
|
||||
try {
|
||||
await invoke('start_capture')
|
||||
captureError = null
|
||||
} catch (error) {
|
||||
captureError = String(error)
|
||||
}
|
||||
await refreshStatus()
|
||||
return !captureError
|
||||
}
|
||||
|
||||
async function restartCapture() {
|
||||
await invoke('stop_capture').catch(() => undefined)
|
||||
return ensureCaptureStarted()
|
||||
}
|
||||
|
||||
el('forwardPrinter').addEventListener('change', () => {
|
||||
const selected = systemPrinters.find((printer) => printer.name === el<HTMLSelectElement>('forwardPrinter').value)
|
||||
if (selected?.address) {
|
||||
@ -339,6 +366,7 @@ el('install-printer').addEventListener('click', async () => {
|
||||
try {
|
||||
virtualPrinterStatus = await invoke<VirtualPrinterStatus>('install_virtual_printer', { targetPrinter })
|
||||
config = await invoke<AppConfig>('save_config', { config: readForm() })
|
||||
await restartCapture()
|
||||
await refreshPrinters()
|
||||
} catch (error) {
|
||||
state.textContent = `Printer setup failed: ${String(error)}`
|
||||
@ -365,16 +393,17 @@ el('remove-printer').addEventListener('click', async () => {
|
||||
el('save').addEventListener('click', async () => {
|
||||
config = await invoke<AppConfig>('save_config', { config: readForm() })
|
||||
writeForm(config)
|
||||
await refreshStatus()
|
||||
if (status?.running) await restartCapture()
|
||||
else await refreshStatus()
|
||||
})
|
||||
|
||||
el('start').addEventListener('click', async () => {
|
||||
config = await invoke<AppConfig>('save_config', { config: readForm() })
|
||||
await invoke('start_capture')
|
||||
await refreshStatus()
|
||||
await restartCapture()
|
||||
})
|
||||
|
||||
el('stop').addEventListener('click', async () => {
|
||||
captureError = null
|
||||
await invoke('stop_capture')
|
||||
await refreshStatus()
|
||||
})
|
||||
@ -565,7 +594,8 @@ await listen<Job>('capture-job', (event) => {
|
||||
|
||||
config = await invoke<AppConfig>('get_config')
|
||||
writeForm(config)
|
||||
await Promise.all([refreshStatus(), refreshPrinters()])
|
||||
await refreshPrinters()
|
||||
await ensureCaptureStarted()
|
||||
|
||||
currentVersion = await getVersion()
|
||||
bundleType = await getBundleType().catch(() => null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user