Computer: Switch to forked version + enable debuglogs (#1042)
This commit is contained in:
commit
91e835cdfd
6 changed files with 67 additions and 41 deletions
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
|
||||
import "package:adaptive_theme/adaptive_theme.dart";
|
||||
import 'package:background_fetch/background_fetch.dart';
|
||||
import "package:computer/computer.dart";
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -153,6 +154,8 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
|
|||
} else {
|
||||
AppLifecycleService.instance.onAppInForeground('init via: $via');
|
||||
}
|
||||
// Start workers asynchronously. No need to wait for them to start
|
||||
Computer.shared().turnOn(workersCount: 4, verbose: kDebugMode);
|
||||
CryptoUtil.init();
|
||||
await NotificationService.instance.init();
|
||||
await NetworkClient.instance.init();
|
||||
|
|
|
@ -16,7 +16,6 @@ const assetFetchPageSize = 2000;
|
|||
Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
|
||||
int fromTime,
|
||||
int toTime,
|
||||
Computer computer,
|
||||
) async {
|
||||
final pathEntities = await _getGalleryList(
|
||||
updateFromTime: fromTime,
|
||||
|
@ -31,17 +30,24 @@ Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
|
|||
final List<File> uniqueFiles = [];
|
||||
for (AssetPathEntity pathEntity in pathEntities) {
|
||||
final List<AssetEntity> assetsInPath = await _getAllAssetLists(pathEntity);
|
||||
final Tuple2<Set<String>, List<File>> result = await computer.compute(
|
||||
_getLocalIDsAndFilesFromAssets,
|
||||
param: <String, dynamic>{
|
||||
"pathEntity": pathEntity,
|
||||
"fromTime": fromTime,
|
||||
"alreadySeenLocalIDs": alreadySeenLocalIDs,
|
||||
"assetList": assetsInPath,
|
||||
},
|
||||
);
|
||||
alreadySeenLocalIDs.addAll(result.item1);
|
||||
uniqueFiles.addAll(result.item2);
|
||||
late Tuple2<Set<String>, List<File>> result;
|
||||
if (assetsInPath.isEmpty) {
|
||||
result = const Tuple2({}, []);
|
||||
} else {
|
||||
result = await Computer.shared().compute(
|
||||
_getLocalIDsAndFilesFromAssets,
|
||||
param: <String, dynamic>{
|
||||
"pathEntity": pathEntity,
|
||||
"fromTime": fromTime,
|
||||
"alreadySeenLocalIDs": alreadySeenLocalIDs,
|
||||
"assetList": assetsInPath,
|
||||
},
|
||||
taskName:
|
||||
"getLocalPathAssetsAndFiles-${pathEntity.name}-count-${assetsInPath.length}",
|
||||
);
|
||||
alreadySeenLocalIDs.addAll(result.item1);
|
||||
uniqueFiles.addAll(result.item2);
|
||||
}
|
||||
localPathAssets.add(
|
||||
LocalPathAsset(
|
||||
localIDs: result.item1,
|
||||
|
@ -118,15 +124,17 @@ Future<LocalDiffResult> getDiffWithLocal(
|
|||
Set<String> existingIDs, // localIDs of files already imported in app
|
||||
Map<String, Set<String>> pathToLocalIDs,
|
||||
Set<String> invalidIDs,
|
||||
Computer computer,
|
||||
) async {
|
||||
final Map<String, dynamic> args = <String, dynamic>{};
|
||||
args['assets'] = assets;
|
||||
args['existingIDs'] = existingIDs;
|
||||
args['invalidIDs'] = invalidIDs;
|
||||
args['pathToLocalIDs'] = pathToLocalIDs;
|
||||
final LocalDiffResult diffResult =
|
||||
await computer.compute(_getLocalAssetsDiff, param: args);
|
||||
final LocalDiffResult diffResult = await Computer.shared().compute(
|
||||
_getLocalAssetsDiff,
|
||||
param: args,
|
||||
taskName: "getLocalAssetsDiff",
|
||||
);
|
||||
if (diffResult.localPathAssets != null) {
|
||||
diffResult.uniqueLocalFiles =
|
||||
await _convertLocalAssetsToUniqueFiles(diffResult.localPathAssets!);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:computer/computer.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
@ -24,7 +23,6 @@ import 'package:tuple/tuple.dart';
|
|||
class LocalSyncService {
|
||||
final _logger = Logger("LocalSyncService");
|
||||
final _db = FilesDB.instance;
|
||||
final Computer _computer = Computer();
|
||||
late SharedPreferences _prefs;
|
||||
Completer<void>? _existingSync;
|
||||
|
||||
|
@ -47,7 +45,6 @@ class LocalSyncService {
|
|||
if (!AppLifecycleService.instance.isForeground) {
|
||||
await PhotoManager.setIgnorePermissionCheck(true);
|
||||
}
|
||||
await _computer.turnOn(workersCount: 1);
|
||||
if (hasGrantedPermissions()) {
|
||||
_registerChangeCallback();
|
||||
}
|
||||
|
@ -164,7 +161,6 @@ class LocalSyncService {
|
|||
existingLocalFileIDs,
|
||||
pathToLocalIDs,
|
||||
invalidIDs,
|
||||
_computer,
|
||||
);
|
||||
bool hasAnyMappingChanged = false;
|
||||
if (localDiffResult.newPathToLocalIDs?.isNotEmpty ?? false) {
|
||||
|
@ -268,17 +264,18 @@ class LocalSyncService {
|
|||
required int toTime,
|
||||
}) async {
|
||||
final Tuple2<List<LocalPathAsset>, List<File>> result =
|
||||
await getLocalPathAssetsAndFiles(fromTime, toTime, _computer);
|
||||
|
||||
// Update the mapping for device path_id to local file id. Also, keep track
|
||||
// of newly discovered device paths
|
||||
await FilesDB.instance.insertLocalAssets(
|
||||
result.item1,
|
||||
shouldAutoBackup: Configuration.instance.hasSelectedAllFoldersForBackup(),
|
||||
);
|
||||
await getLocalPathAssetsAndFiles(fromTime, toTime);
|
||||
|
||||
final List<File> files = result.item2;
|
||||
if (files.isNotEmpty) {
|
||||
// Update the mapping for device path_id to local file id. Also, keep track
|
||||
// of newly discovered device paths
|
||||
await FilesDB.instance.insertLocalAssets(
|
||||
result.item1,
|
||||
shouldAutoBackup:
|
||||
Configuration.instance.hasSelectedAllFoldersForBackup(),
|
||||
);
|
||||
|
||||
_logger.info(
|
||||
"Loaded ${files.length} photos from " +
|
||||
DateTime.fromMicrosecondsSinceEpoch(fromTime).toString() +
|
||||
|
|
|
@ -166,10 +166,10 @@ Uint8List chachaDecryptData(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
class CryptoUtil {
|
||||
static final Computer _computer = Computer();
|
||||
// Note: workers are turned on during app startup.
|
||||
static final Computer _computer = Computer.shared();
|
||||
|
||||
static init() {
|
||||
_computer.turnOn(workersCount: 4);
|
||||
Sodium.init();
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,11 @@ class CryptoUtil {
|
|||
args["cipher"] = cipher;
|
||||
args["nonce"] = nonce;
|
||||
args["key"] = key;
|
||||
return _computer.compute(cryptoSecretboxOpenEasy, param: args);
|
||||
return _computer.compute(
|
||||
cryptoSecretboxOpenEasy,
|
||||
param: args,
|
||||
taskName: "decrypt",
|
||||
);
|
||||
}
|
||||
|
||||
// Decrypts the given cipher, with the given key and nonce using XSalsa20
|
||||
|
@ -262,7 +266,11 @@ class CryptoUtil {
|
|||
final args = <String, dynamic>{};
|
||||
args["source"] = source;
|
||||
args["key"] = key;
|
||||
return _computer.compute(chachaEncryptData, param: args);
|
||||
return _computer.compute(
|
||||
chachaEncryptData,
|
||||
param: args,
|
||||
taskName: "encryptChaCha",
|
||||
);
|
||||
}
|
||||
|
||||
// Decrypts the given source, with the given key and header using XChaCha20
|
||||
|
@ -277,7 +285,11 @@ class CryptoUtil {
|
|||
args["source"] = source;
|
||||
args["key"] = key;
|
||||
args["header"] = header;
|
||||
return _computer.compute(chachaDecryptData, param: args);
|
||||
return _computer.compute(
|
||||
chachaDecryptData,
|
||||
param: args,
|
||||
taskName: "decryptChaCha",
|
||||
);
|
||||
}
|
||||
|
||||
// Encrypts the file at sourceFilePath, with the key (if provided) and a
|
||||
|
@ -293,7 +305,8 @@ class CryptoUtil {
|
|||
args["sourceFilePath"] = sourceFilePath;
|
||||
args["destinationFilePath"] = destinationFilePath;
|
||||
args["key"] = key;
|
||||
return _computer.compute(chachaEncryptFile, param: args);
|
||||
return _computer.compute(chachaEncryptFile,
|
||||
param: args, taskName: "encryptFile");
|
||||
}
|
||||
|
||||
// Decrypts the file at sourceFilePath, with the given key and header using
|
||||
|
@ -309,7 +322,8 @@ class CryptoUtil {
|
|||
args["destinationFilePath"] = destinationFilePath;
|
||||
args["header"] = header;
|
||||
args["key"] = key;
|
||||
return _computer.compute(chachaDecryptFile, param: args);
|
||||
return _computer.compute(chachaDecryptFile,
|
||||
param: args, taskName: "decryptFile");
|
||||
}
|
||||
|
||||
// Generates and returns a 256-bit key.
|
||||
|
@ -391,7 +405,7 @@ class CryptoUtil {
|
|||
return DerivedKeyResult(key, memLimit, opsLimit);
|
||||
}
|
||||
|
||||
// Derives a key for a given password, salt, memLimit and opsLimit using
|
||||
// Derives a key for a given password, salt, memLimit and opsLimit using
|
||||
// Argon2id, v1.3.
|
||||
static Future<Uint8List> deriveKey(
|
||||
Uint8List password,
|
||||
|
@ -407,6 +421,7 @@ class CryptoUtil {
|
|||
"memLimit": memLimit,
|
||||
"opsLimit": opsLimit,
|
||||
},
|
||||
taskName: "deriveKey",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -417,6 +432,7 @@ class CryptoUtil {
|
|||
param: {
|
||||
"sourceFilePath": source.path,
|
||||
},
|
||||
taskName: "fileHash",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
11
pubspec.lock
11
pubspec.lock
|
@ -275,11 +275,12 @@ packages:
|
|||
computer:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: computer
|
||||
sha256: "3df9f1ef497aaf69e066b00f4441726eb28037dc33e97b5d56393967f92c5fe8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "82e365fed8a1a76f6eea0220de98389eed7b0445"
|
||||
url: "https://github.com/ente-io/computer.git"
|
||||
source: git
|
||||
version: "3.2.1"
|
||||
confetti:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -28,7 +28,8 @@ dependencies:
|
|||
chewie:
|
||||
path: thirdparty/chewie
|
||||
collection: # dart
|
||||
computer: ^2.0.0
|
||||
computer:
|
||||
git: "https://github.com/ente-io/computer.git"
|
||||
confetti: ^0.6.0
|
||||
connectivity_plus: ^3.0.3
|
||||
crypto: ^3.0.2
|
||||
|
|
Loading…
Add table
Reference in a new issue