1/* 2 * Copyright (c) 2024 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 16const hilog = requireNapi('hilog'); 17const Want = requireNapi('app.ability.Want'); 18const componentSnapshot = requireNapi('arkui.componentSnapshot'); 19const componentUtils = requireNapi('arkui.componentUtils'); 20const image = requireNapi('multimedia.image'); 21const util = requireNapi('util'); 22 23const tag = 'AddFormMenuItem::js::'; 24 25async function querySnapshotAsync(want, componentId) { 26 !want.parameters && (want.parameters = {}); 27 let pixelStr = '/9j/4AAQSk'; 28 let width = 300.00; 29 let height = 300.00; 30 let screenOffsetX = 210.00; 31 let screeOffsetY = 490.00; 32 want.parameters['ohos.extra.param.key.add_form_to_host_width'] = width; 33 want.parameters['ohos.extra.param.key.add_form_to_host_height'] = height; 34 want.parameters['ohos.extra.param.key.add_form_to_host_screenx'] = screenOffsetX; 35 want.parameters['ohos.extra.param.key.add_form_to_host_screeny'] = screeOffsetY; 36 want.parameters['ohos.extra.param.key.add_form_to_host_snapshot'] = pixelStr; 37 hilog.info(0x3900, tag, 'pixelStr length:' + pixelStr.length); 38} 39 40function querySnapshot(want, componentId) { 41 querySnapshotAsync(want, componentId); 42 return true; 43} 44 45/** 46 * Build function of AddFormMenuItem. 47 * 48 * @param { Want } want - The want of the form to publish. 49 * @param { string } componentId - The id of the component used to get form snapshot. 50 * @param { AddFormOptions } [options] - Add form options. 51 * @syscap SystemCapability.ArkUI.ArkUI.Full 52 * @since 12 53 */ 54export function AddFormMenuItem(want, componentId, options, parent = null) { 55 this.observeComponentCreation2((elmtId, isInitialRender) => { 56 If.create(); 57 if (querySnapshot(want, componentId)) { 58 this.ifElseBranchUpdateFunction(0, () => { 59 }); 60 } 61 else { 62 this.ifElseBranchUpdateFunction(1, () => { 63 }); 64 } 65 }, If); 66 If.pop(); 67 this.observeComponentCreation2((elmtId, isInitialRender) => { 68 MenuItem.create(options?.style?.options ? options.style.options : { 69 startIcon: { 70 'id': 125830229, 71 'type': 20000, 72 params: ['sys.media.ic_form_menu_add'], 73 'bundleName': '', 74 'moduleName': '' 75 }, 76 content: { 77 'id': 125832726, 78 'type': 10003, 79 params: ['sys.string.ohos_add_form_to_desktop'], 80 'bundleName': '', 81 'moduleName': '' 82 } 83 }); 84 }, MenuItem); 85 MenuItem.pop(); 86} 87 88export default { AddFormMenuItem }; 89