Skip to content

Commit

Permalink
Merge pull request #975 from ImranR98/dev
Browse files Browse the repository at this point in the history
Less notif spam, no check in aeroplane mode (#974)
  • Loading branch information
ImranR98 authored Oct 8, 2023
2 parents 02f374f + 7453d19 commit 547c2c8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
18 changes: 14 additions & 4 deletions lib/custom_errors.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:android_package_installer/android_package_installer.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -72,6 +74,9 @@ class MultiAppMultiError extends ObtainiumError {
MultiAppMultiError() : super(tr('placeholder'), unexpected: true);

add(String appId, dynamic error, {String? appName}) {
if (error is SocketException) {
error = error.message;
}
rawErrors[appId] = error;
var string = error.toString();
var tempIds = idsByErrorString.remove(string);
Expand All @@ -83,12 +88,17 @@ class MultiAppMultiError extends ObtainiumError {
}
}

String errorString(String appId) =>
'${appIdNames.containsKey(appId) ? '${appIdNames[appId]} ($appId)' : appId}: ${rawErrors[appId].toString()}';
String errorString(String appId, {bool includeIdsWithNames = false}) =>
'${appIdNames.containsKey(appId) ? '${appIdNames[appId]}${includeIdsWithNames ? ' ($appId)' : ''}' : appId}: ${rawErrors[appId].toString()}';

String errorsAppsString(String errString, List<String> appIds,
{bool includeIdsWithNames = false}) =>
'$errString [${list2FriendlyString(appIds.map((id) => appIdNames.containsKey(id) == true ? '${appIdNames[id]}${includeIdsWithNames ? ' ($id)' : ''}' : id).toList())}]';

@override
String toString() =>
idsByErrorString.keys.map((e) => errorString(e)).join('\n\n');
String toString() => idsByErrorString.entries
.map((e) => errorsAppsString(e.key, e.value))
.join('\n\n');
}

showError(dynamic e, BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart';
// ignore: implementation_imports
import 'package:easy_localization/src/localization.dart';

const String currentVersion = '0.14.24';
const String currentVersion = '0.14.25';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

Expand Down
34 changes: 29 additions & 5 deletions lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,30 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
logs.add(
'BG ${installMode ? 'install' : 'update'} task $taskId: Started (${installMode ? toInstall.length : toCheck.length}).');

var netResult = await (Connectivity().checkConnectivity());

if (netResult == ConnectivityResult.none) {
var networkBasedRetryInterval = 15;
var nextRegularCheck = appsProvider.settingsProvider.lastBGCheckTime
.add(Duration(minutes: appsProvider.settingsProvider.updateInterval));
var potentialNetworkRetryCheck =
DateTime.now().add(Duration(minutes: networkBasedRetryInterval));
var shouldRetry = potentialNetworkRetryCheck.isBefore(nextRegularCheck);
logs.add(
'BG update task $taskId: No network. Will ${shouldRetry ? 'retry in $networkBasedRetryInterval minutes' : 'not retry'}.');
AndroidAlarmManager.oneShot(
const Duration(minutes: 15), taskId + 1, bgUpdateCheck,
params: {
'toCheck': toCheck
.map((entry) => {'key': entry.key, 'value': entry.value})
.toList(),
'toInstall': toInstall
.map((entry) => {'key': entry.key, 'value': entry.value})
.toList(),
});
return;
}

if (!installMode) {
// If in update mode, we check for updates.
// We divide the results into 4 groups:
Expand All @@ -1391,7 +1415,7 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
List<App> toNotify = [];
List<MapEntry<String, int>> toRetry = [];
var retryAfterXSeconds = 0;
List<String> toThrow = [];
MultiAppMultiError toThrow = MultiAppMultiError();
var networkRestricted = false;
if (appsProvider.settingsProvider.bgUpdatesOnWiFiOnly) {
var netResult = await (Connectivity().checkConnectivity());
Expand Down Expand Up @@ -1427,7 +1451,7 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
retryAfterXSeconds = minRetryIntervalForThisApp;
}
} else {
toThrow.add(key);
toThrow.add(key, err, appName: errors?.appIdNames[key]);
}
});
} else {
Expand Down Expand Up @@ -1455,10 +1479,10 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
}

// Send the error notifications
if (toThrow.isNotEmpty) {
for (var appId in toThrow) {
if (toThrow.rawErrors.isNotEmpty) {
for (var element in toThrow.idsByErrorString.entries) {
notificationsProvider.notify(ErrorCheckingUpdatesNotification(
errors!.errorString(appId),
errors!.errorsAppsString(element.key, element.value),
id: Random().nextInt(10000)));
}
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: "06a96f1249f38a00435b3b0c9a3246d934d7dbc8183fc7c9e56989860edb99d4"
sha256: ca12e6c9ac022f33fd89128e7007fb5e97ab6e814d4fa05dd8d4f2db1e3c69cb
url: "https://pub.dev"
source: hosted
version: "3.4.4"
version: "3.4.5"
args:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.14.24+216 # When changing this, update the tag in main() accordingly
version: 0.14.25+217 # When changing this, update the tag in main() accordingly

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit 547c2c8

Please sign in to comment.