1/* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AppStorageKeyName, Log, PrinterExtensionInfo } from '@ohos/common' 17import AppStorageHelper from '../Common/Adapter/AppStorageHelper' 18 19const TAG = '[PrintExtensionModel]:' 20 21export class PrintExtensionModel { 22 private mPrintExtensions: Array<PrinterExtensionInfo> = [] 23 24 get getPrintExtensions():Array<PrinterExtensionInfo> { 25 return this.mPrintExtensions; 26 } 27 28 set setPrintExtensions(array: Array<PrinterExtensionInfo>) { 29 this.mPrintExtensions = array; 30 } 31 32 /** 33 * get all PrintExtension 34 */ 35 public dealGetAllPrintExtension(data: Array<PrinterExtensionInfo>) { 36 if (data === undefined) { 37 Log.error(TAG, 'dealGetAllPrintExtension return for null data'); 38 return; 39 } 40 this.mPrintExtensions = []; 41 for (let index = 0; index < data.length; index++) { 42 let newInfo = new PrinterExtensionInfo(data[index].extensionId, data[index].vendorId, 43 data[index].vendorName, data[index].vendorIcon, data[index].version); 44 this.mPrintExtensions.push(newInfo); 45 } 46 AppStorageHelper.setValue<Array<PrinterExtensionInfo>>(this.getPrintExtensions, AppStorageKeyName.PRINT_EXTENSION_LIST_NAME); 47 } 48}