mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
some fixes
This commit is contained in:
@@ -300,6 +300,8 @@ private struct DirectoryView: View {
|
||||
.onAppear {
|
||||
if manager.currentDirectory != path {
|
||||
manager.changeDirectory(to: path)
|
||||
} else {
|
||||
manager.refreshDirectory()
|
||||
}
|
||||
}
|
||||
.fileImporter(
|
||||
|
||||
@@ -115,6 +115,7 @@ final class TimeSyncManager: NSObject, ObservableObject {
|
||||
private var pendingListPath: String?
|
||||
private var pendingListOperationID: UUID?
|
||||
private var simpleOperationID: UUID?
|
||||
private var pendingDirectoryRequest: (path: String, operationID: UUID)?
|
||||
|
||||
private struct UploadState {
|
||||
let id: UUID
|
||||
@@ -402,6 +403,7 @@ final class TimeSyncManager: NSObject, ObservableObject {
|
||||
pendingListPath = nil
|
||||
pendingListOperationID = nil
|
||||
simpleOperationID = nil
|
||||
pendingDirectoryRequest = nil
|
||||
isFileBusy = false
|
||||
currentDirectory = "/"
|
||||
directoryEntries = []
|
||||
@@ -675,19 +677,51 @@ final class TimeSyncManager: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
private func requestDirectory(path: String) {
|
||||
let normalizedPath = normalizedPath(path)
|
||||
|
||||
guard let commandCharacteristic = fileCommandCharacteristic else {
|
||||
fileErrorMessage = FileServiceError.characteristicUnavailable.localizedDescription
|
||||
let opID = pendingDirectoryRequest?.operationID ?? UUID()
|
||||
pendingDirectoryRequest = (path: normalizedPath, operationID: opID)
|
||||
pendingListPath = normalizedPath
|
||||
pendingListData.removeAll()
|
||||
isFileBusy = true
|
||||
pendingListOperationID = opID
|
||||
updateOperation(id: opID, title: "Loading", message: normalizedPath, progress: nil, indeterminate: true)
|
||||
return
|
||||
}
|
||||
pendingListPath = path
|
||||
|
||||
let opID: UUID
|
||||
if let pending = pendingDirectoryRequest, pending.path == normalizedPath {
|
||||
opID = pending.operationID
|
||||
pendingDirectoryRequest = nil
|
||||
} else {
|
||||
opID = UUID()
|
||||
}
|
||||
|
||||
pendingListPath = normalizedPath
|
||||
pendingListData.removeAll()
|
||||
isFileBusy = true
|
||||
let opID = UUID()
|
||||
pendingListOperationID = opID
|
||||
updateOperation(id: opID, title: "Loading", message: path, progress: nil, indeterminate: true)
|
||||
let payload = payloadFor(path: path)
|
||||
updateOperation(id: opID, title: "Loading", message: normalizedPath, progress: nil, indeterminate: true)
|
||||
let payload = payloadFor(path: normalizedPath)
|
||||
enqueueFileCommand(.listDirectory, payload: payload, characteristic: commandCharacteristic)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func flushPendingDirectoryRequest() -> Bool {
|
||||
guard let pending = pendingDirectoryRequest,
|
||||
let commandCharacteristic = fileCommandCharacteristic else { return false }
|
||||
|
||||
pendingDirectoryRequest = nil
|
||||
pendingListPath = pending.path
|
||||
pendingListData.removeAll()
|
||||
isFileBusy = true
|
||||
pendingListOperationID = pending.operationID
|
||||
updateOperation(id: pending.operationID, title: "Loading", message: pending.path, progress: nil, indeterminate: true)
|
||||
let payload = payloadFor(path: pending.path)
|
||||
enqueueFileCommand(.listDirectory, payload: payload, characteristic: commandCharacteristic)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CBCentralManagerDelegate
|
||||
@@ -824,6 +858,10 @@ extension TimeSyncManager: CBPeripheralDelegate {
|
||||
connectionState = .ready
|
||||
statusMessage = "Connected to Cardboy."
|
||||
}
|
||||
|
||||
if fileResponseCharacteristic?.isNotifying == true {
|
||||
_ = flushPendingDirectoryRequest()
|
||||
}
|
||||
}
|
||||
|
||||
func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
|
||||
@@ -833,7 +871,9 @@ extension TimeSyncManager: CBPeripheralDelegate {
|
||||
}
|
||||
|
||||
if characteristic.uuid == fileResponseUUID, characteristic.isNotifying {
|
||||
refreshDirectory()
|
||||
if !flushPendingDirectoryRequest() {
|
||||
refreshDirectory()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user