Skip to content

Commit

Permalink
Fix linter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Feb 4, 2024
1 parent 1b884cb commit f9ba44d
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions Shared/Services/Sync/LibraryItemSyncOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,31 @@ extension LibraryItemSyncOperation {
session: session
)

// TODO: remove these subscribers
bindUploadObservers()

cellularDataObserver?.invalidate()
cellularDataObserver = UserDefaults.standard.observe(
\.userSettingsAllowCellularData,
options: [.new]
) { [weak self] _, change in
guard let newValue = change.newValue else { return }

let previousSession: URLSession = newValue
? BPURLSession.shared.backgroundSession
: BPURLSession.shared.backgroundCellularSession

self?.rescheduleUploadFile(
fileURL: fileURL,
remoteURL: remoteURL,
relativePath: relativePath,
previousSession: previousSession
)
}

uploadTask.resume()
}

func bindUploadObservers() {
progressSubscriber?.cancel()
progressSubscriber = BPURLSession.shared.progressPublisher.sink(receiveValue: { (path, progress) in
NotificationCenter.default.post(
Expand All @@ -241,29 +265,6 @@ extension LibraryItemSyncOperation {
self?.handleUploadFinished(task)
}
})

cellularDataObserver?.invalidate()
cellularDataObserver = UserDefaults.standard.observe(
\.userSettingsAllowCellularData,
options: [.new]
) { [weak self] _, change in
guard
let newValue = change.newValue
else { return }

let previousSession: URLSession = newValue
? BPURLSession.shared.backgroundSession
: BPURLSession.shared.backgroundCellularSession

self?.rescheduleUploadFile(
fileURL: fileURL,
remoteURL: remoteURL,
relativePath: relativePath,
previousSession: previousSession
)
}

uploadTask.resume()
}

func rescheduleUploadFile(
Expand Down

0 comments on commit f9ba44d

Please sign in to comment.