2023-07-06 17:18:41 +03:30
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
2023-09-06 12:56:30 +03:30
|
|
|
import 'package:hiddify/core/prefs/prefs.dart';
|
2023-08-19 22:27:23 +03:30
|
|
|
import 'package:hiddify/domain/connectivity/connection_failure.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
|
|
|
|
|
part 'connection_status.freezed.dart';
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
sealed class ConnectionStatus with _$ConnectionStatus {
|
|
|
|
|
const ConnectionStatus._();
|
|
|
|
|
|
|
|
|
|
const factory ConnectionStatus.disconnected([
|
2023-08-19 22:27:23 +03:30
|
|
|
ConnectionFailure? connectionFailure,
|
2023-07-06 17:18:41 +03:30
|
|
|
]) = Disconnected;
|
|
|
|
|
const factory ConnectionStatus.connecting() = Connecting;
|
2023-08-19 22:27:23 +03:30
|
|
|
const factory ConnectionStatus.connected() = Connected;
|
2023-07-06 17:18:41 +03:30
|
|
|
const factory ConnectionStatus.disconnecting() = Disconnecting;
|
|
|
|
|
|
2023-08-19 22:27:23 +03:30
|
|
|
bool get isConnected => switch (this) { Connected() => true, _ => false };
|
2023-07-06 17:18:41 +03:30
|
|
|
|
|
|
|
|
bool get isSwitching => switch (this) {
|
|
|
|
|
Connecting() => true,
|
|
|
|
|
Disconnecting() => true,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
String present(TranslationsEn t) => switch (this) {
|
|
|
|
|
Disconnected() => t.home.connection.tapToConnect,
|
|
|
|
|
Connecting() => t.home.connection.connecting,
|
|
|
|
|
Connected() => t.home.connection.connected,
|
|
|
|
|
Disconnecting() => t.home.connection.disconnecting,
|
|
|
|
|
};
|
|
|
|
|
}
|