From 2505389d00e45c968181d91d0aa110522e270879 Mon Sep 17 00:00:00 2001 From: Vishnu Mohandas Date: Fri, 14 Aug 2020 04:34:32 +0530 Subject: [PATCH] Use Computer to handle isolates --- lib/main.dart | 5 +++++ lib/utils/crypto_util.dart | 11 +++++------ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1318ec0a0..7b3bd90b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:computer/computer.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:photos/core/constants.dart'; @@ -25,6 +26,10 @@ void main() async { } void _main() async { + Computer().turnOn( + workersCount: 4, + areLogsEnabled: false, + ); await Configuration.instance.init(); await PhotoSyncManager.instance.init(); await MemoriesService.instance.init(); diff --git a/lib/utils/crypto_util.dart b/lib/utils/crypto_util.dart index a0408b8d0..68c9435cb 100644 --- a/lib/utils/crypto_util.dart +++ b/lib/utils/crypto_util.dart @@ -1,11 +1,10 @@ import 'dart:typed_data'; import 'package:aes_crypt/aes_crypt.dart'; +import 'package:computer/computer.dart'; import 'package:encrypt/encrypt.dart'; import 'dart:convert'; -import 'package:flutter/foundation.dart' as foundation; - class CryptoUtil { static String getBase64EncodedSecureRandomString({int length = 32}) { return SecureRandom(length).base64; @@ -39,7 +38,7 @@ class CryptoUtil { args["key"] = key; args["source"] = sourcePath; args["destination"] = destinationPath; - return foundation.compute(runEncryptFileToFile, args); + return Computer().compute(runEncryptFileToFile, param: args); } static Future encryptDataToFile( @@ -48,7 +47,7 @@ class CryptoUtil { args["key"] = key; args["source"] = source; args["destination"] = destinationPath; - return foundation.compute(runEncryptDataToFile, args); + return Computer().compute(runEncryptDataToFile, param: args); } static Future decryptFileToFile( @@ -57,14 +56,14 @@ class CryptoUtil { args["key"] = key; args["source"] = sourcePath; args["destination"] = destinationPath; - return foundation.compute(runDecryptFileToFile, args); + return Computer().compute(runDecryptFileToFile, param: args); } static Future decryptFileToData(String sourcePath, String key) { final args = Map(); args["key"] = key; args["source"] = sourcePath; - return foundation.compute(runDecryptFileToData, args); + return Computer().compute(runDecryptFileToData, param: args); } } diff --git a/pubspec.lock b/pubspec.lock index c7ba0f7b7..13396a979 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -92,6 +92,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0-nullsafety" + computer: + dependency: "direct main" + description: + name: computer + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" connectivity: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0cbe8021c..dee110737 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,7 @@ dependencies: progress_dialog: ^1.2.4 animate_do: ^1.7.2 flutter_cache_manager: ^1.4.1 + computer: ^1.0.2 dev_dependencies: flutter_test: