mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 09:31:13 +00:00
refactor: Only use ws updates if the API version supports it
This commit is contained in:
parent
7c28f92581
commit
65322257ec
|
@ -275,11 +275,14 @@ class ApiConnectionRepository {
|
||||||
connectionStatus = ConnectionStatus.connected;
|
connectionStatus = ConnectionStatus.connected;
|
||||||
_connectionStatusStream.add(connectionStatus);
|
_connectionStatusStream.add(connectionStatus);
|
||||||
|
|
||||||
|
if (VersionConstraint.parse(wsJobsUpdatesSupportedVersion)
|
||||||
|
.allows(Version.parse(apiVersion))) {
|
||||||
_serverJobsStreamSubscription =
|
_serverJobsStreamSubscription =
|
||||||
api.getServerJobsStream().listen((final List<ServerJob> jobs) {
|
api.getServerJobsStream().listen((final List<ServerJob> jobs) {
|
||||||
_apiData.serverJobs.data = jobs;
|
_apiData.serverJobs.data = jobs;
|
||||||
_dataStream.add(_apiData);
|
_dataStream.add(_apiData);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Use timer to periodically check for new jobs
|
// Use timer to periodically check for new jobs
|
||||||
_timer = Timer.periodic(
|
_timer = Timer.periodic(
|
||||||
|
@ -295,9 +298,14 @@ class ApiConnectionRepository {
|
||||||
await _serverJobsStreamSubscription?.cancel();
|
await _serverJobsStreamSubscription?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const String wsJobsUpdatesSupportedVersion = '>=3.3.0';
|
||||||
|
|
||||||
Future<void> _refetchEverything(final Version version) async {
|
Future<void> _refetchEverything(final Version version) async {
|
||||||
|
if (_serverJobsStreamSubscription == null ||
|
||||||
|
_apiData.serverJobs.data == null) {
|
||||||
await _apiData.serverJobs
|
await _apiData.serverJobs
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
}
|
||||||
await _apiData.backups
|
await _apiData.backups
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
await _apiData.backupConfig
|
await _apiData.backupConfig
|
||||||
|
@ -347,8 +355,7 @@ class ApiData {
|
||||||
),
|
),
|
||||||
serverJobs = ApiDataElement<List<ServerJob>>(
|
serverJobs = ApiDataElement<List<ServerJob>>(
|
||||||
fetchData: () async => api.getServerJobs(),
|
fetchData: () async => api.getServerJobs(),
|
||||||
// TODO: Figure this out later, as ws keeps this updated
|
ttl: 10,
|
||||||
ttl: 10000,
|
|
||||||
),
|
),
|
||||||
backupConfig = ApiDataElement<BackupConfiguration>(
|
backupConfig = ApiDataElement<BackupConfiguration>(
|
||||||
fetchData: () async => api.getBackupsConfiguration(),
|
fetchData: () async => api.getBackupsConfiguration(),
|
||||||
|
|
Loading…
Reference in a new issue