Skip to content

Commit 17ed14c

Browse files
committed
fix: crash when switching between view types in device table on macOS
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 7066c8d commit 17ed14c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Sushitrain/DevicesView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private struct DeviceMetricView: View {
100100
}
101101

102102
private func update() async {
103-
(self.measurement, self.address) = await Task.detached {
103+
(self.measurement, self.address) = await Task { @concurrent in
104104
return await self.calculateMeasurement()
105105
}.value
106106
}
@@ -416,7 +416,7 @@ struct LatencyView: View {
416416

417417
TableColumnForEach(self.peers) { peer in
418418
TableColumn(peer.displayName) { folder in
419-
DevicesGridCellView(device: peer, folder: folder, viewStyle: viewStyle)
419+
DevicesGridCellView(appState: appState, device: peer, folder: folder, viewStyle: viewStyle)
420420
// Needed because for some reason SwiftUI doesn't propagate environment inside TableColumn
421421
.environment(self.appState)
422422
}.width(ideal: 50).alignment(.center)
@@ -571,7 +571,9 @@ struct LatencyView: View {
571571
TableColumnForEach(self.folders) { folder in
572572
TableColumn(folder.displayName) { (row: DevicesGridRow) in
573573
if case .connectedDevice(let peer) = row {
574-
DevicesGridCellView(device: peer, folder: folder, viewStyle: viewStyle)
574+
DevicesGridCellView(appState: self.appState, device: peer, folder: folder, viewStyle: viewStyle)
575+
// Needed because for some reason SwiftUI doesn't propagate environment inside TableColumn
576+
.environment(self.appState)
575577
}
576578
else {
577579
EmptyView()
@@ -717,7 +719,7 @@ struct LatencyView: View {
717719
}
718720

719721
private struct DevicesGridCellView: View {
720-
@Environment(AppState.self) private var appState
722+
var appState: AppState
721723
var device: SushitrainPeer
722724
var folder: SushitrainFolder
723725
var viewStyle: GridViewStyle
@@ -802,7 +804,7 @@ struct LatencyView: View {
802804
self.loadingTask = nil
803805
}
804806

805-
self.loadingTask = Task.detached(priority: .userInitiated) {
807+
self.loadingTask = Task(priority: .userInitiated) { @concurrent in
806808
dispatchPrecondition(condition: .notOnQueue(.main))
807809
let sharedWithDeviceIDs = folder.sharedWithDeviceIDs()?.asArray() ?? []
808810
let sharedEncrypted = folder.sharedEncryptedWithDeviceIDs()?.asArray() ?? []

0 commit comments

Comments
 (0)