feat: improve desktop path selection and USB connection recovery
This commit is contained in:
1 parent
5aa575f182
commit
6490665af8
28 files changed
+846
-51
No files matched your search
@@ -0,0 +1,34 @@
|
||||
/// Poll-based hysteresis and bounded retry delay, independent of processes/UI.
|
||||
class UsbRecoveryPolicy {
|
||||
int missing = 0, attempts = 0, stable = 0;
|
||||
DateTime retryAt = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
bool due(
|
||||
DateTime now, {
|
||||
required bool ready,
|
||||
bool unauthorized = false,
|
||||
bool broken = false,
|
||||
}) {
|
||||
if (unauthorized) {
|
||||
missing = 0;
|
||||
stable = 0;
|
||||
return false;
|
||||
}
|
||||
if (ready && !broken) {
|
||||
missing = 0;
|
||||
if (++stable >= 10) {
|
||||
attempts = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
stable = 0;
|
||||
missing++;
|
||||
return (broken || missing >= 3) && !now.isBefore(retryAt);
|
||||
}
|
||||
|
||||
void attempted(DateTime now) {
|
||||
final seconds = [2, 4, 8, 16, 30][attempts.clamp(0, 4)];
|
||||
attempts++;
|
||||
missing = 0;
|
||||
retryAt = now.add(Duration(seconds: seconds));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user