Skip to content

Commit

Permalink
Add kMaxInt
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed May 16, 2024
1 parent 1743711 commit ef8f9fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/src/model/constant.dart
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 5 additions & 1 deletion lib/src/spinify_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ef8f9fb

Please sign in to comment.