ImageToPDFTools.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // ImageToPDFTools.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/18.
  6. //
  7. import Cocoa
  8. class ImageToPDFTools: NSObject {
  9. /**
  10. 获取打开文件
  11. */
  12. static func fetchOpenDocumentFiles() -> [URL] {
  13. var files:[URL] = []
  14. for window in NSApp.windows {
  15. if window.windowController is KMBrowserWindowController {
  16. let controller: KMBrowserWindowController = window.windowController as! KMBrowserWindowController
  17. if controller.browser != nil {
  18. let model: CTTabStripModel = controller.browser.tabStripModel
  19. let count = model.count()
  20. if count > 0 {
  21. for i in 0...(count - 1) {
  22. let document: KMMainDocument = model.tabContents(at: Int32(i)) as? KMMainDocument ?? KMMainDocument()
  23. if document.isHome {
  24. continue
  25. }
  26. if !(FileManager.default.fileExists(atPath: document.fileURL?.path ?? "")) {
  27. continue
  28. }
  29. if document.fileURL != nil {
  30. files.append(document.fileURL!)
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. return files
  38. }
  39. }