Build Android (FCM) / build-android-fcm (push) Canceled after 0s
Build Android / build-android (push) Canceled after 0s
Build iOS / build-ios (push) Canceled after 0s
Build Linux / build-linux (push) Canceled after 0s
Build macOS / build-macos (push) Canceled after 0s
Build Windows / build-windows (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../utils/ids.dart';
|
|
|
|
abstract class DeviceIdentity {
|
|
static const String _instanceIdKey = 'mt_instance_id';
|
|
static const String _deviceIdKey = 'device_id_local';
|
|
|
|
static final Random _rng = Random.secure();
|
|
static int? _clientSessionId;
|
|
|
|
static int get clientSessionId =>
|
|
_clientSessionId ??= _rng.nextInt(0x7FFFFFFF) + 1;
|
|
|
|
static Future<String> instanceId() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final existing = prefs.getString(_instanceIdKey);
|
|
if (existing != null && existing.isNotEmpty) return existing;
|
|
final generated = uuidV4();
|
|
await prefs.setString(_instanceIdKey, generated);
|
|
return generated;
|
|
}
|
|
|
|
static Future<String> deviceId() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final existing = prefs.getString(_deviceIdKey);
|
|
if (existing != null && existing.isNotEmpty) return existing;
|
|
final generated = randomHex(8);
|
|
await prefs.setString(_deviceIdKey, generated);
|
|
return generated;
|
|
}
|
|
}
|