fix: 向导第 2 步自动轮询——手动装驱动/插打印机后页面自动刷新
用户实测反馈:手动安装驱动输密码后向导页面无变化。排查确认驱动实际已装上 (/Library/Printers/HiTi 存在),问题是向导只在按钮事件时刷新——用户在 App 外装完驱动没有任何事件触发重建,页面停在"尚未安装"旧文案。 修复:向导停留在第 2 步期间每 3 秒静默轮询(驱动目录判断 + 打印机状态), 装完驱动/插上打印机/系统识别出队列后页面自动切换分支;驱动未装分支同时 补"重新检测"按钮;一键安装执行中暂停轮询避免打断。
This commit is contained in:
1 parent
d475cac6ab
commit
78d6b82305
1 file changed
+26
-4
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -53,17 +54,32 @@ class _SetupWizardState extends State<SetupWizard> {
|
||||
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<void> _checkPrinter() async {
|
||||
setState(() => _printerChecking = true);
|
||||
Timer? _pollTimer;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pollTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _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<SetupWizard> {
|
||||
),
|
||||
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('重新检测'),
|
||||
),
|
||||
]
|
||||
|
||||
// 驱动已装但打印机未就绪 → 引导连接/添加队列
|
||||
|
||||
Reference in new issue
Block a user