initial
This commit is contained in:
43
lib/domain/connectivity/connection_status.dart
Normal file
43
lib/domain/connectivity/connection_status.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/locale/locale.dart';
|
||||
import 'package:hiddify/domain/connectivity/connectivity_failure.dart';
|
||||
|
||||
part 'connection_status.freezed.dart';
|
||||
|
||||
@freezed
|
||||
sealed class ConnectionStatus with _$ConnectionStatus {
|
||||
const ConnectionStatus._();
|
||||
|
||||
const factory ConnectionStatus.disconnected([
|
||||
ConnectivityFailure? connectFailure,
|
||||
]) = Disconnected;
|
||||
const factory ConnectionStatus.connecting() = Connecting;
|
||||
const factory ConnectionStatus.connected([
|
||||
ConnectivityFailure? disconnectFailure,
|
||||
]) = Connected;
|
||||
const factory ConnectionStatus.disconnecting() = Disconnecting;
|
||||
|
||||
factory ConnectionStatus.fromBool(bool connected) {
|
||||
return connected
|
||||
? const ConnectionStatus.connected()
|
||||
: const Disconnected();
|
||||
}
|
||||
|
||||
bool get isConnected => switch (this) {
|
||||
Connected() => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
4
lib/domain/connectivity/connectivity.dart
Normal file
4
lib/domain/connectivity/connectivity.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
export 'connection_status.dart';
|
||||
export 'connectivity_failure.dart';
|
||||
export 'network_prefs.dart';
|
||||
export 'traffic.dart';
|
||||
21
lib/domain/connectivity/connectivity_failure.dart
Normal file
21
lib/domain/connectivity/connectivity_failure.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/locale/locale.dart';
|
||||
import 'package:hiddify/domain/failures.dart';
|
||||
|
||||
part 'connectivity_failure.freezed.dart';
|
||||
|
||||
// TODO: rewrite
|
||||
@freezed
|
||||
sealed class ConnectivityFailure with _$ConnectivityFailure, Failure {
|
||||
const ConnectivityFailure._();
|
||||
|
||||
const factory ConnectivityFailure.unexpected([
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
]) = ConnectivityUnexpectedFailure;
|
||||
|
||||
@override
|
||||
String present(TranslationsEn t) {
|
||||
return t.failure.connectivity.unexpected;
|
||||
}
|
||||
}
|
||||
17
lib/domain/connectivity/network_prefs.dart
Normal file
17
lib/domain/connectivity/network_prefs.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'network_prefs.freezed.dart';
|
||||
part 'network_prefs.g.dart';
|
||||
|
||||
@freezed
|
||||
class NetworkPrefs with _$NetworkPrefs {
|
||||
const NetworkPrefs._();
|
||||
|
||||
const factory NetworkPrefs({
|
||||
@Default(true) bool systemProxy,
|
||||
@Default(true) bool bypassPrivateNetworks,
|
||||
}) = _NetworkPrefs;
|
||||
|
||||
factory NetworkPrefs.fromJson(Map<String, dynamic> json) =>
|
||||
_$NetworkPrefsFromJson(json);
|
||||
}
|
||||
13
lib/domain/connectivity/traffic.dart
Normal file
13
lib/domain/connectivity/traffic.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'traffic.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class Traffic with _$Traffic {
|
||||
const Traffic._();
|
||||
|
||||
const factory Traffic({
|
||||
required int upload,
|
||||
required int download,
|
||||
}) = _Traffic;
|
||||
}
|
||||
Reference in New Issue
Block a user