From df316dbac1b76ffc8de723dce3da543912edf931 Mon Sep 17 00:00:00 2001 From: "@chuangda_1" Date: Tue, 11 Oct 2022 20:55:24 +0800 Subject: [PATCH 1/3] Add print mockjs Signed-off-by: @chuangda_1 --- .../ohos_application_PrinterCapability.js | 13 + .../ohos_application_PrinterExtensionInfo.js | 12 + .../extend/systemplugin/napi/ohos_print.js | 280 ++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_print.js diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js new file mode 100644 index 00000000..bfe4628b --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js @@ -0,0 +1,13 @@ +import { paramMock } from "../utils" +export const PrinterCapabilityClass = class PrinterCapability { + constructor() { + this.minMargin = PrintMarginMock; + this.pageSize = [PrinterPageSizeMock]; + this.resolution =[PrinterResolutionMock]; + 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/ohos_application_PrinterExtensionInfo.js b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js new file mode 100644 index 00000000..647fcf67 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js @@ -0,0 +1,12 @@ +import { paramMock } from "../utils" +export const PrinterExtensionInfoClass = class PrinterExtensionInfo { + constructor() { + this.extensionId ='[PC Preview] unknow extensionId'; + this.vendorId ='[PC Preview] unknow vendorId'; + 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/ohos_print.js b/runtime/main/extend/systemplugin/napi/ohos_print.js new file mode 100644 index 00000000..354ae987 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_print.js @@ -0,0 +1,280 @@ +import { paramMock } from '../utils'; +import { PrinterExtensionInfoClass } from "./ohos_application_PrinterExtensionInfo" +import { PrinterCapabilityClass } from "./ohos_application_PrinterCapability" +export function print() { + 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) + } + } + }, + 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, PrintTaskClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new PrintTaskClass()); + }) + } + }, + 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, [PrinterExtensionInfoClass()]); + } else { + return new Promise((resolve, reject) => { + resolve([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, print.PrinterState, print.PrinterInfo); + } + } + }, + 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); + } + } + } + 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] == 'jobStateChange') { + args[len - 1].call(this, print.jobStateChange, print.PrintJob); + } + } + }, + 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] == 'jobStateChange') { + args[len - 1].call(this, paramMock.businessErrorMock, 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] == 'jobStateChange') { + 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] == '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 -- Gitee From 48960466adc9752d1315a23b14f2ed1f60751c85 Mon Sep 17 00:00:00 2001 From: "@chuangda_1" Date: Wed, 12 Oct 2022 11:42:32 +0800 Subject: [PATCH 2/3] mork js code add Signed-off-by: @chuangda_1 --- .../ohos_application_PrinterCapability.js | 14 +++++++++ .../ohos_application_PrinterExtensionInfo.js | 14 +++++++++ .../extend/systemplugin/napi/ohos_print.js | 30 ++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js index bfe4628b..d08c9d1f 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js +++ b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js @@ -1,3 +1,17 @@ +/* + * 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" export const PrinterCapabilityClass = class PrinterCapability { constructor() { diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js index 647fcf67..e7702bc0 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js +++ b/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js @@ -1,3 +1,17 @@ +/* + * 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" export const PrinterExtensionInfoClass = class PrinterExtensionInfo { constructor() { diff --git a/runtime/main/extend/systemplugin/napi/ohos_print.js b/runtime/main/extend/systemplugin/napi/ohos_print.js index 354ae987..178c10aa 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_print.js +++ b/runtime/main/extend/systemplugin/napi/ohos_print.js @@ -1,21 +1,35 @@ +/* + * 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 "./ohos_application_PrinterExtensionInfo" import { PrinterCapabilityClass } from "./ohos_application_PrinterCapability" export function print() { const PrintTask = { - on: function (...args) { - console.warn("PrintTask.on interface mocked in the Previewer. How this interface works on the" + + 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) + 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" + + 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') { @@ -24,7 +38,7 @@ export function print() { } } }, - print: function (...args) { + 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 @@ -36,7 +50,7 @@ export function print() { }) } }, - queryAllPrinterExtensionInfos: function (...args) { + 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 @@ -60,7 +74,7 @@ export function print() { }) } }, - stopDiscoverPrinter: function (...args) { + 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 -- Gitee From 3051e5a04aa0975b58c5354ea2b064363ec4902f Mon Sep 17 00:00:00 2001 From: "@chuangda_1" Date: Wed, 12 Oct 2022 16:39:38 +0800 Subject: [PATCH 3/3] Add new js Signed-off-by: @chuangda_1 --- .../extend/systemplugin/napi/ohos_print.js | 158 ++++++++++++------ .../napi/print/ohos_print_printMargin.js | 25 +++ .../ohos_print_printerCapability.js} | 10 +- .../ohos_print_printerExtensionInfo.js} | 2 +- .../napi/print/ohos_print_printerPageSize.js | 25 +++ .../print/ohos_print_printerResolution.js | 24 +++ 6 files changed, 184 insertions(+), 60 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/print/ohos_print_printMargin.js rename runtime/main/extend/systemplugin/napi/{ohos_application_PrinterCapability.js => print/ohos_print_printerCapability.js} (71%) rename runtime/main/extend/systemplugin/napi/{ohos_application_PrinterExtensionInfo.js => print/ohos_print_printerExtensionInfo.js} (94%) create mode 100644 runtime/main/extend/systemplugin/napi/print/ohos_print_printerPageSize.js create mode 100644 runtime/main/extend/systemplugin/napi/print/ohos_print_printerResolution.js diff --git a/runtime/main/extend/systemplugin/napi/ohos_print.js b/runtime/main/extend/systemplugin/napi/ohos_print.js index 178c10aa..dd4b4b2b 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_print.js +++ b/runtime/main/extend/systemplugin/napi/ohos_print.js @@ -13,9 +13,11 @@ * limitations under the License. */ import { paramMock } from '../utils'; -import { PrinterExtensionInfoClass } from "./ohos_application_PrinterExtensionInfo" -import { PrinterCapabilityClass } from "./ohos_application_PrinterCapability" -export function print() { +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" + @@ -23,30 +25,102 @@ export function print() { 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) + 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) + args[len - 1].call(this); } } }, - print: function (...args) { + }; + 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, PrintTaskClass()); + args[len - 1].call(this, paramMock.businessErrorMock, PrintTask); } else { return new Promise((resolve, reject) => { - resolve(new PrintTaskClass()); + resolve(PrintTask); }) } }, @@ -55,10 +129,10 @@ export function print() { " 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, [PrinterExtensionInfoClass()]); + args[len - 1].call(this, paramMock.businessErrorMock, [new PrinterExtensionInfoClass()]); } else { return new Promise((resolve, reject) => { - resolve([PrinterExtensionInfoClass()]); + resolve([new PrinterExtensionInfoClass()]); }) } }, @@ -158,15 +232,22 @@ export function print() { }) } }, + 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, print.PrinterState, print.PrinterInfo); + 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" + @@ -175,49 +256,15 @@ export function print() { if (typeof args[len - 1] === 'function') { if (args[0] == 'printerStateChange') { args[len - 1].call(this, paramMock.businessErrorMock, 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] == 'jobStateChange') { - args[len - 1].call(this, print.jobStateChange, print.PrintJob); - } - } - }, - 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] == 'jobStateChange') { + } + else if (args[0] == 'jobStateChange') { args[len - 1].call(this, paramMock.businessErrorMock, 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] == 'jobStateChange') { - 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] == 'jobStateChange') { + } + 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.") @@ -289,6 +336,7 @@ export function print() { resolve(paramMock.paramArrayMock); }); } - }, - return print - } \ No newline at end of file + } + }; + 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 00000000..6e710341 --- /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/ohos_application_PrinterCapability.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js similarity index 71% rename from runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js rename to runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js index d08c9d1f..66b676d2 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterCapability.js +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerCapability.js @@ -12,12 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { paramMock } from "../utils" +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 = PrintMarginMock; - this.pageSize = [PrinterPageSizeMock]; - this.resolution =[PrinterResolutionMock]; + this.minMargin = new PrintMarginClass(); + this.pageSize = [new PrinterPageSizeClass()]; + this.resolution =[new PrinterResolutionClass()]; this.colorMode ='[PC Preview] unknow colorMode'; this.duplexMode ='[PC Preview] unknow duplexMode'; } diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js similarity index 94% rename from runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js rename to runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js index e7702bc0..c9c6dc14 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_application_PrinterExtensionInfo.js +++ b/runtime/main/extend/systemplugin/napi/print/ohos_print_printerExtensionInfo.js @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { paramMock } from "../utils" 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'; } 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 00000000..d1e89d5f --- /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 00000000..b5558958 --- /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 -- Gitee