Use Computer to handle isolates
This commit is contained in:
parent
7bd2ad19de
commit
2505389d00
4 changed files with 18 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:computer/computer.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:photos/core/constants.dart';
|
import 'package:photos/core/constants.dart';
|
||||||
|
@ -25,6 +26,10 @@ void main() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _main() async {
|
void _main() async {
|
||||||
|
Computer().turnOn(
|
||||||
|
workersCount: 4,
|
||||||
|
areLogsEnabled: false,
|
||||||
|
);
|
||||||
await Configuration.instance.init();
|
await Configuration.instance.init();
|
||||||
await PhotoSyncManager.instance.init();
|
await PhotoSyncManager.instance.init();
|
||||||
await MemoriesService.instance.init();
|
await MemoriesService.instance.init();
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:aes_crypt/aes_crypt.dart';
|
import 'package:aes_crypt/aes_crypt.dart';
|
||||||
|
import 'package:computer/computer.dart';
|
||||||
import 'package:encrypt/encrypt.dart';
|
import 'package:encrypt/encrypt.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart' as foundation;
|
|
||||||
|
|
||||||
class CryptoUtil {
|
class CryptoUtil {
|
||||||
static String getBase64EncodedSecureRandomString({int length = 32}) {
|
static String getBase64EncodedSecureRandomString({int length = 32}) {
|
||||||
return SecureRandom(length).base64;
|
return SecureRandom(length).base64;
|
||||||
|
@ -39,7 +38,7 @@ class CryptoUtil {
|
||||||
args["key"] = key;
|
args["key"] = key;
|
||||||
args["source"] = sourcePath;
|
args["source"] = sourcePath;
|
||||||
args["destination"] = destinationPath;
|
args["destination"] = destinationPath;
|
||||||
return foundation.compute(runEncryptFileToFile, args);
|
return Computer().compute(runEncryptFileToFile, param: args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> encryptDataToFile(
|
static Future<String> encryptDataToFile(
|
||||||
|
@ -48,7 +47,7 @@ class CryptoUtil {
|
||||||
args["key"] = key;
|
args["key"] = key;
|
||||||
args["source"] = source;
|
args["source"] = source;
|
||||||
args["destination"] = destinationPath;
|
args["destination"] = destinationPath;
|
||||||
return foundation.compute(runEncryptDataToFile, args);
|
return Computer().compute(runEncryptDataToFile, param: args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> decryptFileToFile(
|
static Future<void> decryptFileToFile(
|
||||||
|
@ -57,14 +56,14 @@ class CryptoUtil {
|
||||||
args["key"] = key;
|
args["key"] = key;
|
||||||
args["source"] = sourcePath;
|
args["source"] = sourcePath;
|
||||||
args["destination"] = destinationPath;
|
args["destination"] = destinationPath;
|
||||||
return foundation.compute(runDecryptFileToFile, args);
|
return Computer().compute(runDecryptFileToFile, param: args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Uint8List> decryptFileToData(String sourcePath, String key) {
|
static Future<Uint8List> decryptFileToData(String sourcePath, String key) {
|
||||||
final args = Map<String, String>();
|
final args = Map<String, String>();
|
||||||
args["key"] = key;
|
args["key"] = key;
|
||||||
args["source"] = sourcePath;
|
args["source"] = sourcePath;
|
||||||
return foundation.compute(runDecryptFileToData, args);
|
return Computer().compute(runDecryptFileToData, param: args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0-nullsafety"
|
version: "1.15.0-nullsafety"
|
||||||
|
computer:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: computer
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.2"
|
||||||
connectivity:
|
connectivity:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -58,6 +58,7 @@ dependencies:
|
||||||
progress_dialog: ^1.2.4
|
progress_dialog: ^1.2.4
|
||||||
animate_do: ^1.7.2
|
animate_do: ^1.7.2
|
||||||
flutter_cache_manager: ^1.4.1
|
flutter_cache_manager: ^1.4.1
|
||||||
|
computer: ^1.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue