-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from mirea-ninja/release/v1.3.2
* fix: Add displaying coursework in grades (#298) * Исправлено #297 * Теперь оценки отображаются только для активного профиля ЛКС * fix: Create new interner connection checker (#300) * fix: Change default token storage to helper store (#301)
- Loading branch information
Showing
16 changed files
with
155 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,74 @@ | ||
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart'; | ||
|
||
/// The default parameters for DNS lookups | ||
const Map<String, String> dnsParameters = { | ||
'name': 'ya.ru', | ||
'type': 'A', | ||
'dnssec': '1', | ||
}; | ||
|
||
/// The default headers for DNS lookups | ||
const Map<String, String> dnsHeaders = { | ||
'Accept': 'application/dns-json', | ||
'Cache-Control': 'no-cache', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
final List<AddressCheckOptions> defaultAddresses = [ | ||
AddressCheckOptions( | ||
Uri.parse('https://yandex.cloudflare-dns.com/dns-query').replace( | ||
queryParameters: dnsParameters, | ||
), | ||
headers: dnsHeaders, | ||
), | ||
AddressCheckOptions( | ||
Uri.parse('https://mozilla.cloudflare-dns.com/dns-query').replace( | ||
queryParameters: dnsParameters, | ||
), | ||
headers: dnsHeaders, | ||
), | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
|
||
/// The default hosts to ping to check for internet connection. | ||
final List<String> defaultHosts = [ | ||
'ya.ru', | ||
'google.com', | ||
]; | ||
|
||
/// A class that checks if the device is connected to the internet. | ||
/// | ||
/// It uses the [Connectivity] plugin to check for internet connection. | ||
/// It also uses the [InternetAddress.lookup] method to ping the default hosts. | ||
/// | ||
/// If the device is connected to the internet, the [connectionChange] stream | ||
/// will emit true. | ||
class InternetConnectionChecker { | ||
static final InternetConnectionChecker _singleton = | ||
InternetConnectionChecker._internal(); | ||
InternetConnectionChecker._internal(); | ||
|
||
static InternetConnectionChecker getInstance() => _singleton; | ||
|
||
bool _hasConnection = false; | ||
|
||
/// The stream that emits whenever the connection status changes. | ||
StreamController connectionChangeController = StreamController.broadcast(); | ||
|
||
final Connectivity _connectivity = Connectivity(); | ||
|
||
void initialize() { | ||
_connectivity.onConnectivityChanged.listen(_connectionChange); | ||
checkConnection(); | ||
} | ||
|
||
Stream get connectionChange => connectionChangeController.stream; | ||
|
||
void dispose() { | ||
connectionChangeController.close(); | ||
} | ||
|
||
void _connectionChange(ConnectivityResult result) { | ||
checkConnection(); | ||
} | ||
|
||
Future<bool> checkConnection() async { | ||
bool previousConnection = _hasConnection; | ||
|
||
bool currentConnectionStatus = false; | ||
|
||
for (var host in defaultHosts) { | ||
try { | ||
final result = await InternetAddress.lookup(host); | ||
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) { | ||
currentConnectionStatus = true; | ||
break; | ||
} | ||
} on SocketException catch (_) {} | ||
} | ||
|
||
if (previousConnection != currentConnectionStatus) { | ||
_hasConnection = currentConnectionStatus; | ||
connectionChangeController.add(_hasConnection); | ||
} | ||
|
||
return _hasConnection; | ||
} | ||
|
||
Future<bool> get hasConnection async => await checkConnection(); | ||
|
||
bool get lastKnownConnection => _hasConnection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.