Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5728,7 +5728,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -5794,7 +5794,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down
53 changes: 40 additions & 13 deletions iOSClient/Networking/NCNetworkingProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
private let networking = NCNetworking.shared

private var currentTask: Task<Void, Never>?

@MainActor
private var currentUploadTask: Task<(account: String, file: NKFile?, error: NKError), Never>?

@MainActor
private var currentUploadRequest: UploadRequest?

private var enableControllingScreenAwake = true
private var currentAccount = ""
private var inWaitingCount: Int = 0
Expand Down Expand Up @@ -54,6 +61,8 @@

Task {
await self.stopTimer()
await self.cancelCurrentTaskOnBackground()
await self.cancelCurrentUpload()
}
}

Expand Down Expand Up @@ -146,6 +155,19 @@
timer = nil
}

private func cancelCurrentTaskOnBackground() {
currentTask?.cancel()
currentTask = nil
}

@MainActor
private func cancelCurrentUpload() async {
self.currentUploadTask?.cancel()
self.currentUploadRequest?.cancel()
self.currentUploadTask = nil
self.currentUploadRequest = nil
}

private func handleTimerTick() async {
if currentTask != nil {
print("[NKLOG] current task is running")
Expand All @@ -157,6 +179,10 @@
currentTask = nil
}

if Task.isCancelled {
return
}

guard networking.isOnline,
!currentAccount.isEmpty,
networking.noServerErrorAccount(currentAccount)
Expand Down Expand Up @@ -207,9 +233,13 @@
ScreenAwakeManager.shared.mode = resultsScreenAwake.isEmpty && !hasSyncTask ? .off : NCPreferences().screenAwakeMode
}

if Task.isCancelled {
return
}

await runMetadataPipelineAsync(metadatas: metadatas)

// TODO: Check temperature

Check warning on line 242 in iOSClient/Networking/NCNetworkingProcess.swift

View workflow job for this annotation

GitHub Actions / Lint

Todo Violation: TODOs should be resolved (Check temperature) (todo)

if lastUsedInterval != minInterval {
await startTimer(interval: minInterval)
Expand Down Expand Up @@ -358,29 +388,28 @@
// UPLOAD E2EE
//
if metadata.isDirectoryE2EE {
var currentUploadTask: Task<(account: String, file: NKFile?, error: NKError), Never>?
var request: UploadRequest?
let controller = await getController(account: metadata.account, sceneIdentifier: metadata.sceneIdentifier)
let scene = await SceneManager.shared.getWindow(sceneIdentifier: metadata.sceneIdentifier)?.windowScene

let token = await showUploadBanner(scene: scene,
blocksTouches: true,
onButtonTap: {
if let currentUploadTask {
currentUploadTask.cancel()
}
if let request {
request.cancel()
Task {
await self.cancelCurrentUpload()
}
})

await NCNetworkingE2EEUpload().upload(metadata: metadata,
controller: controller,
stageBanner: .button,
tokenBanner: token) { uploadRequest in
request = uploadRequest
Task {@MainActor in
self.currentUploadRequest = uploadRequest
}
} currentUploadTask: { task in
currentUploadTask = task
Task {@MainActor in
self.currentUploadTask = task
}
}

// wait dismiss banner before open another (loop)
Expand All @@ -405,7 +434,6 @@

@MainActor
func uploadChunk(metadata: tableMetadata) async {
var currentUploadTask: Task<(account: String, file: NKFile?, error: NKError), Never>?
var tokenBanner: Int?
let scene = SceneManager.shared.getWindow(sceneIdentifier: metadata.sceneIdentifier)?.windowScene

Expand All @@ -416,9 +444,8 @@
stage: .button,
allowMinimizeOnTap: true,
onButtonTap: {
if let currentUploadTask {
currentUploadTask.cancel()
} else {
Task {
await self.cancelCurrentUpload()
LucidBanner.shared.dismiss()
}
})
Expand Down
Loading