Fix crash on state change in file provider domain sync status

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-01-10 15:42:33 +08:00
parent 36001aeff7
commit f8ebbe8c71
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 30 additions and 12 deletions

View file

@ -30,7 +30,7 @@ Q_LOGGING_CATEGORY(lcMacFileProviderDomainSyncStatus, "nextcloud.gui.macfileprov
class FileProviderDomainSyncStatus::MacImplementation
{
public:
explicit MacImplementation(const QString &domainIdentifier, FileProviderDomainSyncStatus *parent = nullptr)
explicit MacImplementation(const QString &domainIdentifier, FileProviderDomainSyncStatus *parent)
: q(parent)
{
_domain = FileProviderUtils::domainForIdentifier(domainIdentifier);
@ -47,23 +47,41 @@ public:
_uploadProgressObserver = [[ProgressObserver alloc] initWithProgress:uploadProgress];
_downloadProgressObserver.progressKVOChangeHandler = ^(NSProgress *const progress){
qCDebug(lcMacFileProviderDomainSyncStatus) << "Download progress changed" << progress.localizedDescription;
q->setDownloading(!progress.paused && !progress.cancelled && !progress.finished);
q->setDownloadFractionCompleted(progress.fractionCompleted);
q->setDownloadFileTotalCount(progress.fileTotalCount.intValue);
q->setDownloadFileCompletedCount(progress.fileCompletedCount.intValue);
updateDownload(progress);
};
_uploadProgressObserver.progressKVOChangeHandler = ^(NSProgress *const progress){
qCDebug(lcMacFileProviderDomainSyncStatus) << "Upload progress changed" << progress.localizedDescription;
q->setUploading(!progress.paused && !progress.cancelled && !progress.finished);
q->setUploadFractionCompleted(progress.fractionCompleted);
q->setUploadFileTotalCount(progress.fileTotalCount.intValue);
q->setUploadFileCompletedCount(progress.fileCompletedCount.intValue);
updateUpload(progress);
};
}
~MacImplementation() = default;
void updateDownload(NSProgress *const progress) const
{
qCInfo(lcMacFileProviderDomainSyncStatus) << "Download progress changed" << progress.localizedDescription;
if (progress == nil || q == nullptr) {
return;
}
q->setDownloading(!progress.paused && !progress.cancelled && !progress.finished);
q->setDownloadFractionCompleted(progress.fractionCompleted);
q->setDownloadFileTotalCount(progress.fileTotalCount.intValue);
q->setDownloadFileCompletedCount(progress.fileCompletedCount.intValue);
}
void updateUpload(NSProgress *const progress) const
{
qCInfo(lcMacFileProviderDomainSyncStatus) << "Upload progress changed" << progress.localizedDescription;
if (progress == nil || q == nullptr) {
return;
}
q->setUploading(!progress.paused && !progress.cancelled && !progress.finished);
q->setUploadFractionCompleted(progress.fractionCompleted);
q->setUploadFileTotalCount(progress.fileTotalCount.intValue);
q->setUploadFileCompletedCount(progress.fileCompletedCount.intValue);
}
private:
NSFileProviderDomain *_domain = nil;
NSFileProviderManager *_manager = nil;

View file

@ -21,7 +21,7 @@ typedef void(^ProgressKVOChangeHandler)(NSProgress *const progress);
@interface ProgressObserver : NSObject
@property (readonly) NSProgress *progress;
@property (readwrite, atomic) ProgressKVOChangeHandler progressKVOChangeHandler;
@property (readwrite, copy) ProgressKVOChangeHandler progressKVOChangeHandler;
- (instancetype)initWithProgress:(NSProgress *)progress;