1/* 2 * Copyright (c) 2025 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 { TipsDialog } from '@kit.ArkUI'; 17import { common, Want } from '@kit.AbilityKit'; 18import { BusinessError } from '@kit.BasicServicesKit'; 19import { logger } from '../common/util/Logger'; 20 21/** 22 * 权限引导弹窗 23 */ 24@CustomDialog 25export struct CommonTipsDialog { 26 @Link isDialogShow: boolean; 27 dialogController?: CustomDialogController; 28 29 build() { 30 TipsDialog({ 31 title: $r('app.string.custom_scan_tips_camera_permissions_reason'), 32 content: $r('app.string.custom_scan_access_tips'), 33 primaryButton: { 34 value: $r('app.string.custom_scan_cancel'), 35 action: () => { 36 this.closeDialog(); 37 }, 38 }, 39 secondaryButton: { 40 value: $r('app.string.custom_scan_access_setting'), 41 action: () => { 42 this.openPermissionsInSystemSettings(); 43 } 44 }, 45 }) 46 } 47 48 /** 49 * 关闭弹窗 50 */ 51 closeDialog(): void { 52 logger.info('Start to close dialog.'); 53 if (this.isDialogShow && this.dialogController !== undefined) { 54 this.isDialogShow = false; 55 this.dialogController.close(); 56 logger.info('Succeeded in closing dialog.'); 57 } 58 } 59 60 /** 61 * 拉起设置指定应用页面弹窗 62 */ 63 openPermissionsInSystemSettings(): void { 64 logger.info('Start to open permissions in system settings.'); 65 let context = getContext(this) as common.UIAbilityContext; 66 let wantInfo: Want = { 67 bundleName: 'com.huawei.hmos.settings', 68 abilityName: 'com.huawei.hmos.settings.MainAbility', 69 uri: 'application_info_entry', 70 parameters: { 71 settingsParamBundleName: 'com.north.cases' // 当前应用包名 72 } 73 }; 74 try { 75 context.startAbility(wantInfo).then(() => { 76 logger.info('Succeeded in starting ability.'); 77 }).catch((error: BusinessError) => { 78 logger.error(`Failed to start ability by promise. Code: ` + error.code); 79 }) 80 } catch (error) { 81 logger.error(`Failed to start ability by catch. Code: ` + error.code); 82 } 83 84 } 85} 86