diff --git a/runtime/main/extend/systemplugin/napi/ohos_print.js b/runtime/main/extend/systemplugin/napi/ohos_print.js new file mode 100644 index 0000000000000000000000000000000000000000..dd4b4b2b493bcb1f466c7febc07d2ee6b99461d4 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_print.js @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { paramMock } from '../utils'; +import { PrinterExtensionInfoClass } from "./print/ohos_print_printerExtensionInfo" +import { PrinterCapabilityClass } from "./print/ohos_print_printerCapability" +import { PrinterPageSizeClass } from "./print/ohos_print_printerPageSize" +import { PrintMarginClass } from "./print/ohos_print_printMargin" +export function mockPrint() { + const PrintTask = { + on: function (...args) { + console.warn("PrintTask.on interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'blocked' || 'success' || 'failed' || 'cancelled') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } + } + }, + off: function (...args) { + console.warn("PrintTask.off interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'blocked' || 'success' || 'failed' || 'cancelled') { + args[len - 1].call(this); + } + } + }, + }; + const PrinterState = { + PRINTER_ADDED : 1, // new printers arrival + PRINTER_REMOVED : 2, // printers lost + PRINTER_CONNECTED : 3, // printer has been connected + PRINTER_DISCONNECTED : 4, // printer has been disconnected + PRINTER_RUNNING : 5, // printer is working + PRINTER_UNKNOWN : 6 // unknown printer state + }; + const PrintJobState = { + PRINT_JOB_PREPARE : 1, // initial state of print job + PRINT_JOB_QUEUED : 2, // deliver print job to the printer + PRINT_JOB_RUNNING : 3, // executing print job + PRINT_JOB_BLOCKED : 4, // print job has been blocked + PRINT_JOB_COMPLETED : 5, // print job ocmpleted + PRINT_JOB_UNKNOWN : 6 // unknown state of print job + }; + const PrintJobSubState = { + PRINT_JOB_SUCCESS : 0, // print job succeed + PRINT_JOB_FAILED : 1, // print job fail + PRINT_JOB_CANCELLED : 2, // print job has been cancelled + PRINT_JOB_FILE_CORRUPT : 3, // print job has been corrupted + PRINT_JOB_BLOCK_OFFLINE : 4,// printer is offline + PRINT_JOB_BLOCK_BUSY : 5, // printer is occupied by other process + PRINT_JOB_BLOCK_CANCELLED : 6, // print job has been canncelled + PRINT_JOB_BLOCK_OUT_OF_PAPER : 7, // out of paper + PRINT_JOB_BLOCK_OUT_OF_INK : 8, // out of ink + PRINT_JOB_BLOCK_OUT_OF_TONER : 9, // out of toner + PRINT_JOB_BLOCK_JAMMED : 10, // paper jam + PRINT_JOB_BLOCK_DOOR_OPEN : 11, // cover open + PRINT_JOB_BLOCK_SERVICE_REQUEST : 12, // service request + PRINT_JOB_BLOCK_LOW_ON_INK : 13, // low on ink + PRINT_JOB_BLOCK_LOW_ON_TONER : 14, // low on toner + PRINT_JOB_BLOCK_REALLY_LOW_ON_INK : 15, // really low on ink + PRINT_JOB_BLOCK_BAD_CERTIFICATE : 16, // bad certification + PRINT_JOB_BLOCK_UNKNOWN : 17 // unknown issue + }; + const PrinterInfo = { + printerId : "[PC Preview] unknow printerId", + printerName : "[PC Preview] unknow printerName", + printerIcon : "[PC Preview] unknow printerIcon", + printerState : PrinterState, + description : "[PC Preview] unknow description", + capability : new PrinterCapabilityClass(), + option : "[PC Preview] unknow option" + }; + const PrinterRange = { + startPage : "[PC Preview] unknow startPage"; // start page of sequence + endPage : "[PC Preview] unknow endPage"; // end page of sequence + pages : "[PC Preview] unknow pages"; // discrete page of sequence + }; + const PreviewAttribute = { + previewRange : PrinterRange; // preview page range + result : "[PC Preview] unknow result"; // preview file + }; + const PrintJob { + files : "[PC Preview] unknow files"; // document list to be printed + jobId : "[PC Preview] unknow jobId"; // job id + printerId : "[PC Preview] unknow printerId"; // printer id to take charge of printing + jobState : PrintJobState; // current print job state + copyNumber : "[PC Preview] unknow copyNumber"; // copies of document list + pageRange : PrinterRange; // range size to be printed + isSequential : "[PC Preview] unknow isSequential"; // sequential print + pageSize : new PrinterPageSizeClass(); // the selected page size + isLandscape : "[PC Preview] unknow isLandscape"; // vertical printing + colorMode : "[PC Preview] unknow colorMode"; // color mode + duplexMode : "[PC Preview] unknow duplexMode"; // duplex mode + margin : new PrintMarginClass(); // current margin setting + preview : PreviewAttribute; // preview setting + option : "[PC Preview] unknow option"; // json object string + }; + + const print = { + print: function (...args) { + console.warn("print.print interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, PrintTask); + } else { + return new Promise((resolve, reject) => { + resolve(PrintTask); + }) + } + }, + queryAllPrinterExtensionInfos: function (...args) { + console.warn("print.queryAllPrinterExtensionInfos interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, [new PrinterExtensionInfoClass()]); + } else { + return new Promise((resolve, reject) => { + resolve([new PrinterExtensionInfoClass()]); + }) + } + }, + startDiscoverPrinter: function (...args) { + console.warn("print.startDiscoverPrinter interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + stopDiscoverPrinter: function (...args) { + console.warn("print.stopDiscoverPrinter interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + connectPrinter: function (...args) { + console.warn("print.connectPrinter interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + disconnectPrinter: function (...args) { + console.warn("print.disconnectPrinter interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + requestPrintPreview: function (...args) { + console.warn("print.requestPrintPreview interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + queryPrinterCapability: function (...args) { + console.warn("print.queryPrinterCapability interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new PrinterCapabilityClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new PrinterCapabilityClass()); + }) + } + }, + startPrintJob: function (...args) { + console.warn("print.startPrintJob interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + cancelPrintJob: function (...args) { + console.warn("print.cancelPrintJob interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + + on: function (...args) { + console.warn("print.on interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length + if (typeof args[len - 1] === 'function') { + if (args[0] == 'printerStateChange') { + args[len - 1].call(this, PrinterState, PrinterInfo); + } + else if (args[0] == 'jobStateChange') { + args[len - 1].call(this, PrintJobState, PrintJob); + } + else if (args[0] == 'extInfoChange') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); + } + } + }, + off: function (...args) { + console.warn("print.off interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + const len = args.length; + if (typeof args[len - 1] === 'function') { + if (args[0] == 'printerStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } + else if (args[0] == 'jobStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } + else if (args[0] == 'jobStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } + } + }, + addPrinters: function (...args) { + console.warn("print.addPrinters interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + removePrinters: function (...args) { + console.warn("print.removePrinters interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + updatePrinters: function (...args) { + console.warn("print.updatePrinters interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + updatePrinterState: function (...args) { + console.warn("print.updatePrinterState interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + updatePrintJobState: function (...args) { + console.warn("print.updatePrintJobState interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + readFile: function (...args) { + console.warn('print.readFile interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + const len = args.length; + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); + } else { + return new Promise((resolve) => { + resolve(paramMock.paramArrayMock); + }); + } + } + }; + return print +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/print/ohos_print_printMargin.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printMargin.js new file mode 100644 index 0000000000000000000000000000000000000000..6e7103414ba132f95bc7732fcacd1b03414f8289 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printMargin.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const PrintMarginClass = class PrintMargin { + constructor() { + this.top = '[PC Preview] unknow top'; // top margin + this.bottom = '[PC Preview] unknow bottom'; // bottom margin + this.left = '[PC Preview] unknow left'; // left side margin + this.right = '[PC Preview] unknow right'; // right side margin + } +} +export function mockPrintMargin() { + return new PrintMarginClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js new file mode 100644 index 0000000000000000000000000000000000000000..66b676d26795477162f696c00ff5e2e9d03fb5c4 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { PrintMarginClass } from "./ohos_application_PrintMargin" +import { PrinterPageSizeClass } from "./ohos_application_PrinterPageSize" +import { PrinterResolutionClass } from "./ohos_application_PrinterResolution" +export const PrinterCapabilityClass = class PrinterCapability { + constructor() { + this.minMargin = new PrintMarginClass(); + this.pageSize = [new PrinterPageSizeClass()]; + this.resolution =[new PrinterResolutionClass()]; + this.colorMode ='[PC Preview] unknow colorMode'; + this.duplexMode ='[PC Preview] unknow duplexMode'; + } +} +export function mockPrinterCapability() { + return new PrinterCapabilityClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js new file mode 100644 index 0000000000000000000000000000000000000000..c9c6dc14262d5de7fbd4784edaf0eff51aa4beff --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const PrinterExtensionInfoClass = class PrinterExtensionInfo { + constructor() { + this.extensionId ='[PC Preview] unknow extensionId'; + this.vendorId ='[PC Preview] unknow vendorId'; + this.vendorName ='[PC Preview] unknow vendorName'; + this.vendorIcon ='[PC Preview] unknow vendorIcon'; + this.version ='[PC Preview] unknow version'; + } +} +export function mockPrinterExtensionInfo() { + return new PrinterExtensionInfoClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/print/ohos_print_printerPageSize.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerPageSize.js new file mode 100644 index 0000000000000000000000000000000000000000..d1e89d5fd9ab6df8ce75256bb470cf6531ff866f --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerPageSize.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const PrinterPageSizeClass = class PrinterPageSize { + constructor() { + this.id = '[PC Preview] unknow id'; // page size id + this.name = '[PC Preview] unknow name'; // page size name + this.width = '[PC Preview] unknow width'; // page size width + this.height = '[PC Preview] unknow height'; // page size height + } +} +export function mockPrinterPageSize() { + return new PrinterPageSizeClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/print/ohos_print_printerResolution.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerResolution.js new file mode 100644 index 0000000000000000000000000000000000000000..b5558958b0ef6a39571fee401f923c3f5151e392 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerResolution.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const PrinterResolutionClass = class PrinterResolution { + constructor() { + this.id ='[PC Preview] unknow id'; + this.horizontalDpi ='[PC Preview] unknow horizontalDpi'; + this.verticalDpi ='[PC Preview] unknow verticalDpi'; + } +} +export function mockPrinterResolution() { + return new PrinterResolutionClass(); +} \ No newline at end of file