From 2f8f71d0410f59d5d303a4c221a628630168bfe2 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Fri, 5 Jan 2024 19:46:13 -0800 Subject: Add image preview to Files so you don't have to download images to view them, works with animated GIFs too. Added cmd-R shortcut for Servers window. More work on login view. --- Hotline/macOS/FilesView.swift | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'Hotline/macOS/FilesView.swift') diff --git a/Hotline/macOS/FilesView.swift b/Hotline/macOS/FilesView.swift index 09354ed..5443270 100644 --- a/Hotline/macOS/FilesView.swift +++ b/Hotline/macOS/FilesView.swift @@ -70,8 +70,7 @@ struct FileView: View { .padding(.leading, CGFloat(depth * (12 + 10))) .onChange(of: file.expanded) { loading = false - if file.isFolder { - print("EXPANDED \(file.name)? \(expanded)") + if file.isFolder && file.fileSize > 0 { if file.expanded { Task { loading = true @@ -108,9 +107,14 @@ struct FileView: View { struct FilesView: View { @Environment(Hotline.self) private var model: Hotline + @Environment(\.openWindow) private var openWindow @State private var selection: FileInfo? + private func openPreviewWindow(_ previewInfo: PreviewFileInfo) { + let _ = FilePreviewWindowController(info: previewInfo) + } + var body: some View { NavigationStack { List(model.files, id: \.self, selection: $selection) { file in @@ -129,7 +133,6 @@ struct FilesView: View { .contextMenu(forSelectionType: FileInfo.self) { items in // ... } primaryAction: { items in - print("ITEMS?", items) guard let clickedFile = items.first else { return } @@ -139,7 +142,6 @@ struct FilesView: View { clickedFile.expanded.toggle() } else { - print("DOWNLOAD FILE", clickedFile.name, clickedFile.path) model.downloadFile(clickedFile.name, path: clickedFile.path) } } @@ -157,6 +159,17 @@ struct FilesView: View { } return .ignored } + .onKeyPress(.space) { + if let s = selection, s.isImage { + model.previewFile(s.name, path: s.path) { info in + if let info = info { + openPreviewWindow(info) + } + } + return .handled + } + return .ignored + } .overlay { if !model.filesLoaded { VStack { @@ -167,8 +180,6 @@ struct FilesView: View { } } .toolbar { - - ToolbarItem(placement: .primaryAction) { Button { } label: { @@ -180,15 +191,17 @@ struct FilesView: View { ToolbarItem(placement: .primaryAction) { Button { if let s = selection, !s.isFolder { - print("DOWNLOAD FILE", s.name, s.path) - model.previewFile(s.name, path: s.path, addTransfer: true) { transfer, fileData in - print("FILE PREVIEWED?", fileData.count) + model.previewFile(s.name, path: s.path) { info in + if let info = info { + openPreviewWindow(info) + } } } } label: { Label("Preview File", systemImage: "eye") } .help("Preview File") + .disabled(selection?.isImage == false) } ToolbarItem(placement: .primaryAction) { -- cgit