support for windows 10 UWP apps

This commit is contained in:
Pirvu Doru Lucian 2014-03-04 18:21:30 +02:00 committed by Sebastián Katzer
parent a4f5dd098f
commit 970060a28e
3 changed files with 54 additions and 1 deletions

View File

@ -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)

View File

@ -107,4 +107,12 @@
<resource-file src="res/android/layout/select_printer_activity.xml"
target="res/layout/select_printer_activity.xml" />
</platform>
<!-- windows -->
<platform name="windows">
<js-module src="src/windows/PrinterProxy.js" name="PrinterProxy">
<merges target="" />
</js-module>
</platform>
</plugin>

View File

@ -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);