25 lines
633 B
Dart
25 lines
633 B
Dart
import 'package:uuid/uuid.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:pshared/config/web.dart';
|
|
import 'package:pshared/service/secure_storage.dart';
|
|
|
|
|
|
class DeviceIdManager {
|
|
static final _logger = Logger('service.device_id');
|
|
|
|
static final String _key = Constants.deviceIdStorageKey;
|
|
static Future<String> getDeviceId() async {
|
|
String? deviceId = await SecureStorageService.get(_key);
|
|
|
|
if (deviceId == null) {
|
|
_logger.fine('Device id is not set, generating new');
|
|
deviceId = (const Uuid()).v4();
|
|
await SecureStorageService.set(_key, deviceId);
|
|
}
|
|
|
|
return deviceId;
|
|
}
|
|
}
|