1/* 2 * Copyright (c) 2024-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 16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17import commonEventManager from '@ohos.commonEventManager'; 18 19let TAG = '[WIFI-NI:WifiDialog]==>'; 20const WIFI_NI_ACCEPT_EVENT: string = 'ohos.event.wifi.DIALOG_ACCEPT'; 21const WIFI_NI_REJECT_EVENT: string = 'ohos.event.wifi.DIALOG_REJECT'; 22 23@Entry 24@Component 25struct dialogPlusPage { 26 @State title: Resource = $r('app.string.wifi_cdd_notify_title'); 27 @State primaryButtonValue: Resource = $r('app.string.wifi_cdd_notify_no_button'); 28 @State secondaryButtonValue: Resource = $r('app.string.wifi_cdd_notify_yes_button'); 29 private WIFI_DIALOG_CDD: number = 0; 30 private WIFI_DIALOG_THREE_VAP: number = 1; 31 private WIFI_DIALOG_CANDIDATE_CONNECT: number = 2; 32 33 aboutToAppear() { 34 console.info(TAG, 'aboutToAppear') 35 if (AppStorage.get('wifiDialogType') != null) { 36 let type : number = AppStorage.get('wifiDialogType') as number 37 switch (type) { 38 case this.WIFI_DIALOG_CDD: 39 this.title = $r('app.string.wifi_cdd_notify_title'); 40 this.primaryButtonValue = $r('app.string.wifi_cdd_notify_no_button'); 41 this.secondaryButtonValue = $r('app.string.wifi_cdd_notify_yes_button'); 42 break; 43 case this.WIFI_DIALOG_THREE_VAP: 44 this.title = $r('app.string.wifi_three_vap_notify_title'); 45 this.primaryButtonValue = $r('app.string.wifi_three_vap_notify_no_button'); 46 this.secondaryButtonValue = $r('app.string.wifi_three_vap_notify_yes_button'); 47 break; 48 case this.WIFI_DIALOG_CANDIDATE_CONNECT: 49 this.title = $r('app.string.wifi_candidate_connect_notify_title'); 50 this.primaryButtonValue = $r('app.string.wifi_candidate_connect_notify_no_button'); 51 this.secondaryButtonValue = $r('app.string.wifi_candidate_connect_notify_yes_button'); 52 break; 53 default: 54 break; 55 } 56 AlertDialog.show( 57 { 58 title: '', 59 message: this.title, 60 autoCancel: false, 61 primaryButton: { 62 value: this.primaryButtonValue, 63 action: () => { 64 this.onCancel(type); 65 } 66 }, 67 secondaryButton: { 68 value: this.secondaryButtonValue, 69 action: () => { 70 this.onAccept(type); 71 } 72 } 73 } 74 ) 75 console.info(TAG, 'dialog show success') 76 } 77 } 78 79 aboutToDisappear() { 80 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 81 if (session) { 82 session.terminateSelf(); 83 } 84 } 85 86 onCancel(type :number) { 87 console.info(TAG, 'Wifi dialog cancel clicked.') 88 89 const options: commonEventManager.CommonEventPublishData = { 90 code: 0, 91 data: 'message', 92 subscriberPermissions: [], 93 isOrdered: true, 94 isSticky: false, 95 parameters: { 'dialogType': type } 96 } 97 98 commonEventManager.publish(WIFI_NI_REJECT_EVENT, options, (err) => { 99 if (err) { 100 console.info(TAG, 'Wifi dialog cancel event publish failed .' + JSON.stringify(err)); 101 } else { 102 console.info(TAG, 'Wifi dialog cancel event publish success.'); 103 } 104 }) 105 106 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 107 if (session) { 108 session.terminateSelf(); 109 } 110 } 111 112 onAccept(type : number) { 113 console.info(TAG, 'Wifi dialog accept clicked.') 114 115 const options: commonEventManager.CommonEventPublishData = { 116 code: 0, 117 data: 'message', 118 subscriberPermissions: [], 119 isOrdered: true, 120 isSticky: false, 121 parameters: { 'dialogType': type } 122 } 123 124 commonEventManager.publish(WIFI_NI_ACCEPT_EVENT, options, (err) => { 125 if (err) { 126 console.info(TAG, 'Wifi dialog accept event publish failed .' + JSON.stringify(err)); 127 } else { 128 console.info(TAG, 'Wifi dialog accept event publish success.'); 129 } 130 }) 131 132 let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession'); 133 if (session) { 134 session.terminateSelf(); 135 } 136 } 137 138 build() { 139 } 140}