David PHAM-VAN

Fix directPrint printer selection on macOS

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 ## 5.6.8 3 ## 5.6.8
4 4
5 - Fix print dialog crash on Linux 5 - Fix print dialog crash on Linux
  6 +- Fix directPrint printer selection on macOS
6 7
7 ## 5.6.7 8 ## 5.6.7
8 9
@@ -119,6 +119,9 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { @@ -119,6 +119,9 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
119 119
120 for name in NSPrinter.printerNames { 120 for name in NSPrinter.printerNames {
121 let printer = NSPrinter(name: name) 121 let printer = NSPrinter(name: name)
  122 + if printer == nil {
  123 + continue
  124 + }
122 let pr: NSDictionary = [ 125 let pr: NSDictionary = [
123 "url": name, 126 "url": name,
124 "name": name, 127 "name": name,
@@ -143,12 +146,21 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { @@ -143,12 +146,21 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
143 printInfo.orientation = NSPrintInfo.PaperOrientation.landscape 146 printInfo.orientation = NSPrintInfo.PaperOrientation.landscape
144 } 147 }
145 148
146 - // Print the custom view 149 + // A printer is specified
  150 + if printer != nil {
  151 + let pr = NSPrinter(name: printer!)
  152 + if pr == nil {
  153 + printing.onCompleted(printJob: self, completed: false, error: "Unable to find the printer")
  154 + return
  155 + }
  156 + printInfo.printer = pr!
  157 + }
  158 +
  159 + // The custom print view
147 printOperation = NSPrintOperation(view: self, printInfo: printInfo) 160 printOperation = NSPrintOperation(view: self, printInfo: printInfo)
148 printOperation!.jobTitle = name 161 printOperation!.jobTitle = name
149 printOperation!.printPanel.options = [.showsPreview] 162 printOperation!.printPanel.options = [.showsPreview]
150 if printer != nil { 163 if printer != nil {
151 - printInfo.printer = NSPrinter(name: printer!)!  
152 printOperation!.showsPrintPanel = false 164 printOperation!.showsPrintPanel = false
153 printOperation!.showsProgressPanel = false 165 printOperation!.showsProgressPanel = false
154 } 166 }