mirror of
https://github.com/openharmony/applications_print_spooler.git
synced 2026-07-01 04:19:37 -04:00
spooler应用代码规范整改 Signed-off-by:zhengzhihao3@huawei.com
Signed-off-by: zhengzhihao <zhengzhihao3@huawei.com>
This commit is contained in:
+2
-2
@@ -2,8 +2,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.spooler",
|
||||
"vendor": "ohos",
|
||||
"versionCode": 10000008,
|
||||
"versionName": "1.0.0.8",
|
||||
"versionCode": 10000010,
|
||||
"versionName": "1.0.0.10",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"distributedNotificationEnabled": true
|
||||
|
||||
+7
-5
@@ -1,12 +1,14 @@
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"compileSdkVersion": 11,
|
||||
"compatibleSdkVersion": 10,
|
||||
"signingConfigs": [
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default"
|
||||
"signingConfig": "default",
|
||||
"compileSdkVersion": 11,
|
||||
"compatibleSdkVersion": 11,
|
||||
"runtimeOS": "OpenHarmony"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -32,4 +34,4 @@
|
||||
"srcPath": "./feature/ippPrint"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -82,7 +82,8 @@ export { RequestCode,
|
||||
|
||||
export { StringUtil } from './src/main/ets/utils/StringUtil'
|
||||
|
||||
export { PrintMargin,
|
||||
export { PrintAttributes,
|
||||
PrintMargin,
|
||||
PrinterRange,
|
||||
PreviewAttribute,
|
||||
PrintResolution,
|
||||
|
||||
@@ -32,7 +32,7 @@ class ConfigManager {
|
||||
/**
|
||||
* 应用上下文
|
||||
*/
|
||||
private mContext?: common.UIAbilityContext;
|
||||
private mContext?: common.UIAbilityContext | common.UIExtensionContext;
|
||||
/**
|
||||
* EnviornmentCallback id
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ class ConfigManager {
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
onStart(context: common.UIAbilityContext) :void {
|
||||
onStart(context: common.UIAbilityContext | common.UIExtensionContext) :void {
|
||||
if (this.isStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,39 @@ import { CustomPrintJobState } from '../model/PrintBean';
|
||||
import { StringUtil } from '../utils/StringUtil';
|
||||
|
||||
const TAG: string = 'print_fwk';
|
||||
|
||||
/**
|
||||
* defines print attributes.
|
||||
*/
|
||||
export class PrintAttributes implements print.PrintAttributes {
|
||||
copyNumber?: number;
|
||||
pageRange?: PrinterRange;
|
||||
pageSize?: PrintPageSize;
|
||||
colorMode?: print.PrintColorMode;
|
||||
duplexMode?: print.PrintDuplexMode;
|
||||
directionMode?: print.PrintDirectionMode;
|
||||
isSequential: boolean; /* Add a Variable */
|
||||
isLandscape: boolean; /* Add a Variable */
|
||||
options: string; /* Add a Variable */
|
||||
margin: PrintMargin;
|
||||
|
||||
constructor(copyNumber: number, pageRange: PrinterRange,
|
||||
isSequential: boolean, pageSize: PrintPageSize, isLandscape: boolean,
|
||||
colorMode: print.PrintColorMode, duplexMode: print.PrintDuplexMode, margin: PrintMargin,
|
||||
directionMode: print.PrintDirectionMode, options: string) {
|
||||
this.copyNumber = copyNumber;
|
||||
this.pageRange = pageRange;
|
||||
this.pageSize = pageSize;
|
||||
this.colorMode = colorMode;
|
||||
this.duplexMode = duplexMode;
|
||||
this.directionMode = directionMode;
|
||||
this.isSequential = isSequential;
|
||||
this.isLandscape = isLandscape;
|
||||
this.margin = margin;
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* defines print margin.
|
||||
*/
|
||||
|
||||
@@ -148,6 +148,8 @@ export class Constants {
|
||||
static readonly WANT_FILE_LIST_KEY: string = 'fileList';
|
||||
static readonly WANT_CALLERPID_KEY: string = 'ohos.aafwk.param.callerUid';
|
||||
static readonly WANT_PKG_NAME_KEY: string = 'caller.pkgName';
|
||||
static readonly WANT_DOCUMENT_NAME_KEY: string = 'documentName';
|
||||
static readonly wantPrintAttributeKey = 'printAttributes';
|
||||
static readonly EVENT_GET_ABILITY_DATA: string = 'getAbilityData';
|
||||
static readonly DEFAULT_CONNECTING_PRINTER_ID: string = 'noNeedDisconnect';
|
||||
static readonly WINDOW_FLOAT_MODE: number = 102;
|
||||
@@ -161,6 +163,13 @@ export class Constants {
|
||||
static readonly MDNS_PRINTER = 'mdns:';
|
||||
static readonly TEMP_JOB_FOLDER = 'jobs';
|
||||
static readonly JPEG_SUFFIX = '.jpeg';
|
||||
static readonly PRINT_PREVIEW_WINDOW_PREFIX: string = 'PrintPreviewWindow_';
|
||||
static readonly PRINT_PREVIEW_PAGE_URL: string = 'pages/PrintPage';
|
||||
static readonly PRIVACY_STATEMENT_PAGE_URL: string = 'pages/PrivacyStatementPage';
|
||||
static readonly PREVIEW_DIALOG_COUNT: string = 'PreviewDialogCount';
|
||||
static readonly WINDOW_ID = 'windowId';
|
||||
static readonly SESSION = 'session';
|
||||
static readonly PREVIEW_IS_VERTICAL: string = 'PreviewIsVertical';
|
||||
}
|
||||
|
||||
export class AppStorageKeyName {
|
||||
@@ -171,6 +180,9 @@ export class AppStorageKeyName {
|
||||
static readonly START_PRINT_TIME: string = 'startPrintTime';
|
||||
static readonly INGRESS_PACKAGE: string = 'ingressPackage';
|
||||
static readonly APP_VERSION: string = 'appVersion';
|
||||
static readonly DOCUMENT_NAME: string = 'documentName';
|
||||
static readonly PREVIEW_PAGE_INSTANCE: string = 'PreviewPageInstance';
|
||||
static readonly imageSourcesName: string = 'ImageSources';
|
||||
}
|
||||
|
||||
export class GlobalThisStorageKey {
|
||||
|
||||
@@ -31,7 +31,7 @@ export class StringUtil {
|
||||
* @return {string} - string from res
|
||||
*/
|
||||
public static getString(name: string, ...args: Array<string | number>): string {
|
||||
let abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
let abilityContext = GlobalThisHelper.getValue<common.UIExtensionContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
Log.info('getString abilityContext: ' +abilityContext)
|
||||
if (abilityContext !== undefined && !CheckEmptyUtils.checkStrIsEmpty(name)) {
|
||||
return <string> abilityContext?.resourceManager?.getStringByNameSync(name, ...args) ?? '';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"apiType": 'stageMode',
|
||||
"buildOption": {
|
||||
"compileMode": "esmodule",
|
||||
"externalNativeOptions": {
|
||||
"abiFilters": [
|
||||
"arm64-v8a"
|
||||
|
||||
@@ -31,7 +31,10 @@ export default class AppStorageHelper {
|
||||
AppStorageKeyName.CONFIG_LANGUAGE,
|
||||
AppStorageKeyName.START_PRINT_TIME,
|
||||
AppStorageKeyName.INGRESS_PACKAGE,
|
||||
AppStorageKeyName.APP_VERSION
|
||||
AppStorageKeyName.APP_VERSION,
|
||||
AppStorageKeyName.DOCUMENT_NAME,
|
||||
AppStorageKeyName.PREVIEW_PAGE_INSTANCE,
|
||||
AppStorageKeyName.imageSourcesName,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -76,6 +79,25 @@ export default class AppStorageHelper {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除AppStorage对象的值,key需要先注册到registerKeys,否则挂载失败
|
||||
* 如果AppStorage中有对应的属性,且该属性已经没有订阅者,则删除成功,返回true。如果属性不存在,或者该属性还存在订阅者,则返回false
|
||||
*
|
||||
* @returns 删除成功返回true,失败返回false
|
||||
*/
|
||||
public static deleteValue<T>(storageKey: string): boolean {
|
||||
const element = AppStorageHelper.registerKeys.find((ele) => ele === storageKey);
|
||||
if (element === undefined) {
|
||||
Log.error(TAG, 'Can not find register storageKey: ' + JSON.stringify(storageKey));
|
||||
return false;
|
||||
}
|
||||
if (AppStorage.has(storageKey)) {
|
||||
AppStorage.delete(storageKey);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取挂载到AppStorage上的全局变量
|
||||
*
|
||||
|
||||
@@ -52,7 +52,7 @@ export default class PreferencesAdapter {
|
||||
*/
|
||||
public async getOrCreatePreferencesSync(preferencesName: string): Promise<boolean> {
|
||||
Log.info(TAG, 'getOrCreatePreferencesSync start');
|
||||
const ABILITY_CONTEXT = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
const ABILITY_CONTEXT = GlobalThisHelper.getValue<common.UIExtensionContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
if (preferencesName) {
|
||||
try {
|
||||
Log.info(TAG, 'getOrCreatePreferencesSync getValue');
|
||||
|
||||
@@ -95,4 +95,14 @@ export default class Util {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getPreviewDialogId
|
||||
*
|
||||
* @param startId startId
|
||||
* @returns PreviewDialogId
|
||||
*/
|
||||
public static getPreviewDialogId(startId: string): string {
|
||||
return Constants.PRINT_PREVIEW_WINDOW_PREFIX + startId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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 { configMgr, GlobalObject, GlobalThisHelper, GlobalThisStorageKey, MediaSizeHelper } from '@ohos/common';
|
||||
import AppStorageHelper from '../Common/Adapter/AppStorageHelper';
|
||||
import { Log } from '@ohos/common';
|
||||
import { Constants, AppStorageKeyName, PreferencesKey } from '@ohos/common';
|
||||
import type common from '@ohos.app.ability.common';
|
||||
import PreferencesAdapter from '../Common/Adapter/PreferencesAdapter';
|
||||
import bundleManager from '@ohos.bundle.bundleManager';
|
||||
import PrintAdapter from '../Common/Adapter/PrintAdapter';
|
||||
import { Configuration } from '@ohos.app.ability.Configuration';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
import CheckEmptyUtils from '@ohos/common';
|
||||
import Queue from '@ohos.util.Queue';
|
||||
import Util from '../Common/Utils/Util';
|
||||
import type { PrintAttributes } from '@ohos/common';
|
||||
|
||||
const TAG = '[MainAbility]:';
|
||||
|
||||
export default class MainAbility extends UIExtensionAbility {
|
||||
private lock: boolean = false;
|
||||
private storeRequest = new Queue<RequestDialogModel>();
|
||||
private readonly PRIVACY_STATEMENT_STORE: string = 'privacyStatementStore';
|
||||
private session: UIExtensionContentSession | undefined = undefined;
|
||||
|
||||
onCreate(): void {
|
||||
GlobalThisHelper.createValue<common.UIExtensionContext>(this.context, GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT, true);
|
||||
MediaSizeHelper.init(this.context);
|
||||
this.context.resourceManager.getConfiguration((error, value) => {
|
||||
AppStorageHelper.createValue<string>(value.locale as string, AppStorageKeyName.CONFIG_LANGUAGE);
|
||||
});
|
||||
|
||||
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT)
|
||||
.then((bundleInfo) => {
|
||||
AppStorageHelper.createValue<string>(bundleInfo.versionName as string, AppStorageKeyName.APP_VERSION);
|
||||
});
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
Log.info(TAG, 'onDestroy');
|
||||
let adapter = GlobalThisHelper.getValue<PrintAdapter>(GlobalThisStorageKey.KEY_PRINT_ADAPTER);
|
||||
let previewPageInstances: number = AppStorageHelper.getValue(AppStorageKeyName.PREVIEW_PAGE_INSTANCE) as number;
|
||||
if (previewPageInstances === 1) {
|
||||
adapter?.getPrinterDiscCtl()?.stopDiscovery('');
|
||||
this.unsubscribe();
|
||||
}
|
||||
AppStorageHelper.createValue<number>(previewPageInstances - 1, AppStorageKeyName.PREVIEW_PAGE_INSTANCE);
|
||||
let pixelMap = GlobalThisHelper.getValue<image.PixelMap>(GlobalThisStorageKey.KEY_CURRENT_PIXELMAP);
|
||||
if (pixelMap !== undefined) {
|
||||
pixelMap.release().then(() => {
|
||||
Log.info(TAG, 'onDestroy currentPixelMap release success');
|
||||
});
|
||||
}
|
||||
GlobalObject.getInstance().removeObject(Constants.PREVIEW_IS_VERTICAL);
|
||||
GlobalObject.getInstance().removeObject(Constants.PREVIEW_DIALOG_COUNT);
|
||||
let res = AppStorageHelper.deleteValue(AppStorageKeyName.imageSourcesName);
|
||||
Log.info(TAG, 'delete imageSources:' + res);
|
||||
}
|
||||
|
||||
onSessionCreate(want: Want, session: UIExtensionContentSession): void {
|
||||
Log.info(TAG + 'onSessionCreate, want: ' + JSON.stringify(want));
|
||||
this.session = session;
|
||||
let fileList: string[] = [];
|
||||
let callerPid: string = '';
|
||||
let pkgName: string = '';
|
||||
let docName: string = '';
|
||||
let attributes: string = '';
|
||||
let jobId: string = '';
|
||||
if (want.parameters !== undefined) {
|
||||
fileList = want.parameters[Constants.WANT_FILE_LIST_KEY] as string[];
|
||||
Log.info(TAG + 'fileList: ' + JSON.stringify(fileList));
|
||||
|
||||
callerPid = want.parameters[Constants.WANT_CALLERPID_KEY] as string;
|
||||
pkgName = want.parameters[Constants.WANT_PKG_NAME_KEY] as string;
|
||||
docName = want.parameters[Constants.WANT_DOCUMENT_NAME_KEY] as string;
|
||||
attributes = want.parameters[Constants.wantPrintAttributeKey] as string;
|
||||
jobId = want.parameters[Constants.WANT_JOB_ID_KEY] as string;
|
||||
}
|
||||
let printAttributes: PrintAttributes | undefined = undefined;
|
||||
if (!CheckEmptyUtils.checkStrIsEmpty(attributes)) {
|
||||
printAttributes = JSON.parse(attributes);
|
||||
}
|
||||
this.storeRequest.add(new RequestDialogModel(fileList, callerPid, pkgName, docName, printAttributes, jobId));
|
||||
this.consumeRequest();
|
||||
}
|
||||
|
||||
private consumeRequest(): void {
|
||||
if (this.storeRequest.length === 0) {
|
||||
Log.warn(TAG, 'no dialogRequest in queue.');
|
||||
return;
|
||||
}
|
||||
if (this.lock) {
|
||||
Log.warn(TAG, 'consumer is busying: need waiting');
|
||||
return;
|
||||
}
|
||||
this.handleDialogRequest(this.storeRequest.pop(), this.requestCompleteCallback);
|
||||
}
|
||||
|
||||
private async handleDialogRequest(model: RequestDialogModel, callback: (id: string) => void): Promise<void> {
|
||||
GlobalThisHelper.createValue<string>(model.jobId, GlobalThisStorageKey.KEY_JOB_ID);
|
||||
let dialogId = Util.getPreviewDialogId(model.jobId);
|
||||
let pkgNameMap: Map<string, string> = AppStorageHelper.getValue<Map<string, string>>(
|
||||
AppStorageKeyName.INGRESS_PACKAGE) ?? new Map<string, string>();
|
||||
let docNameMap: Map<string, string> = AppStorageHelper.getValue<Map<string, string>>(
|
||||
AppStorageKeyName.DOCUMENT_NAME) ?? new Map<string, string>();
|
||||
let previewPageInstances: number = AppStorageHelper.getValue(AppStorageKeyName.PREVIEW_PAGE_INSTANCE) ?? 0;
|
||||
pkgNameMap.set(dialogId, model.pkgName);
|
||||
docNameMap.set(dialogId, model.docName);
|
||||
AppStorageHelper.createValue<Map<string, string>>(pkgNameMap, AppStorageKeyName.INGRESS_PACKAGE);
|
||||
AppStorageHelper.createValue<Map<string, string>>(docNameMap, AppStorageKeyName.DOCUMENT_NAME);
|
||||
let storage: LocalStorage = new LocalStorage();
|
||||
storage.setOrCreate<string>(Constants.WANT_JOB_ID_KEY, model.jobId);
|
||||
storage.setOrCreate(Constants.WANT_FILE_LIST_KEY, model.fileList ?? new Array<string>());
|
||||
storage.setOrCreate(Constants.wantPrintAttributeKey, model.printAttributes);
|
||||
storage.setOrCreate(Constants.WINDOW_ID, dialogId);
|
||||
storage.setOrCreate(Constants.SESSION, this.session);
|
||||
|
||||
let pageUrl = Constants.PRINT_PREVIEW_PAGE_URL;
|
||||
await this.isFirstUsePrint().then((flag) => {
|
||||
Log.info(TAG, 'isFirstUsePrint : ' + flag);
|
||||
if (flag) {
|
||||
pageUrl = Constants.PRIVACY_STATEMENT_PAGE_URL;
|
||||
} else {
|
||||
pageUrl = Constants.PRINT_PREVIEW_PAGE_URL;
|
||||
}
|
||||
});
|
||||
GlobalObject.getInstance().setObject(Constants.PREVIEW_DIALOG_COUNT,
|
||||
(GlobalObject.getInstance().getObject(Constants.PREVIEW_DIALOG_COUNT) as number) + 1);
|
||||
|
||||
this.session?.loadContent(pageUrl, storage);
|
||||
this.session?.setWindowBackgroundColor('#40000000');
|
||||
AppStorageHelper.createValue<number>(previewPageInstances + 1, AppStorageKeyName.PREVIEW_PAGE_INSTANCE);
|
||||
callback(dialogId);
|
||||
Log.debug(TAG, 'handleDialogRequest end.');
|
||||
}
|
||||
|
||||
private requestCompleteCallback = (dialogId: string): void => {
|
||||
Log.info(TAG, `requestCompleteCallback CreateWindow:${JSON.stringify(dialogId)} completed`);
|
||||
this.lock = false;
|
||||
this.consumeRequest();
|
||||
};
|
||||
|
||||
onConfigurationUpdated(config: Configuration): void {
|
||||
Log.info(TAG, 'onConfigurationUpdated, language:' + config.language);
|
||||
AppStorageHelper.createValue<string>(config.language as string, AppStorageKeyName.CONFIG_LANGUAGE);
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
Log.info(TAG, 'onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
Log.info(TAG, 'onBackground');
|
||||
}
|
||||
|
||||
async isFirstUsePrint(): Promise<boolean> {
|
||||
Log.info(TAG, 'isFirstUsePrint start');
|
||||
const success = await PreferencesAdapter.getInstance().getOrCreatePreferencesSync(this.PRIVACY_STATEMENT_STORE);
|
||||
Log.info(TAG, 'isFirstUsePrint getOrCreatePreferencesSync success: ' + success);
|
||||
if (success) {
|
||||
const agreePrivacyStatement = await PreferencesAdapter.getInstance()
|
||||
.getValue(PreferencesKey.KEY_PRIVACY_STATEMENT_PREFERENCES);
|
||||
Log.info(TAG, 'isFirstUsePrint getValue agreePrivacyStatement: ' + agreePrivacyStatement);
|
||||
if (agreePrivacyStatement) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Log.info(TAG, 'isFirstUsePrint success is not');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private subscribe(): void {
|
||||
configMgr.onStart(this.context);
|
||||
}
|
||||
|
||||
private unsubscribe(): void {
|
||||
configMgr.onStop();
|
||||
}
|
||||
};
|
||||
|
||||
class RequestDialogModel {
|
||||
fileList: Array<string>;
|
||||
callerPid: string;
|
||||
pkgName: string;
|
||||
docName: string;
|
||||
printAttributes: PrintAttributes | undefined;
|
||||
jobId: string;
|
||||
|
||||
constructor(fileList: Array<string>, callerPid: string, pkgName: string, docName: string,
|
||||
printAttributes: PrintAttributes | undefined, jobId: string) {
|
||||
this.fileList = fileList;
|
||||
this.callerPid = callerPid;
|
||||
this.pkgName = pkgName;
|
||||
this.docName = docName;
|
||||
this.printAttributes = printAttributes;
|
||||
this.jobId = jobId;
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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 UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import { configMgr, GlobalThisHelper, GlobalThisStorageKey, MediaSizeHelper } from '@ohos/common';
|
||||
import AppStorageHelper from '../Common/Adapter/AppStorageHelper';
|
||||
import { Log } from '@ohos/common';
|
||||
import { Constants, AppStorageKeyName, PreferencesKey } from '@ohos/common';
|
||||
import type common from '@ohos.app.ability.common';
|
||||
import PreferencesAdapter from '../Common/Adapter/PreferencesAdapter';
|
||||
import bundleManager from '@ohos.bundle.bundleManager';
|
||||
import PrintAdapter from '../Common/Adapter/PrintAdapter';
|
||||
import { Configuration } from '@ohos.app.ability.Configuration';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import window from '@ohos.window';
|
||||
|
||||
const TAG = '[MainAbility]:';
|
||||
|
||||
export default class MainAbility extends UIAbility {
|
||||
private readonly PRIVACY_STATEMENT_STORE: string = 'privacyStatementStore';
|
||||
private storage: LocalStorage = new LocalStorage();
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
Log.info(TAG, 'onCreate: ' + JSON.stringify(want) + ' launchParam : ' + JSON.stringify(launchParam));
|
||||
let jobId = want.parameters[Constants.WANT_JOB_ID_KEY] as string;
|
||||
let fileList = want.parameters[Constants.WANT_FILE_LIST_KEY] as Array<string>;
|
||||
let pkgName = want.parameters[Constants.WANT_PKG_NAME_KEY] as string;
|
||||
Log.info(TAG, 'fileList = ' + JSON.stringify(fileList));
|
||||
GlobalThisHelper.createValue<common.UIAbilityContext>(this.context, GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT, true);
|
||||
MediaSizeHelper.init(this.context);
|
||||
this.storage.setOrCreate<string>(Constants.WANT_JOB_ID_KEY, jobId);
|
||||
this.storage.setOrCreate<Array<string>>(Constants.WANT_FILE_LIST_KEY, fileList);
|
||||
this.context.resourceManager.getConfiguration((error, value) => {
|
||||
AppStorageHelper.createValue<string>(<string> value.locale, AppStorageKeyName.CONFIG_LANGUAGE);
|
||||
});
|
||||
AppStorageHelper.createValue<string>(pkgName, AppStorageKeyName.INGRESS_PACKAGE);
|
||||
|
||||
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT)
|
||||
.then((bundleInfo) => {
|
||||
AppStorageHelper.createValue<string>(<string> bundleInfo.versionName, AppStorageKeyName.APP_VERSION);
|
||||
});
|
||||
configMgr.onStart(this.context);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
Log.info(TAG, 'onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
Log.info(TAG, 'onWindowStageCreate');
|
||||
|
||||
this.isFirstUsePrint().then((flag) => {
|
||||
windowStage.getMainWindow().then((window) => {
|
||||
window.resetSize(vp2px(Constants.MAIN_WINDOW_WIDTH), vp2px(Constants.MAIN_WINDOW_HEIGHT));
|
||||
}).catch((err) => {
|
||||
|
||||
});
|
||||
|
||||
Log.info(TAG, 'onWindowStageCreate flag: ' + JSON.stringify(flag));
|
||||
if (flag) {
|
||||
windowStage.loadContent('pages/PrivacyStatementPage', this.storage);
|
||||
} else {
|
||||
windowStage.loadContent('pages/PrintPage', this.storage);
|
||||
}
|
||||
});
|
||||
|
||||
GlobalThisHelper.createValue(windowStage, GlobalThisStorageKey.KEY_MAIN_ABILITY_WINDOW_STAGE, true);
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
Log.info(TAG, 'onWindowStageDestroy');
|
||||
let adapter = GlobalThisHelper.getValue<PrintAdapter>(GlobalThisStorageKey.KEY_PRINT_ADAPTER);
|
||||
adapter.getPrinterDiscCtl().stopDiscovery('');
|
||||
let pixelMap = GlobalThisHelper.getValue<image.PixelMap>(GlobalThisStorageKey.KEY_CURRENT_PIXELMAP);
|
||||
if (pixelMap !== undefined) {
|
||||
pixelMap.release().then(() => {
|
||||
Log.info(TAG, 'onWindowStageDestroy currentPixelMap release success');
|
||||
});
|
||||
}
|
||||
this.storage.clear();
|
||||
configMgr.onStop();
|
||||
}
|
||||
|
||||
onConfigurationUpdated(config: Configuration): void {
|
||||
Log.info(TAG, 'onConfigurationUpdated, language:' + config.language);
|
||||
AppStorageHelper.createValue<string>(<string> config.language, AppStorageKeyName.CONFIG_LANGUAGE);
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
Log.info(TAG, 'onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
Log.info(TAG, 'onBackground');
|
||||
}
|
||||
|
||||
async isFirstUsePrint(): Promise<boolean> {
|
||||
Log.info(TAG, 'isFirstUsePrint start');
|
||||
const success = await PreferencesAdapter.getInstance().getOrCreatePreferencesSync(this.PRIVACY_STATEMENT_STORE);
|
||||
Log.info(TAG, 'isFirstUsePrint getOrCreatePreferencesSync success: ' + success);
|
||||
if (success) {
|
||||
const agreePrivacyStatement = await PreferencesAdapter.getInstance().getValue(PreferencesKey.KEY_PRIVACY_STATEMENT_PREFERENCES);
|
||||
Log.info(TAG, 'isFirstUsePrint getValue agreePrivacyStatement: ' + agreePrivacyStatement);
|
||||
if (agreePrivacyStatement) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Log.info(TAG, 'isFirstUsePrint success is not');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -13,7 +13,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ErrorMessage, MediaSizeHelper, MediaTypeCode, MediaTypes, PreviewAttribute, PrinterCapsOptions, PrintJob, PrintJobOptions, PrintUtil, startPrintJob } from '@ohos/common';
|
||||
import {
|
||||
ErrorMessage,
|
||||
MediaSizeHelper,
|
||||
MediaTypeCode,
|
||||
MediaTypes,
|
||||
PreviewAttribute,
|
||||
PrinterCapsOptions,
|
||||
PrintJob,
|
||||
PrintJobOptions,
|
||||
PrintUtil,
|
||||
startPrintJob
|
||||
} from '@ohos/common';
|
||||
import WifiP2pHelper from '../Common/Adapter/WifiP2pHelper';
|
||||
import FileModel from '../Model/FileModel';
|
||||
import SelectionModel from '../Model/SelectionModel';
|
||||
@@ -60,6 +71,7 @@ import { AboutPageComponent } from './component/AboutPageComponent';
|
||||
import router from '@ohos.router';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
|
||||
const TAG = 'PrintPage';
|
||||
|
||||
@@ -97,7 +109,7 @@ struct Index {
|
||||
@Provide('NeedDuplex') @Watch('needDuplexChange')needDuplex: boolean = true;
|
||||
@Provide('IsBorderless') isBorderless: boolean = false //是否无边距
|
||||
@Provide('IsPreviewFailed') isPreviewFailed: boolean = false //是否需要显示预览失败图示
|
||||
private abilityContext: common.UIAbilityContext | undefined = undefined;
|
||||
private abilityContext: common.UIExtensionContext | undefined = undefined;
|
||||
@State @Watch('updateImageSources')imageSources: Array<FileModel> = new Array();
|
||||
@State startPage: number = Constants.NUMBER_1 //打印范围起始页
|
||||
@State startPageStr: string = Constants.STRING_ONE //打印范围起始页
|
||||
@@ -159,7 +171,7 @@ struct Index {
|
||||
private firstPrinterDiscoveredFlag: boolean = false;
|
||||
private changeRangeTypeFlag: boolean = true;//范围框radio选中是否让startPage输入框获焦
|
||||
private fileNum: number = Constants.NUMBER_0;
|
||||
|
||||
private session?: UIExtensionContentSession = undefined;
|
||||
WLANConfirmDialogCtl: CustomDialogController = new CustomDialogController({
|
||||
builder: WLANConfirmDialog(),
|
||||
alignment: DialogAlignment.Center,
|
||||
@@ -691,8 +703,8 @@ struct Index {
|
||||
cancelWidth: $r('app.float.button_index_width'),
|
||||
cancelHeight: $r('app.float.button_index_height'),
|
||||
cancelClick: () => {
|
||||
this.abilityContext?.terminateSelf().then((data) => {
|
||||
console.info('===>terminateSelfCallBack===>: ' + data);
|
||||
this.session?.terminateSelf().then(() => {
|
||||
console.info('===>terminateSelfCallBack===>: ');
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -717,6 +729,8 @@ struct Index {
|
||||
})
|
||||
}.width($r('app.float.print_setting_width'))
|
||||
}
|
||||
.padding({ top: 32, bottom: 32 })
|
||||
.backgroundColor($r('sys.color.ohos_id_color_panel_bg'))
|
||||
.onTouch((event:TouchEvent)=>{
|
||||
if (event.type === TouchType.Down) {
|
||||
Log.info(TAG,'requestFocus')
|
||||
@@ -797,12 +811,13 @@ struct Index {
|
||||
}
|
||||
|
||||
private getWant() {
|
||||
this.abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT)
|
||||
this.abilityContext = GlobalThisHelper.getValue<common.UIExtensionContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT)
|
||||
if (CheckEmptyUtils.isEmpty<LocalStorage>(storage)) {
|
||||
storage = router.getParams() as LocalStorage;
|
||||
}
|
||||
this.jobId = storage.get<string>(Constants.WANT_JOB_ID_KEY)!;
|
||||
this.jobFileList = storage.get<Array<string>>(Constants.WANT_FILE_LIST_KEY)!;
|
||||
this.session = storage.get<UIExtensionContentSession>(Constants.SESSION);
|
||||
Log.debug(TAG, 'aboutToAppear jobId: ' + JSON.stringify(this.jobId) + ', fileList: ' + JSON.stringify(this.jobFileList));
|
||||
}
|
||||
|
||||
@@ -1153,7 +1168,6 @@ struct Index {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setDuplexSelect() {
|
||||
this.duplexSelectArray = new Array<SelectionModel>()
|
||||
this.duplexSelectArray.push(SelectionModel.DuplexMode_SINGLE, SelectionModel.DuplexMode_LONG, SelectionModel.DuplexMode_SHORT)
|
||||
@@ -1175,7 +1189,7 @@ struct Index {
|
||||
*/
|
||||
async loadImageSources() {
|
||||
Log.info(TAG, 'loadImageSources start')
|
||||
if (this.jobFileList) {
|
||||
if (this.jobFileList && this.jobFileList.length !== 0) {
|
||||
this.fileNum = this.jobFileList.length;
|
||||
this.imageSources = await FileUtil.initImageData(this.checkMaxPages(this.jobFileList));
|
||||
} else {
|
||||
@@ -1490,8 +1504,8 @@ struct Index {
|
||||
this.abilityContext?.startAbility(jobAbilityWant).then(() => {
|
||||
Log.info(TAG,'startJobManagerAbility')
|
||||
this.canPrint = false;
|
||||
this.abilityContext?.terminateSelf().then((data) => {
|
||||
console.info('===>terminateSelfCallBack===>: '+data);
|
||||
this.session?.terminateSelf().then(() => {
|
||||
console.info('===>terminateSelfCallBack===>: ');
|
||||
});
|
||||
}).catch((err: BusinessError) => {
|
||||
Log.error(TAG, 'fail to startAbility, err =' + JSON.stringify(err));
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import CheckEmptyUtils, { Log } from '@ohos/common';
|
||||
import CheckEmptyUtils, { Constants, Log } from '@ohos/common';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { GlobalThisHelper, GlobalThisStorageKey} from '@ohos/common';
|
||||
import { PreferencesKey} from '@ohos/common';
|
||||
import PreferencesAdapter from '../Common/Adapter/PreferencesAdapter';
|
||||
import {PrivacyStatementDialog} from './PrivacyStatementDialog';
|
||||
import {CancelButton} from './component/BaseComponent';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
|
||||
const TAG = 'PrivacyStatementPage';
|
||||
|
||||
@@ -29,7 +30,8 @@ let storage = LocalStorage.getShared();
|
||||
@Component
|
||||
struct PrivacyStatementPage {
|
||||
private readonly PRIVACY_STATEMENT_STORE: string = 'privacyStatementStore';
|
||||
private abilityContext: common.UIAbilityContext | undefined = undefined
|
||||
private abilityContext: common.UIExtensionContext | undefined = undefined;
|
||||
private session?: UIExtensionContentSession = undefined;
|
||||
private dialogController: CustomDialogController = new CustomDialogController({
|
||||
builder: PrivacyStatementDialog(),
|
||||
autoCancel: false,
|
||||
@@ -37,7 +39,9 @@ struct PrivacyStatementPage {
|
||||
})
|
||||
|
||||
aboutToAppear() {
|
||||
this.abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT)
|
||||
this.abilityContext = GlobalThisHelper.getValue<common.UIExtensionContext>(
|
||||
GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
this.session = storage.get<UIExtensionContentSession>(Constants.SESSION);
|
||||
}
|
||||
|
||||
build() {
|
||||
@@ -114,7 +118,7 @@ struct PrivacyStatementPage {
|
||||
cancelWidth: $r('app.float.privacy_statement_button_width'),
|
||||
cancelHeight: $r('app.float.privacy_statement_button_height'),
|
||||
cancelClick: () => {
|
||||
this.abilityContext?.terminateSelf();
|
||||
this.session?.terminateSelf();
|
||||
}
|
||||
})
|
||||
.margin({right: $r('app.float.privacy_statement_button_space')})
|
||||
|
||||
@@ -27,8 +27,8 @@ const TAG = 'PrivacyStatementWebPage';
|
||||
@Component
|
||||
struct PrivacyStatementWebPage {
|
||||
@State @Watch('languageChange') language: string = configMgr.getConfiguration().language ?? '';
|
||||
private abilityContext: common.UIAbilityContext = GlobalThisHelper
|
||||
.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
private abilityContext: common.UIExtensionContext = GlobalThisHelper
|
||||
.getValue<common.UIExtensionContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT);
|
||||
private webController: webview.WebviewController = new webview.WebviewController();
|
||||
private privacyStatementFlag: boolean = false;
|
||||
private baseUrl: string = Constants.STRING_NONE;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowBackground": "$color:color_ffffff",
|
||||
"name": "MainAbility",
|
||||
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
|
||||
"srcEntrance": "./ets/MainAbility/MainAbility.ets",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
@@ -53,6 +53,13 @@
|
||||
"description": "service",
|
||||
"type": "print",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"icon": "$media:icon",
|
||||
"name": "PrintServiceExtAbility",
|
||||
"srcEntry": "./ets/MainAbility/MainAbility.ets",
|
||||
"type": "sysDialog/common",
|
||||
"exported": true
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"hvigorVersion": "2.4.2",
|
||||
"hvigorVersion": "3.2.4",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "2.4.2"
|
||||
"@ohos/hvigor-ohos-plugin": "3.2.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user