diff --git a/lib/ui/setup_wizard.dart b/lib/ui/setup_wizard.dart index b2cac5b..42f19e2 100644 --- a/lib/ui/setup_wizard.dart +++ b/lib/ui/setup_wizard.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -53,17 +54,32 @@ class _SetupWizardState extends State { void initState() { super.initState(); _checkPrinter(); + // 第 2 步期间自动轮询:用户手动装驱动 / 插上打印机后页面自动刷新 + // (驱动目录判断零成本;getStatus 走 lpoptions,3s 一次可接受) + _pollTimer = Timer.periodic(const Duration(seconds: 3), (_) { + if (_step == 1 && mounted && !_driverInstalling) { + _checkPrinter(silent: true); + } + }); } - Future _checkPrinter() async { - setState(() => _printerChecking = true); + Timer? _pollTimer; + + @override + void dispose() { + _pollTimer?.cancel(); + super.dispose(); + } + + Future _checkPrinter({bool silent = false}) async { + if (!silent) setState(() => _printerChecking = true); try { final status = await _agent.backend.getStatus(); if (mounted) setState(() => _printerStatus = status); } catch (_) { if (mounted) setState(() => _printerStatus = null); } finally { - if (mounted) setState(() => _printerChecking = false); + if (mounted && !silent) setState(() => _printerChecking = false); } } @@ -262,9 +278,15 @@ class _SetupWizardState extends State { ), const SizedBox(height: 8), Text( - '安装完成后:USB 连接打印机并开机,系统识别出现打印队列即完成。', + '安装完成后页面会自动刷新(也可手动重新检测);随后 USB 连接打印机并开机,系统识别出现打印队列即完成。', style: Theme.of(context).textTheme.bodySmall, ), + const SizedBox(height: 4), + TextButton.icon( + onPressed: _printerChecking ? null : () => _checkPrinter(), + icon: const Icon(Icons.refresh, size: 16), + label: const Text('重新检测'), + ), ] // 驱动已装但打印机未就绪 → 引导连接/添加队列