1/* 2 * Copyright (c) 2021-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 { AsyncCallback } from './basic'; 17import Want from './@ohos.app.ability.Want'; 18 19/** 20 * Plugin component template property. 21 * @syscap SystemCapability.ArkUI.ArkUI.Full 22 * @since 8 23 */ 24interface PluginComponentTemplate { 25 source: string; 26 ability: string; 27} 28 29/** 30 * Plugin component manager interface. 31 * @syscap SystemCapability.ArkUI.ArkUI.Full 32 * @since 8 33 */ 34declare namespace pluginComponentManager { 35 type KVObject = { [key: string]: number | string | boolean | [] | KVObject } 36 37 /** 38 * Plugin component push parameters. 39 * @since 8 40 */ 41 interface PushParameters { 42 want: Want; 43 name: string; 44 data: KVObject; 45 extraData: KVObject; 46 jsonPath?: string; 47 } 48 49 /** 50 * Plugin component push parameters which is used in push function. 51 * @param { Want } owner - The information of the application which uses the push function. 52 * @param { Want } target - The information of the template which is being pushed to others. 53 * @param { string } name - The name of the template which is being pushed to others. 54 * @param { KVObject } data - The data which is used to update pluginComponent. 55 * @param { KVObject } extraData - The extra data. 56 * @param { string } jsonPath - The path used to find the file which storage template path. 57 * @since 9 58 * @systemapi 59 */ 60 interface PushParameterForStage { 61 owner: Want; 62 target: Want; 63 name: string; 64 data: KVObject; 65 extraData: KVObject; 66 jsonPath?: string; 67 } 68 69 /** 70 * Plugin component request parameters. 71 * @since 8 72 */ 73 interface RequestParameters { 74 want: Want; 75 name: string; 76 data: KVObject; 77 jsonPath?: string; 78 } 79 80 /** 81 * Plugin component request parameters which is used in request function. 82 * @param { Want } owner - The information of the application which uses the request function. 83 * @param { Want } target - The information of the template which is being requested form others. 84 * @param { string } name - The name of the template which is being requested form others. 85 * @param { KVObject } data - The extra data. 86 * @param { string } jsonPath - The path used to find the file which storage template path. 87 * @since 9 88 * @systemapi 89 */ 90 interface RequestParameterForStage { 91 owner: Want; 92 target: Want; 93 name: string; 94 data: KVObject; 95 jsonPath?: string; 96 } 97 98 /** 99 * Plugin component request callback parameters. 100 * @since 8 101 */ 102 interface RequestCallbackParameters { 103 componentTemplate: PluginComponentTemplate; 104 data: KVObject; 105 extraData: KVObject; 106 } 107 108 /** 109 * Plugin component request event result value. 110 * @since 8 111 */ 112 interface RequestEventResult { 113 template?: string; 114 data?: KVObject; 115 extraData?: KVObject; 116 } 117 118 /** 119 * Plugin component push event callback. 120 * @since 8 121 */ 122 type OnPushEventCallback = (source: Want, template: PluginComponentTemplate, data: KVObject, 123 extraData: KVObject) => void; 124 125 /** 126 * Plugin component request event callback. 127 * @since 8 128 */ 129 130 type OnRequestEventCallback = (source: Want, name: string, data: KVObject) => RequestEventResult; 131 132 /** 133 * Plugin component push method. 134 * @since 8 135 */ 136 function push(param: PushParameters, callback: AsyncCallback<void>): void; 137 138 /** 139 * Plugin component request method. 140 * @since 8 141 */ 142 function request(param: RequestParameters, callback: AsyncCallback<RequestCallbackParameters>): void; 143 144 /** 145 * Plugin component push method used to send the information of the template it provides. 146 * @param { PushParameterForStage | PushParameterStage } param - Plugin component push parameters for stage. 147 * @param { AsyncCallback<void> } callback - Plugin component push event callback. 148 * @StageModelOnly 149 * @since 9 150 * @systemapi 151 */ 152 function push(param: PushParameterForStage, callback: AsyncCallback<void>): void; 153 154 /** 155 * Plugin component request method used to send a request for the information of the template it wants. 156 * @param { RequestParameterForStage | RequestParameterStage } param - Plugin component request parameters for stage. 157 * @param { AsyncCallback<RequestCallbackParameters> } callback - Plugin component request event callback. 158 * @StageModelOnly 159 * @since 9 160 * @systemapi 161 */ 162 function request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void; 163 164 /** 165 * Plugin component event listener. 166 * @since 8 167 */ 168 function on(eventType: string, callback: OnPushEventCallback | OnRequestEventCallback): void; 169} 170 171export default pluginComponentManager; 172