Merge pull request #339 from ente-io/neeraj/mob-82-background-battery-drain
Minor improvements to reduce battery usage
This commit is contained in:
commit
fb7d71380e
3 changed files with 12 additions and 6 deletions
|
@ -113,11 +113,11 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
stopOnTerminate: false,
|
||||
startOnBoot: true,
|
||||
enableHeadless: true,
|
||||
requiresBatteryNotLow: false,
|
||||
requiresBatteryNotLow: true,
|
||||
requiresCharging: false,
|
||||
requiresStorageNotLow: false,
|
||||
requiresDeviceIdle: false,
|
||||
requiredNetworkType: NetworkType.NONE,
|
||||
requiredNetworkType: NetworkType.ANY,
|
||||
), (String taskId) async {
|
||||
await widget.runBackgroundTask(taskId);
|
||||
}, (taskId) {
|
||||
|
|
|
@ -105,7 +105,6 @@ class RemoteSyncService {
|
|||
_existingSync = null;
|
||||
}
|
||||
} catch (e, s) {
|
||||
_logger.severe("Error executing remote sync ", e, s);
|
||||
_existingSync.complete();
|
||||
_existingSync = null;
|
||||
// rethrow whitelisted error so that UI status can be updated correctly.
|
||||
|
@ -114,7 +113,10 @@ class RemoteSyncService {
|
|||
e is WiFiUnavailableError ||
|
||||
e is StorageLimitExceededError ||
|
||||
e is SyncStopRequestedError) {
|
||||
_logger.warning("Error executing remote sync", e);
|
||||
rethrow;
|
||||
} else {
|
||||
_logger.severe("Error executing remote sync ", e, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,6 +270,10 @@ class RemoteSyncService {
|
|||
|
||||
if (toBeUploaded > 0) {
|
||||
Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparing_for_upload));
|
||||
// verify if files upload is allowed based on their subscription plan and
|
||||
// storage limit. To avoid creating new endpoint, we are using
|
||||
// fetchUploadUrls as alternative method.
|
||||
await _uploader.fetchUploadURLs(toBeUploaded);
|
||||
}
|
||||
final List<Future> futures = [];
|
||||
for (final uploadedFileID in updatedFileIDs) {
|
||||
|
|
|
@ -650,20 +650,20 @@ class FileUploader {
|
|||
|
||||
Future<UploadURL> _getUploadURL() async {
|
||||
if (_uploadURLs.isEmpty) {
|
||||
await _fetchUploadURLs();
|
||||
await fetchUploadURLs(_queue.length);
|
||||
}
|
||||
return _uploadURLs.removeFirst();
|
||||
}
|
||||
|
||||
Future<void> _uploadURLFetchInProgress;
|
||||
|
||||
Future<void> _fetchUploadURLs() async {
|
||||
Future<void> fetchUploadURLs(int fileCount) async {
|
||||
_uploadURLFetchInProgress ??= Future<void>(() async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
Configuration.instance.getHttpEndpoint() + "/files/upload-urls",
|
||||
queryParameters: {
|
||||
"count": min(42, 2 * _queue.length), // m4gic number
|
||||
"count": min(42, fileCount * 2), // m4gic number
|
||||
},
|
||||
options: Options(
|
||||
headers: {"X-Auth-Token": Configuration.instance.getToken()},
|
||||
|
|
Loading…
Add table
Reference in a new issue