• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 http from '@ohos.net.http'
17import Logger from '../util/Logger'
18import saveFile from '../feature/SaveFile'
19import getFix from '../feature/LoadFile'
20
21const TAG: string = 'UpdateDialog'
22
23@Component
24export struct UpdateDialog {
25  build() {
26    Column() {
27      Button($r('app.string.check'))
28        .id('check')
29        .fontSize(20)
30        .margin({ top: 30, bottom: 20 })
31        .type(ButtonType.Capsule)
32        .backgroundColor($r('app.color.background'))
33        .size({ width: '40%', height: '8%' })
34        .onClick(() => {
35          AlertDialog.show(
36            {
37              message: $r('app.string.message'),
38              autoCancel: true,
39              alignment: DialogAlignment.Bottom,
40              gridCount: 4,
41              offset: { dx: 0, dy: -20 },
42              primaryButton: {
43                value: $r('app.string.cancel'),
44                action: () => {
45                  Logger.info(TAG, `Callback when the first button is clicked`)
46                }
47              },
48              secondaryButton: {
49                value: $r('app.string.update'),
50                action: () => {
51                  let result: Promise<http.HttpResponse> = getFix()
52                  result.then(data => {
53                    if (data.responseCode === 200) {
54                      saveFile(AppStorage.Get('filePath'), data.result as ArrayBuffer)
55                    }
56                  })
57                }
58              }
59            }
60          )
61        })
62    }.width('100%')
63    .margin({ top: 5 })
64  }
65}