From 970060a28e992bfba85a72d56da84cf991f84c9c Mon Sep 17 00:00:00 2001 From: Pirvu Doru Lucian Date: Tue, 4 Mar 2014 18:21:30 +0200 Subject: [PATCH] support for windows 10 UWP apps --- CHANGELOG.md | 3 ++- plugin.xml | 8 +++++++ src/windows/PrinterProxy.js | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/windows/PrinterProxy.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ad45646..ea649ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,12 @@ - [__change__:] Plugin requires Android KitKat or newer - [__change__:] `isAvailable` returns false if no enabled service can be found (Android) - [feature:] New `pick` interface to pick a printer for future usage +- [feature:] Initial support for Windows10 platform (Thanks to #cristi-badila) - [enhancement:] `isAvailable` returns count of available services (Android) - [enhancement:] `print` returns bool value to indicate the result - [enhancement:] Added missing `duplex` support (Android) - [__change__:] `duplex` requires a string (`none`, `long` or `short`) -- [enhancement:] Support for `hidePageRange`, `hideNumberOfCopies` and `hidePaperFormat` (iOS specific) +- [enhancement:] Support for `border`, `hidePageRange`, `hideNumberOfCopies` and `hidePaperFormat` (iOS specific) #### Version 0.7.1 (23.04.2015) diff --git a/plugin.xml b/plugin.xml index a94fda8..27fac47 100644 --- a/plugin.xml +++ b/plugin.xml @@ -107,4 +107,12 @@ + + + + + + + + diff --git a/src/windows/PrinterProxy.js b/src/windows/PrinterProxy.js new file mode 100644 index 0000000..7ca5d84 --- /dev/null +++ b/src/windows/PrinterProxy.js @@ -0,0 +1,44 @@ +PrinterProxy = { + printDocumentSource: null, + + isAvailable: function (successCallback, failCallback, args) { + successCallback(true, 0); + }, + + print: function (successCallback, failCallback, args) { + var documentFragment = document.createDocumentFragment(); + var content = document.createElement("html"); + + window.printContent = args[0]; + content.innerHTML = window.printContent; + documentFragment.appendChild(content); + PrinterProxy.getPrintDocumentSource(documentFragment).then(function(source) { + PrinterProxy.printDocumentSource = source; + Windows.Graphics.Printing.PrintManager.showPrintUIAsync(); + }); + }, + + getPrintDocumentSource: function(documentFragment) { + var promise; + if(MSApp.getHtmlPrintDocumentSourceAsync) { + promise = MSApp.getHtmlPrintDocumentSourceAsync(documentFragment); + } else { + promise = new WinJS.Promise(function(completeDispatch) { + completeDispatch(MSApp.getHtmlPrintDocumentSource(documentFragment)); + }); + } + + return promise; + }, + + printTaskRequested: function (printEvent) { + printEvent.request.createPrintTask("Print", function (args) { + args.setSource(PrinterProxy.printDocumentSource); + }); + } +}; + +var printManager = Windows.Graphics.Printing.PrintManager.getForCurrentView(); +printManager.onprinttaskrequested = PrinterProxy.printTaskRequested; + +require("cordova/exec/proxy").add("Printer", PrinterProxy); \ No newline at end of file