aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Shared/FileIconView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/Shared/FileIconView.swift')
-rw-r--r--Hotline/Shared/FileIconView.swift42
1 files changed, 42 insertions, 0 deletions
diff --git a/Hotline/Shared/FileIconView.swift b/Hotline/Shared/FileIconView.swift
new file mode 100644
index 0000000..7336cf3
--- /dev/null
+++ b/Hotline/Shared/FileIconView.swift
@@ -0,0 +1,42 @@
+import SwiftUI
+import UniformTypeIdentifiers
+
+struct FileIconView: View {
+ let filename: String
+
+ #if os(iOS)
+ private func fileIcon(filename: String) -> Image {
+ let fileExtension = (filename as NSString).pathExtension
+ if let fileType = UTType(filenameExtension: fileExtension) {
+ if fileType.isSubtype(of: .movie) {
+ return Image(systemName: "play.rectangle")
+ }
+ else if fileType.isSubtype(of: .image) {
+ return Image(systemName: "photo")
+ }
+ else if fileType.isSubtype(of: .archive) {
+ return Image(systemName: "doc.zipper")
+ }
+ else if fileType.isSubtype(of: .text) {
+ return Image(systemName: "doc.text")
+ }
+ else {
+ return Image(systemName: "doc")
+ }
+ }
+
+ return Image(systemName: "doc")
+ }
+ #elseif os(macOS)
+ private func fileIcon(filename: String) -> Image {
+ Image(nsImage: NSWorkspace.shared.icon(for: UTType(filenameExtension: (filename as NSString).pathExtension) ?? UTType.content))
+ }
+ #endif
+
+
+ var body: some View {
+ fileIcon(filename: filename)
+ .resizable()
+ .scaledToFit()
+ }
+}