forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirmware_update_check_session.dart
More file actions
36 lines (29 loc) · 967 Bytes
/
Copy pathfirmware_update_check_session.dart
File metadata and controls
36 lines (29 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'package:flutter/foundation.dart';
@immutable
class FirmwareUpdateCheckSession {
const FirmwareUpdateCheckSession._({required this.deviceId, required this.generation});
final String deviceId;
final int generation;
}
/// Identifies the exact device connection that owns an asynchronous firmware
/// check. Reconnecting the same physical device still creates a new session.
class FirmwareUpdateCheckSessionGuard {
int _generation = 0;
String? _deviceId;
void start(String deviceId) {
_generation++;
_deviceId = deviceId;
}
void invalidate() {
_generation++;
_deviceId = null;
}
FirmwareUpdateCheckSession? capture() {
final deviceId = _deviceId;
if (deviceId == null) return null;
return FirmwareUpdateCheckSession._(deviceId: deviceId, generation: _generation);
}
bool isCurrent(FirmwareUpdateCheckSession session) {
return session.generation == _generation && session.deviceId == _deviceId;
}
}