overlay fixes

This commit is contained in:
2025-10-20 00:58:33 +02:00
parent b72ea4f417
commit e8ae1cbec4
2 changed files with 36 additions and 28 deletions

View File

@@ -149,6 +149,11 @@ private struct FileManagerTabView: View {
manager.changeDirectory(to: target)
}
}
.onChange(of: manager.connectionState) { newState in
if newState == .ready, !manager.isFileBusy {
manager.refreshDirectory()
}
}
}
}

View File

@@ -204,6 +204,10 @@ final class TimeSyncManager: NSObject, ObservableObject {
// MARK: - File operations exposed to UI
func refreshDirectory() {
if isFileBusy {
pendingDirectoryRequest = (path: currentDirectory, operationID: pendingDirectoryRequest?.operationID ?? UUID())
return
}
requestDirectory(path: currentDirectory)
}
@@ -679,17 +683,7 @@ final class TimeSyncManager: NSObject, ObservableObject {
private func requestDirectory(path: String) {
let normalizedPath = normalizedPath(path)
guard let commandCharacteristic = fileCommandCharacteristic else {
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
}
if let commandCharacteristic = fileCommandCharacteristic {
let opID: UUID
if let pending = pendingDirectoryRequest, pending.path == normalizedPath {
opID = pending.operationID
@@ -697,14 +691,19 @@ final class TimeSyncManager: NSObject, ObservableObject {
} else {
opID = UUID()
}
startDirectoryRequest(path: normalizedPath, operationID: opID, characteristic: commandCharacteristic)
} else {
let opID = pendingDirectoryRequest?.operationID ?? UUID()
pendingDirectoryRequest = (path: normalizedPath, operationID: opID)
if connectionState == .ready {
pendingListPath = normalizedPath
pendingListData.removeAll()
isFileBusy = true
pendingListOperationID = opID
updateOperation(id: opID, title: "Loading", message: normalizedPath, progress: nil, indeterminate: true)
let payload = payloadFor(path: normalizedPath)
enqueueFileCommand(.listDirectory, payload: payload, characteristic: commandCharacteristic)
}
}
}
@discardableResult
@@ -713,14 +712,18 @@ final class TimeSyncManager: NSObject, ObservableObject {
let commandCharacteristic = fileCommandCharacteristic else { return false }
pendingDirectoryRequest = nil
pendingListPath = pending.path
startDirectoryRequest(path: pending.path, operationID: pending.operationID, characteristic: commandCharacteristic)
return true
}
private func startDirectoryRequest(path: String, operationID: UUID, characteristic: CBCharacteristic) {
pendingListPath = 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
pendingListOperationID = operationID
updateOperation(id: operationID, title: "Loading", message: path, progress: nil, indeterminate: true)
let payload = payloadFor(path: path)
enqueueFileCommand(.listDirectory, payload: payload, characteristic: characteristic)
}
}