• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 rpc from '@ohos.rpc';
17import Log from '../../../../../../../common/src/main/ets/default/Log';
18import Constants from '../common/Constants';
19import type { IDialogParameters } from '../controller/Controller';
20
21const TAG = 'Dialog-Index';
22
23const storage = LocalStorage.GetShared();
24
25@Entry(storage)
26@Component
27struct Index {
28  @LocalStorageProp('connectId') connectId: string = undefined;
29  @LocalStorageProp('windowName') windowName: string = undefined;
30  @LocalStorageProp('parameters') parameters: IDialogParameters = undefined;
31
32  aboutToAppear() {
33    Log.showInfo(TAG, `aboutToAppear r ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`)
34  }
35
36  aboutToDisappear() {
37    Log.showInfo(TAG, `aboutToDisappear ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`)
38  }
39
40  onOk() {
41    Log.showDebug(TAG, `onOk start`);
42
43    const controller = globalThis[Constants.SYSTEM_DIALOG_CONTROLLER];
44    const { remoteObject } = controller.getData().get(this.connectId);
45    if (remoteObject) {
46      Log.showDebug(TAG, `onOk ${remoteObject}`);
47
48      let data = rpc.MessageSequence.create();
49      let reply = rpc.MessageSequence.create();
50      let option = new rpc.MessageOption();
51      remoteObject.sendMessageRequest(1, data, reply, option)
52        .then(
53          (result) => Log.showDebug(TAG, `onOk success ${JSON.stringify(result)}`),
54          (error) => {
55            Log.showDebug(TAG, `onOk error ${JSON.stringify(error)}`);
56            this.onClose();
57          }
58        ).finally(() => {
59          data.reclaim();
60          reply.reclaim();
61        });
62    }
63
64    Log.showInfo(TAG, 'onOk end');
65  }
66
67  onClose() {
68    Log.showDebug(TAG, `onClose start`);
69    const controller = globalThis[Constants.SYSTEM_DIALOG_CONTROLLER];
70    controller?.destroyWindow(this.connectId);
71    Log.showInfo(TAG, `onClose end`);
72  }
73
74  build() {
75    Row() {
76      UIExtensionComponent(this.parameters)
77        .width('100%')
78        .height('100%')
79        .backgroundColor('#00000000')
80        .onRelease(code => {
81          Log.showDebug(TAG, `onRelease${code} start`);
82          this.onClose();
83          Log.showDebug(TAG, `onRelease${code} end`);
84        })
85        .onError(code => {
86          Log.showDebug(TAG, `onError${code} start`);
87          this.onClose();
88          Log.showDebug(TAG, `onError${code} end`);
89        })
90    }
91    .width('100%')
92    .height('100%')
93  }
94}
95