Skip to content

Commit

Permalink
Merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
imTigger committed Aug 28, 2020
1 parent 5ee4582 commit 5bf8d35
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.pdfbox.printing.Scaling;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tigerworkshop.webapphardwarebridge.Config;
import tigerworkshop.webapphardwarebridge.interfaces.NotificationListenerInterface;
import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServerInterface;
import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServiceInterface;
import tigerworkshop.webapphardwarebridge.responses.PrintDocument;
Expand All @@ -25,16 +25,21 @@
import java.io.IOException;

public class PrinterWebSocketService implements WebSocketServiceInterface {
private Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
private WebSocketServerInterface server = null;
private Gson gson = new Gson();
private final Gson gson = new Gson();

private SettingService settingService = SettingService.getInstance();
private final SettingService settingService = SettingService.getInstance();
private NotificationListenerInterface notificationListener;

public PrinterWebSocketService() {
logger.info("Starting PrinterWebSocketService");
}

public void setNotificationListener(NotificationListenerInterface notificationListener) {
this.notificationListener = notificationListener;
}

@Override
public void start() {
server.subscribe(this, getChannel());
Expand Down Expand Up @@ -72,6 +77,10 @@ private String getChannel() {
*/
public void printDocument(PrintDocument printDocument) throws Exception {
try {
if (notificationListener != null) {
notificationListener.notify("Printing " + printDocument.getType(), printDocument.getUrl(), TrayIcon.MessageType.INFO);
}

if (isRaw(printDocument)) {
printRaw(printDocument);
} else if (isImage(printDocument)) {
Expand All @@ -87,6 +96,10 @@ public void printDocument(PrintDocument printDocument) throws Exception {
logger.error("Document Print Error, deleting downloaded document");
DocumentService.deleteFileFromUrl(printDocument.getUrl());

if (notificationListener != null) {
notificationListener.notify("Printing Error " + printDocument.getType(), e.getMessage(), TrayIcon.MessageType.ERROR);
}

server.onDataReceived(getChannel(), gson.toJson(new PrintResult(1, printDocument.getId(), e.getClass().getName() + " - " + e.getMessage())));

throw e;
Expand Down Expand Up @@ -226,7 +239,7 @@ private void printPDF(PrintDocument printDocument) throws PrinterException, IOEx
Book book = new Book();
for (int i = 0; i < document.getNumberOfPages(); i += 1) {
// Rotate Page Automatically
if (Config.PDF_AUTO_ROTATE) {
if (settingService.getSetting().getAutoRotation()) {
if (document.getPage(i).getCropBox().getWidth() > document.getPage(i).getCropBox().getHeight()) {
pageFormat.setOrientation(PageFormat.LANDSCAPE);
} else {
Expand Down

0 comments on commit 5bf8d35

Please sign in to comment.