From ef8f9fba6aaca9c37b8178f52db1883eb24723ba Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Thu, 16 May 2024 07:28:48 +0400 Subject: [PATCH] Add kMaxInt --- lib/src/model/constant.dart | 6 ++++++ lib/src/spinify_impl.dart | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 lib/src/model/constant.dart diff --git a/lib/src/model/constant.dart b/lib/src/model/constant.dart new file mode 100644 index 0000000..9cc83c5 --- /dev/null +++ b/lib/src/model/constant.dart @@ -0,0 +1,6 @@ +/// Whether the current platform is web. +const bool kIsWeb = identical(0, 0.0); + +/// Maximum integer value. +const int kMaxInt = int.fromEnvironment('SPINIFY_MAX_INT', + defaultValue: kIsWeb ? 0x20000000000000 : 0x7FFFFFFFFFFFFFFF); diff --git a/lib/src/spinify_impl.dart b/lib/src/spinify_impl.dart index e53b5ca..e06e776 100644 --- a/lib/src/spinify_impl.dart +++ b/lib/src/spinify_impl.dart @@ -5,6 +5,7 @@ import 'package:meta/meta.dart'; import 'model/channel_push.dart'; import 'model/command.dart'; import 'model/config.dart'; +import 'model/constant.dart'; import 'model/history.dart'; import 'model/metric.dart'; import 'model/presence_stats.dart'; @@ -32,7 +33,10 @@ abstract base class SpinifyBase implements ISpinify { } /// Counter for command messages. - int _getNextCommandId() => _metrics.commandId++; + int _getNextCommandId() { + if (_metrics.commandId == kMaxInt) _metrics.commandId = 1; + return _metrics.commandId++; + } @override bool get isClosed => state.isClosed;