diff --git a/Scripts/fix_table_2.py b/Scripts/fix_table_2.py new file mode 100644 index 0000000..7087c7e --- /dev/null +++ b/Scripts/fix_table_2.py @@ -0,0 +1,62 @@ +import re + +with open("Sources/Firelink/DownloadTable.swift", "r") as f: + content = f.read() + +# Fix size to use bytesText if sizeBytes is nil or 0 +old_size = ''' TableColumn("Size", value: \\.sortableSize) { item in + Text(ByteFormatter.string(item.sizeBytes)) + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + }''' +new_size = ''' TableColumn("Size", value: \\.sortableSize) { item in + if let size = item.sizeBytes, size > 0 { + Text(ByteFormatter.string(size)) + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + } else if item.bytesText != "-" && !item.bytesText.isEmpty { + Text(item.bytesText) + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + } else { + Text("Unknown") + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + } + }''' +content = content.replace(old_size, new_size) + +# Add allowsHitTesting(false) to text to fix single click interception +old_text = ''' Text(item.fileName) + .font(.headline) + .lineLimit(1) + .truncationMode(.tail)''' +new_text = ''' Text(item.fileName) + .font(.headline) + .lineLimit(1) + .truncationMode(.tail) + .allowsHitTesting(false)''' +content = content.replace(old_text, new_text) + +# Change performPrimaryAction to use id +old_action = 'openWindow(value: item.id)' +new_action = 'openWindow(id: "download-properties", value: item.id)' +content = content.replace(old_action, new_action) + +with open("Sources/Firelink/DownloadTable.swift", "w") as f: + f.write(content) + +with open("Sources/Firelink/FirelinkApp.swift", "r") as f: + app_content = f.read() + +app_content = app_content.replace( + 'WindowGroup("Download Properties", for: UUID.self)', + 'WindowGroup("Download Properties", id: "download-properties", for: UUID.self)' +) + +with open("Sources/Firelink/FirelinkApp.swift", "w") as f: + f.write(app_content) diff --git a/Sources/Firelink/DownloadTable.swift b/Sources/Firelink/DownloadTable.swift index 707b518..44d5562 100644 --- a/Sources/Firelink/DownloadTable.swift +++ b/Sources/Firelink/DownloadTable.swift @@ -46,16 +46,29 @@ struct DownloadTable: View { .font(.headline) .lineLimit(1) .truncationMode(.tail) + .allowsHitTesting(false) .draggable(item.id.uuidString) } } .width(min: 200, ideal: 340) TableColumn("Size", value: \.sortableSize) { item in - Text(ByteFormatter.string(item.sizeBytes)) + if let size = item.sizeBytes, size > 0 { + Text(ByteFormatter.string(size)) .monospacedDigit() .lineLimit(1) .truncationMode(.tail) + } else if item.bytesText != "-" && !item.bytesText.isEmpty { + Text(item.bytesText) + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + } else { + Text("Unknown") + .monospacedDigit() + .lineLimit(1) + .truncationMode(.tail) + } } .width(min: 80, ideal: 100) @@ -152,7 +165,7 @@ struct DownloadTable: View { if item.status == .completed { openFile(item) } else { - openWindow(value: item.id) + openWindow(id: "download-properties", value: item.id) } } diff --git a/Sources/Firelink/FirelinkApp.swift b/Sources/Firelink/FirelinkApp.swift index b3d27f0..a9b21f9 100644 --- a/Sources/Firelink/FirelinkApp.swift +++ b/Sources/Firelink/FirelinkApp.swift @@ -115,7 +115,7 @@ struct FirelinkApp: App { } .windowResizability(.contentSize) - WindowGroup("Download Properties", for: UUID.self) { $downloadID in + WindowGroup("Download Properties", id: "download-properties", for: UUID.self) { $downloadID in if let downloadID { DownloadPropertiesWindow(downloadID: downloadID) .environmentObject(controller)