aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Library/QuickLookPreviewView.swift
blob: 6ba154e81300a8dd4e3e17b2fd44bdb648630113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import SwiftUI
import Quartz

/// Embeddable QuickLook preview view for macOS
///
/// This view uses QLPreviewView to display file previews inline, without showing a modal.
/// Supports all file types that QuickLook supports (images, PDFs, videos, documents, etc.)
struct QuickLookPreviewView: NSViewRepresentable {
  let fileURL: URL

  func makeNSView(context: Context) -> QLPreviewView {
    let preview = QLPreviewView(frame: .zero, style: .normal)!
    preview.autostarts = true
    preview.shouldCloseWithWindow = true
    preview.previewItem = fileURL as QLPreviewItem
    return preview
  }

  func updateNSView(_ nsView: QLPreviewView, context: Context) {
    nsView.previewItem = fileURL as QLPreviewItem
  }
}