• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16// @ts-nocheck
17import print from '@ohos.print';
18import { Log } from '@ohos/common';
19import AppStorageHelper from '../Common/Adapter/AppStorageHelper';
20import {AppStorageKeyName} from '@ohos/common';
21import {PrintExtensionModel} from '../Model/PrintExtensionModel';
22import { PrinterExtensionInfo } from '@ohos/common';
23
24const TAG = '[PrintExtensionController]:';
25
26/**
27 * PrintExtensionController
28 *
29 */
30export class PrintExtensionController {
31    private mPrintExtensionModel : PrintExtensionModel = new PrintExtensionModel()
32
33    /**
34     * init
35     *
36     */
37    public init() : void {
38        Log.info(TAG, 'PrintExtensionController init')
39        AppStorageHelper.createValue<Array<PrinterExtensionInfo>>(this.getModel().getPrintExtensions, AppStorageKeyName.PRINT_EXTENSION_LIST_NAME)
40    }
41
42    /**
43     * get all printExtension
44     */
45    public getAllPrintExtension() : void {
46        Log.info(TAG, 'queryPrinterCapability')
47        print.queryAllPrinterExtensionInfos().then((data)=> {
48            Log.info(TAG, 'start connect Printer success data : ' )
49            this.getModel().dealGetAllPrintExtension(data)
50        }).catch((err)=> {
51            Log.error(TAG, 'failed to get AllPrintExtension because ' + JSON.stringify(err));
52        });
53    }
54
55    /**
56     * get model
57     *
58     * @return PrintExtensionModel
59     */
60    public getModel() : PrintExtensionModel {
61        return this.mPrintExtensionModel
62    }
63}